on 6a96e21 help sign in
61 lines 1.7 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 header <> javascript <> footer (N.toBuilder moduleName)
25header :: B.Builder
26header = [r|
27<!DOCTYPE HTML>
28<html>
29<head>
30 <meta charset="UTF-8">
31</head>
33<body>
34<div id="embed"></div>
35<script>
36|]
39footer :: B.Builder -> B.Builder
40footer name =
41 "</script>\n\
42 \<script>\n\
43 \// It is too complicated to figure out which kind of Program you created\n\
44 \// based on only the code. So here we check for different possibilities.\n\
45 \//\n\
46 \// When you embed compiled Elm into HTML yourself, you should not copy/paste\n\
47 \// from here. Do just the part that makes sense for your application!\n\
48 \//\n\
49 \var app =\n\
50 \ Elm." <> name <> ".fullscreen\n\
51 \ ? Elm." <> name <> ".fullscreen()\n\
52 \ :\n\
53 \ Elm." <> name <> ".embed\n\
54 \ ? Elm." <> name <> ".embed(document.getElementById('embed'))\n\
55 \ :\n\
56 \ Elm." <> name <> ".worker\n\
57 \ ? (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 <> ".worker())\n\
58 \ : (document.getElementById('embed').innerText = 'I cannot figure out what kind of program this is supposed to be. Perhaps someone on Slack can help?', undefined);\n\
59 \</script>\n\
60 \</body>\n\
61 \</html>"