on 42f3721 help sign in
42 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 Text.RawString.QQ (r)
13import qualified Elm.Name as N
17-- SANDWICH
20sandwich :: N.Name -> B.Builder -> B.Builder
21sandwich moduleName javascript =
22 let name = N.toBuilder moduleName in
23 [r|<!DOCTYPE HTML>
24<html>
25<head>
26 <meta charset="UTF-8">
27 <title>|] <> name <> [r|</title>
28</head>
30<body>
31<div id="elm-f0111bc4e658d0f98db96260c16f7e49"></div>
32<script>
33|] <> javascript <> [r|
35var app = Elm.|] <> name <> [r|.init({ node: document.getElementById("elm-f0111bc4e658d0f98db96260c16f7e49") });
36if (document.getElementById("elm-f0111bc4e658d0f98db96260c16f7e49"))
38 document.getElementById("elm-f0111bc4e658d0f98db96260c16f7e49").innerText = 'This is a headless program, meaning there is nothing to show here.\n\nI started the program anyway though, and you can access it as `app` in the developer console.';
40</script>
41</body>
42</html>|]