@@ -1,7 +1,8 @@
11{-# LANGUAGE OverloadedStrings #-}
22module GenerateHtml (generateHtml,
33 body, css, widgetBody,
4− modulesToHtml, linkedHtml
4+ modulesToHtml, linkedHtml,
5+ JSStyle (..)
56 ) where
67
78import Data.List (intercalate)
@@ -11,6 +12,9 @@ import qualified Text.Blaze.Html5 as H
1112import Text.Blaze.Html5 ((!))
1213import qualified Text.Blaze.Html5.Attributes as A
1314
15+import Text.Jasmine (minify)
16+import qualified Data.ByteString.Lazy.Char8 as BS
17+
1418import Ast
1519import Initialize
1620import CompileToJS
@@ -28,11 +32,15 @@ css = H.style ! A.type_ "text/css" $ preEscapedToMarkup
2832 \ -webkit-hyphens: auto; -ms-hyphens: auto; }\
2933--}
3034
31−makeScript :: Either String String -> H.Html
32−makeScript (Left s) =
35+data JSStyle = Minified | Readable
36+
37+makeScript :: JSStyle -> Either String String -> H.Html
38+makeScript _ (Left s) =
3339 H.script ! A.type_ "text/javascript" ! A.src (H.toValue s) $ ""
34−makeScript (Right s) =
35− H.script ! A.type_ "text/javascript" $ preEscapedToMarkup s
40+makeScript jsStyle (Right s) = H.script ! A.type_ "text/javascript" $ preEscapedToMarkup content
41+ where content = case jsStyle of
42+ Minified -> BS.unpack . minify . BS.pack $ s
43+ Readable -> s
3644
3745-- |This function compiles Elm code into simple HTML.
3846--
@@ -45,11 +53,11 @@ generateHtml :: String -- ^ Location of elm-min.js as expected by the browser
4553 -> Html
4654generateHtml libLoc title source =
4755 case initialize source of
48− Left err -> createHtml libLoc title (Right $ showErr err) (H.noscript "")
49− Right (escs, modul) -> modulesToHtml title libLoc [] True [(escs,modul)]
56+ Left err -> createHtml Readable libLoc title (Right $ showErr err) (H.noscript "")
57+ Right (escs, modul) -> modulesToHtml Readable title libLoc [] True [(escs,modul)]
5058
5159
52−modulesToHtml title libLoc jss nscrpt pairs = createHtml libLoc title' js noscript
60+modulesToHtml jsStyle title libLoc jss nscrpt pairs = createHtml jsStyle libLoc title' js noscript
5361 where modules = map snd pairs
5462 js = Right $ jss ++ concatMap jsModule pairs
5563 noscript = if nscrpt then extract $ last modules else ""
@@ -59,20 +67,21 @@ modulesToHtml title libLoc jss nscrpt pairs = createHtml libLoc title' js noscri
5967
6068
6169linkedHtml rtLoc jsLoc modules =
62− createHtml rtLoc title (Left jsLoc) (H.noscript "")
70+ createHtml Readable rtLoc title (Left jsLoc) (H.noscript "")
6371 where title = (\(Module names _ _ _) -> intercalate "." names) $
6472 snd (last modules)
6573
6674
67−createHtml libLoc title js noscript =
75+createHtml jsStyle libLoc title js noscript =
6876 H.docTypeHtml $ do
6977 H.head $ do
7078 H.meta ! A.charset "UTF-8"
7179 H.title . H.toHtml $ title
72− makeScript (Left libLoc)
73− makeScript js
7480 css
75− H.body $ body noscript
81+ H.body $ do
82+ makeScript Readable (Left libLoc)
83+ makeScript jsStyle js
84+ body noscript
7685
7786body noscript = do
7887 H.div ! A.id "widthChecker" ! A.style "width:100%; height:1px; position:absolute; top:-1px;" $ ""