on bf2e5eb help sign in
53 lines 1.5 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="embed"></div>
32<script>
33|] <> javascript <> [r|
35// It is too complicated to figure out which kind of Program you created
36// based on only the code. So here we check for different possibilities.
37//
38// When you embed compiled Elm into HTML yourself, you should not copy/paste
39// from here. Do just the part that makes sense for your application!
40//
41var app =
42 Elm.|] <> name <> [r|.fullscreen
43 ? Elm.|] <> name <> [r|.fullscreen()
44 :
45 Elm.|] <> name <> [r|.embed
46 ? Elm.|] <> name <> [r|.embed(document.getElementById('embed'))
47 :
48 Elm.|] <> name <> [r|.worker
49 ? (document.getElementById('embed').innerText = 'This is a headless program, meaning there is nothing to show here. I started the program anyway though, and you can access it as `app` in the developer console.', Elm.|] <> name <> [r|.worker())
50 : (document.getElementById('embed').innerText = 'I cannot figure out what kind of program this is supposed to be. Perhaps someone on Slack can help?', undefined);
51</script>
52</body>
53</html>|]