on master help sign in
Make the sandwich generation simpler
16d6dc0Evan Czaplicki
builder/src/Generate/Html.hs+24−32
@@ -19,43 +19,35 @@ import qualified Elm.Name as N
19
19
20sandwich :: N.Name -> B.Builder -> B.Builder
20sandwich :: N.Name -> B.Builder -> B.Builder
21sandwich moduleName javascript =
21sandwich moduleName javascript =
22− header <> javascript <> footer (N.toBuilder moduleName)
22+ let name = N.toBuilder moduleName in
23−
24−
25−header :: B.Builder
26−header = [r|
27−<!DOCTYPE HTML>
23+ [r|<!DOCTYPE HTML>
28<html>
24<html>
29<head>
25<head>
30 <meta charset="UTF-8">
26 <meta charset="UTF-8">
27+ <title>|] <> name <> [r|</title>
31</head>
28</head>
32
29
33<body>
30<body>
34<div id="embed"></div>
31<div id="embed"></div>
35<script>
32<script>
36−|]
33+|] <> javascript <> [r|
37−
34+
38−
39−footer :: B.Builder -> B.Builder
40−footer name =
41− "</script>\n\
42− \<script>\n\
43− \// It is too complicated to figure out which kind of Program you created\n\
35+// It is too complicated to figure out which kind of Program you created
44− \// based on only the code. So here we check for different possibilities.\n\
36+// based on only the code. So here we check for different possibilities.
45− \//\n\
37+//
46− \// When you embed compiled Elm into HTML yourself, you should not copy/paste\n\
38+// When you embed compiled Elm into HTML yourself, you should not copy/paste
47− \// from here. Do just the part that makes sense for your application!\n\
39+// from here. Do just the part that makes sense for your application!
48− \//\n\
40+//
49− \var app =\n\
41+var app =
50− \ Elm." <> name <> ".fullscreen\n\
42+ Elm.|] <> name <> [r|.fullscreen
51− \ ? Elm." <> name <> ".fullscreen()\n\
43+ ? Elm.|] <> name <> [r|.fullscreen()
52− \ :\n\
44+ :
53− \ Elm." <> name <> ".embed\n\
45+ Elm.|] <> name <> [r|.embed
54− \ ? Elm." <> name <> ".embed(document.getElementById('embed'))\n\
46+ ? Elm.|] <> name <> [r|.embed(document.getElementById('embed'))
55− \ :\n\
47+ :
56− \ Elm." <> name <> ".worker\n\
48+ Elm.|] <> name <> [r|.worker
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\
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())
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\
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);
59− \</script>\n\
51+</script>
60− \</body>\n\
52+</body>
61− \</html>"
53+</html>|]