on f4401ac help sign in
53 lines 1.0 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE QuasiQuotes #-}
3module Generate.Html
4 ( sandwich
5 )
6 where
9import qualified Data.ByteString.Builder as B
10import Data.Monoid ((<>))
11import qualified Data.Name as Name
12import Text.RawString.QQ (r)
16-- SANDWICH
19sandwich :: Name.Name -> B.Builder -> B.Builder
20sandwich moduleName javascript =
21 let name = Name.toBuilder moduleName in
22 [r|<!DOCTYPE HTML>
23<html>
24<head>
25 <meta charset="UTF-8">
26 <title>|] <> name <> [r|</title>
27 <style>body { padding: 0; margin: 0; }</style>
28</head>
30<body>
32<pre id="elm">
33This is a headless program, meaning there is nothing to show here.
35I started the program anyway though!
37You can access it as `app` in the developer console.
38</pre>
40<script>
41|] <> javascript <> [r|
43try {
44 var app = Elm.|] <> name <> [r|.init({ node: document.getElementById("elm") });
45} catch (e) {
46 // display initialization errors (e.g. bad flags, infinite recursion)
47 document.getElementById("elm").innerText = e;
48 throw e;
50</script>
52</body>
53</html>|]