on 727d708 help sign in
72 lines 2.5 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2module Generate.Html
3 (generateHtml,
4 createHtml,
5 JSStyle (..),
6 JSSource (..)
7 ) where
9import Text.Blaze (preEscapedToMarkup)
10import qualified Text.Blaze.Html5 as H
11import Text.Blaze.Html5 ((!))
12import qualified Text.Blaze.Html5.Attributes as A
14import Text.Jasmine (minify)
15import qualified Data.ByteString.Lazy.Char8 as BS
17import Initialize (buildFromSource)
18import Generate.JavaScript
19import Generate.Noscript
21data JSStyle = Minified | Readable
22data JSSource = Link String | Source JSStyle String
24makeScript :: JSSource -> H.Html
25makeScript source =
26 case source of
27 Link src -> H.script ! A.type_ "text/javascript" ! A.src (H.toValue src) $ ""
28 Source style src ->
29 H.script ! A.type_ "text/javascript" $
30 preEscapedToMarkup $ case style of
31 Minified -> BS.unpack . minify . BS.pack $ src
32 Readable -> src
34-- |This function compiles Elm code into simple HTML.
35--
36-- Usage example:
37--
38-- > generateHtml "/elm-min.js" "Some title" [elmFile|elm-source/somePage.elm|]
39generateHtml :: String -- ^ Location of elm-runtime.js as expected by the browser
40 -> String -- ^ The page title
41 -> String -- ^ The elm source code.
42 -> H.Html
43generateHtml libLoc title source = H.span "broken for now"
44{--
45 case buildFromSource True source of
46 Right modul -> createHtml libLoc title [] "" title [modul]
47 Left err -> createHtml Readable libLoc title (Right $ showErr err)
48 (H.noscript "") "Main"
49--}
50{--
51modulesToHtml :: FilePath -> String -> []
52modulesToHtml libLoc title scripts nscrpt modules =
53 createHtml jsStyle libLoc title' js noscript altTitle
54 where
55 js = Right $ jss ++ concatMap jsModule modules
56 noscript = if nscrpt then extractNoscript $ last modules else ""
57 title' = if null title then altTitle else title
58 altTitle = intercalate "." names
59 where Module names _ _ _ = last modules
60--}
62createHtml :: FilePath -> String -> [JSSource] -> String -> H.Html
63createHtml libLoc title scripts noscript =
64 H.docTypeHtml $ do
65 H.head $ do
66 H.meta ! A.charset "UTF-8"
67 H.title . H.toHtml $ title
68 makeScript (Link libLoc)
69 mapM_ makeScript scripts
70 H.body $ do
71 H.script ! A.type_ "text/javascript" $ preEscapedToMarkup ("Elm.fullscreen(Elm.Main)" :: String)
72 H.noscript $ preEscapedToMarkup noscript