~singpolyma/dhall-html

f243bbfe207de65740f1c9a291ec4b35ad228a1a — Stephen Paul Weber 11 months ago
Initial commit
3 files changed, 90 insertions(+), 0 deletions(-)

A Makefile
A elements.dhall
A render-record.dhall
A  => Makefile +3 -0
@@ 1,3 @@
package.dhall: render-record.dhall elements.dhall
	echo "./render-record.dhall ./elements.dhall" | dhall-to-text --explain | dhall freeze > package.dhall
	echo >> package.dhall

A  => elements.dhall +72 -0
@@ 1,72 @@
let Map = https://github.com/dhall-lang/dhall-lang/raw/v9.0.0/Prelude/Map/Type
let Map/Entry = https://github.com/dhall-lang/dhall-lang/raw/v9.0.0/Prelude/Map/Entry
let concatMap = https://github.com/dhall-lang/dhall-lang/raw/v9.0.0/Prelude/List/concatMap

let leaves = [
	"img", "link", "meta", "base", "br", "hr", "wbr", "area", "param", "input"
]

let elements = [
	"html",
	"head", "body",
	"object", "script", "style", "title",
	"p", "h1", "h2", "h3", "h4", "h5", "h6",
	"dl", "dt", "dd", "ol", "ul", "li",
	"address", "article", "aside", "blockquote", "del", "div",
	"figure", "figcaption", "footer", "header", "ins", "main", "nav",
	"noscript", "pre", "section",
	"a", "abbr", "dfn", "em", "strong", "code", "kbd", "samp", "var",
	"b", "i", "u", "small", "s", "span", "bdi", "bdo", "cite", "data", "mark",
	"q", "rb", "rp", "rt", "rtc", "ruby", "sub", "sup", "template", "time",
	"audio", "canvas", "embed", "map", "source", "track", "video",
	"form", "button", "datalist", "fieldset", "label", "legend", "meter",
	"option", "optgroup", "output", "progress", "select", "textarea",
	"table", "tr", "th", "td", "colgroup", "col", "caption", "thead", "tbody",
	"tfoot", "iframe"
]
in
concatMap Text (Map/Entry Text Text) (\(leaf: Text) -> [
	{
		mapKey = leaf,
		mapValue = ''
			\(attrs: Map Text Text) ->
				XML.leaf {
					name = ${Text/show leaf},
					attributes = attrs
				}''
	},
	{
		mapKey = "${leaf}_",
		mapValue = ''
			XML.leaf {
				name = ${Text/show leaf},
				attributes = XML.emptyAttributes
			}''
	}
]) leaves
#
concatMap Text (Map/Entry Text Text)
	(\(el: Text) -> [
		{
			mapKey = el,
			mapValue = ''
				\(attrs: Map Text Text) -> \(content: List XML/Type) ->
					XML.element {
						name = ${Text/show el},
						attributes = attrs,
						content = content
					}''
		},
		{
			mapKey = "${el}_",
			mapValue = ''
				\(content: List XML/Type) ->
					XML.element {
						name = ${Text/show el},
						attributes = XML.emptyAttributes,
						content = content
					}''
		}
]) elements
#
[{ mapKey = "text", mapValue = "XML.text"}]

A  => render-record.dhall +15 -0
@@ 1,15 @@
let Map = https://github.com/dhall-lang/dhall-lang/raw/v9.0.0/Prelude/Map/Type
let Map/Entry = https://github.com/dhall-lang/dhall-lang/raw/v9.0.0/Prelude/Map/Entry
let concatMapSep = https://github.com/dhall-lang/dhall-lang/raw/v9.0.0/Prelude/Text/concatMapSep
in \(input: Map Text Text) ->
''
let Map = https://github.com/dhall-lang/dhall-lang/raw/v9.0.0/Prelude/Map/Type
let XML = https://github.com/dhall-lang/dhall-lang/raw/v9.0.0/Prelude/XML/package.dhall
let XML/Type = https://github.com/dhall-lang/dhall-lang/raw/v9.0.0/Prelude/XML/Type
in
{
'' ++
concatMapSep ",\n" (Map/Entry Text Text) (\(el: Map/Entry Text Text) ->
	"\t${el.mapKey} = ${el.mapValue}"
) input
++ "\n}\n"