on 096ff99 help sign in
elk/src/GenerateHtml.hs
42 lines 1.5 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2module GenerateHtml (generateHtml) where
4import Text.Blaze (preEscapedToMarkup)
5import qualified Text.Blaze.Html5 as H
6import Text.Blaze.Html5 ((!))
7import qualified Text.Blaze.Html5.Attributes as A
9import Initialize
10import CompileToJS
11import ExtractNoscript
13css = preEscapedToMarkup $
14 ("* { padding:0; margin:0; \
15 \hyphens: auto; -moz-hyphens: auto;\
16 \ -webkit-hyphens: auto; -ms-hyphens: auto; }\
17 \body { font-family: Arial; }\
18 \a:link {text-decoration: none}\
19 \a:visited {text-decoration: none}\
20 \a:active {text-decoration: none}\
21 \a:hover {text-decoration: underline; color: #ff8f12;}" :: String)
23makeScript :: String -> H.Html
24makeScript s = H.script ! A.type_ "text/javascript" ! A.src (H.toValue s) $ ""
26generateHtml libLoc title source =
27 let expr = initialize source
28 js = compileToJS expr
29 noscript = either id extract expr
30 in
31 H.docTypeHtml $ do
32 H.head $ do
33 H.meta ! A.charset "UTF-8"
34 H.title . H.toHtml $ title
35 makeScript libLoc
36 H.script ! A.type_ "text/javascript" $ preEscapedToMarkup js
37 H.style ! A.type_ "text/css" $ css
38 H.body $ do
39 H.div ! A.id "widthChecker" ! A.style "width:100%; height:1px; position:absolute; top:-1px;" $ ""
40 H.span ! A.id "content" $ ""
41 H.script ! A.type_ "text/javascript" $ "Dispatcher.initialize()"
42 H.noscript $ preEscapedToMarkup noscript