Skip to content

Instantly share code, notes, and snippets.

@neongreen
Created September 8, 2021 20:46
Show Gist options
  • Save neongreen/fd8b817dcbbbb104c5e3a71fcda0a469 to your computer and use it in GitHub Desktop.
Save neongreen/fd8b817dcbbbb104c5e3a71fcda0a469 to your computer and use it in GitHub Desktop.
let List/map =
https://prelude.dhall-lang.org/List/map sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680
let Text/concat =
https://prelude.dhall-lang.org/Text/concat sha256:731265b0288e8a905ecff95c97333ee2db614c39d69f1514cb8eed9259745fc0
let Optional/fold =
https://prelude.dhall-lang.org/Optional/fold
sha256:c5b9d72f6f62bdaa0e196ac1c742cc175cd67a717b880fb8aec1333a5a4132cf
let JSON =
https://prelude.dhall-lang.org/JSON/package.dhall sha256:0c3c40a63108f2e6ad59f23b789c18eb484d0e9aebc9416c5a4f338c6753084b
let Map =
https://prelude.dhall-lang.org/Map/package.dhall sha256:598e9c76103b2686fbbda6cc30078f9e60dd846d9eaf155d0149cf0ae06c21c5
let Location =
https://prelude.dhall-lang.org/Location/Type sha256:613ebb491aeef4ff06368058b4f0e6e3bb8a58d8c145131fc0b947aac045a529
let Content =
< Nodes : List JSON.Type | Markdown : Text | Text : Text | Raw : Text >
let Attr =
< Text : Text | VersionedAsset : { path : Text, location : Location } >
let Node =
{ tag : Optional Text, attrs : Map.Type Text Attr, content : Content }
let emptyNode
: Node
= { tag = None Text
, attrs = Map.empty Text Attr
, content = Content.Nodes ([] : List JSON.Type)
}
let contentToJSON
: Content → JSON.Type
= λ(content : Content)
→ merge
{ Nodes =
λ(ns : List JSON.Type)
→ JSON.object
(toMap { type = JSON.string "nodes", value = JSON.array ns })
, Markdown =
λ(s : Text)
→ JSON.object
( toMap
{ type = JSON.string "markdown", value = JSON.string s }
)
, Text =
λ(s : Text)
→ JSON.object
(toMap { type = JSON.string "text", value = JSON.string s })
, Raw =
λ(s : Text)
→ JSON.object
(toMap { type = JSON.string "raw", value = JSON.string s })
}
content
let locationToJSON
: Location → JSON.Type
= λ(location : Location)
→ merge
{ Environment =
λ(value : Text)
→ JSON.object
( toMap
{ type = JSON.string "Environment"
, value = JSON.string value
}
)
, Local =
λ(value : Text)
→ JSON.object
( toMap
{ type = JSON.string "Local", value = JSON.string value }
)
, Missing = JSON.object (toMap { type = JSON.string "Missing" })
, Remote =
λ(value : Text)
→ JSON.object
( toMap
{ type = JSON.string "Remote", value = JSON.string value }
)
}
location
let attrToJSON
: Attr → JSON.Type
= λ(attr : Attr)
→ merge
{ Text = λ(value : Text) → JSON.string value
, VersionedAsset =
λ(value : { path : Text, location : Location })
→ JSON.object
( toMap
{ path = JSON.string value.path
, location = locationToJSON value.location
}
)
}
attr
let nodeToJSON
: Node → JSON.Type
= λ(node : Node)
→ JSON.object
( toMap
{ tag =
Optional/fold Text node.tag JSON.Type JSON.string JSON.null
, attrs =
JSON.object
(Map.map Text Attr JSON.Type attrToJSON node.attrs)
, content = contentToJSON node.content
}
)
let node
: Text → Node
= λ(tag : Text) → emptyNode ⫽ { tag = Some tag }
let attrs
: Map.Type Text Text → { attrs : Map.Type Text Attr }
= λ(xs : Map.Type Text Text)
→ { attrs = Map.map Text Text Attr Attr.Text xs }
let attrsFull
: Map.Type Text Attr → { attrs : Map.Type Text Attr }
= λ(xs : Map.Type Text Attr) → { attrs = xs }
let content
: List Node → { content : Content }
= λ(ns : List Node)
→ { content = Content.Nodes (List/map Node JSON.Type nodeToJSON ns) }
let nodes
: List Node → Node
= λ(ns : List Node) → emptyNode ⫽ content ns
let markdown
: Text → Node
= λ(s : Text) → emptyNode ⫽ { content = Content.Markdown s }
let text
: Text → Node
= λ(s : Text) → emptyNode ⫽ { content = Content.Text s }
let raw
: Text → Node
= λ(s : Text) → emptyNode ⫽ { content = Content.Raw s }
in { Attr = Attr
, Node = Node
, node = node
, locationToJSON = locationToJSON
, nodeToJSON = nodeToJSON
, emptyNode = emptyNode
, text = text
, raw = raw
, markdown = markdown
, attrs = attrs
, attrsFull = attrsFull
, content = content
, nodes = nodes
}
let Html = ../Html.dhall
let node = Html.node
let attrs = Html.attrs
let content = Html.content
let Page = ./Page.dhall
let -- Build info (ormolu commit ..., ormolu-live commit ...)
buildInfo =
let ormolu =
(../ormolu-rev.dhall).ormolu
let ormolu-live = (../ormolu-rev.dhall).ormolu-live
in node
"p"
⫽ attrs (toMap { class = "build-info" })
⫽ content
[ Html.text
"ormolu commit "
, node
"a"
⫽ attrs
( toMap
{ href =
"https://github.com/tweag/ormolu/commit/${ormolu.rev}"
}
)
⫽ content
[ node "code" ⫽ content [ Html.text ormolu.rev-short ] ]
, Html.text ", ormolu-live commit "
, node
"a"
⫽ attrs
( toMap
{ href =
"https://github.com/monadfix/ormolu-live/commit/${ormolu-live.rev}"
}
)
⫽ content
[ node "code" ⫽ content [ Html.text ormolu-live.rev-short ]
]
]
let -- Live demo of Ormolu
liveDemo =
Html.nodes
[ node "div"
⫽ attrs (toMap { id = "ormolu-live" })
⫽ content
[ node "div"
⫽ attrs (toMap { class = "loading" })
⫽ content [ Html.text "...loading" ]
]
, node "script"
⫽ Html.attrsFull
( toMap
{ language = Html.Attr.Text "javascript"
, src =
Html.Attr.VersionedAsset
{ path = "/ormolu/all.min.js"
, location = ../ormolu-out/all.min.js as Location
}
, defer = Html.Attr.Text ""
}
)
]
in λ ( year
: Text
)
→ Page.toJSON
Page::{
, year = year
, title = "Ormolu live | Monadfix"
, extraHead =
Html.nodes
[ Page.stylesheetLocal
"/styles/ormolu.css"
../styles/ormolu.scss as Location
]
, main =
Html.nodes
[ Html.markdown
''
# Ormolu
[Ormolu](https://github.com/tweag/ormolu) is a modern Haskell formatter by Tweag I/O. It implements exactly one formatting style, respects the layout choice (single-line vs multi-line), and allows no other configuration.
Ormolu is already quite usable and can handle the complete GHC Haskell syntax. But its style is not set in stone, and some corner cases are still handled less gracefully than the others. So, we have adapted Ormolu for web to get more community feedback.
This live version runs entirely in the browser and does not send your code anywhere. Play with it and post your suggestions and issues to the [Ormolu issue tracker](https://github.com/tweag/ormolu/issues).
''
, buildInfo
, liveDemo
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment