1{-# LANGUAGE OverloadedStrings #-}
2module Generate.Html (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
18import Initialize (buildFromSource)
19import Generate.JavaScript
20import Generate.Noscript
21import Metadata.Libraries as Libraries
23data JSStyle = Minified | Readable
24data JSSource = Link String | Source JSStyle String
26makeScript :: JSSource -> H.Html
29 Link src -> H.script ! A.type_ "text/javascript" ! A.src (H.toValue src) $ ""
31 H.script ! A.type_ "text/javascript" $
32 preEscapedToMarkup $ case style of
33 Minified -> BS.unpack . minify . BS.pack $ src
36-- |This function compiles Elm code into simple HTML.
40-- > generateHtml "/elm-min.js" "Some title" [elmFile|elm-source/somePage.elm|]
41generateHtml :: String -- ^ Location of elm-runtime.js as expected by the browser
42 -> String -- ^ The page title
43 -> String -- ^ The elm source code.
45generateHtml libLoc title source = H.span "broken for now"
47 case buildFromSource True source of
48 Right modul -> createHtml libLoc title [] "" title [modul]
49 Left err -> createHtml Readable libLoc title (Right $ showErr err)
50 (H.noscript "") "Main"
53modulesToHtml :: FilePath -> String -> []
54modulesToHtml libLoc title scripts nscrpt modules =
55 createHtml jsStyle libLoc title' js noscript altTitle
57 js = Right $ jss ++ concatMap jsModule modules
58 noscript = if nscrpt then extractNoscript $ last modules else ""
59 title' = if null title then altTitle else title
60 altTitle = intercalate "." names
61 where Module names _ _ _ = last modules
64createHtml :: FilePath -> String -> [JSSource] -> String -> Html
65createHtml libLoc title scripts noscript =
68 H.meta ! A.charset "UTF-8"
69 H.title . H.toHtml $ title
70 makeScript (Link libLoc)
71 mapM_ makeScript scripts
73 H.script ! A.type_ "text/javascript" $ preEscapedToMarkup ("Elm.fullscreen(Elm.Main)" :: String)
74 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