on 8f7c3cd help sign in
113 lines 2.9 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Develop.Generate.Help
4 ( makeHtml
5 , makeCodeHtml
6 , makeElmHtml
7 )
8 where
10import Text.Blaze.Html5 ((!))
11import qualified Text.Blaze.Html5 as H
12import qualified Text.Blaze.Html5.Attributes as A
14import qualified Develop.StaticFiles as StaticFiles
18-- PAGES
21makeHtml :: String -> String -> String -> H.Html
22makeHtml title jsFile initCode =
23 H.docTypeHtml $ do
24 H.head $ do
25 H.meta ! A.charset "UTF-8"
26 H.title $ H.toHtml title
27 H.link
28 ! A.type_ "text/css"
29 ! A.rel "stylesheet"
30 ! A.href (H.toValue ("/" ++ StaticFiles.cssPath))
31 H.script ! A.src (H.toValue jsFile) $ ""
33 H.body $ do
34 H.script $ H.preEscapedToMarkup initCode
38-- CODE
41makeCodeHtml :: String -> String -> H.Html
42makeCodeHtml title code =
43 H.docTypeHtml $ do
44 H.head $ do
45 H.meta ! A.charset "UTF-8"
46 H.title $ H.toHtml title
47 H.style ! A.type_ "text/css" $ codeStyle
49 H.link ! A.rel "stylesheet" ! A.href "//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/styles/default.min.css"
50 H.script ! A.src "//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/highlight.min.js" $ ""
51 H.script $ "if (hljs) { hljs.initHighlightingOnLoad(); }"
53 H.body ! A.style "background-color: #F0F0F0;" $ do
54 H.pre $ H.code $ H.toHtml code
57codeStyle :: H.Html
58codeStyle =
59 H.toHtml $ unlines $
60 [ "html, head, body, pre {"
61 , " margin: 0;"
62 , " height: 100%;"
63 , "}"
64 , "body {"
65 , " font-family: 'Source Code Pro', monospace;"
66 , "}"
67 ]
71-- ELM CODE
74makeElmHtml :: FilePath -> H.Html
75makeElmHtml filePath =
76 H.docTypeHtml $ do
77 H.head $ do
78 H.meta ! A.charset "UTF-8"
79 H.title $ H.toHtml ("~/" ++ filePath)
80 H.style ! A.type_ "text/css" $ elmStyle
82 H.body $ do
83 H.div ! A.style waitingStyle $ do
84 H.div ! A.style "font-size: 3em;" $ "Building your project!"
85 H.img ! A.src (H.toValue StaticFiles.waitingPath)
86 H.div ! A.style "font-size: 1em" $ "With new projects, I need a bunch of extra time to download packages."
88 H.script ! A.src (H.toValue ("/_compile/" ++ filePath)) ! A.charset "utf-8" $ ""
89 H.script $ H.preEscapedToMarkup $ unlines $
90 [ "while (document.body.firstChild) {"
91 , " document.body.removeChild(document.body.firstChild);"
92 , "}"
93 , "runElmProgram();"
94 ]
97elmStyle :: H.Html
98elmStyle =
99 H.toHtml $ unlines $
100 [ "@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro);"
101 , "html, head, body {"
102 , " margin: 0;"
103 , " height: 100%;"
104 , "}"
105 ]
108waitingStyle :: H.AttributeValue
109waitingStyle =
110 H.stringValue $
111 "width: 100%; height: 100%; display: flex; flex-direction: column;"
112 ++ " justify-content: center; align-items: center; color: #9A9A9A;"
113 ++ " font-family: 'Source Sans Pro';"