1{-# LANGUAGE OverloadedStrings #-}
2module GenerateHtml (generateHtml,
8import Data.List (intercalate)
9import Text.Blaze (preEscapedToMarkup)
10import Text.Blaze.Html (Html)
11import qualified Text.Blaze.Html5 as H
12import Text.Blaze.Html5 ((!))
13import qualified Text.Blaze.Html5.Attributes as A
15import Text.Jasmine (minify)
16import qualified Data.ByteString.Lazy.Char8 as BS
19import Initialize (buildFromSource)
22import Libraries as Libraries
24data JSStyle = Minified | Readable
25data JSSource = Link String | Source JSStyle String
27makeScript :: JSSource -> H.Html
30 Link src -> H.script ! A.type_ "text/javascript" ! A.src (H.toValue src) $ ""
32 H.script ! A.type_ "text/javascript" $
33 preEscapedToMarkup $ case style of
34 Minified -> BS.unpack . minify . BS.pack $ src
37-- |This function compiles Elm code into simple HTML.
41-- > generateHtml "/elm-min.js" "Some title" [elmFile|elm-source/somePage.elm|]
42generateHtml :: String -- ^ Location of elm-runtime.js as expected by the browser
43 -> String -- ^ The page title
44 -> String -- ^ The elm source code.
46generateHtml libLoc title source = H.span "broken for now"
48 case buildFromSource True source of
49 Right modul -> createHtml libLoc title [] "" title [modul]
50 Left err -> createHtml Readable libLoc title (Right $ showErr err)
51 (H.noscript "") "Main"
54modulesToHtml :: FilePath -> String -> []
55modulesToHtml libLoc title scripts nscrpt modules =
56 createHtml jsStyle libLoc title' js noscript altTitle
58 js = Right $ jss ++ concatMap jsModule modules
59 noscript = if nscrpt then extractNoscript $ last modules else ""
60 title' = if null title then altTitle else title
61 altTitle = intercalate "." names
62 where Module names _ _ _ = last modules
65createHtml :: FilePath -> String -> [JSSource] -> String -> Html
66createHtml libLoc title scripts noscript =
69 H.meta ! A.charset "UTF-8"
70 H.title . H.toHtml $ title
71 makeScript (Link libLoc)
72 mapM_ makeScript scripts
74 H.script ! A.type_ "text/javascript" $ preEscapedToMarkup ("Elm.fullscreen(Elm.Main)" :: String)
75 H.noscript $ preEscapedToMarkup noscript
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list