@@ -25,6 +25,18 @@ css = H.style ! A.type_ "text/css" $ preEscapedToMarkup
2525makeScript :: String -> H.Html
2626makeScript s = H.script ! A.type_ "text/javascript" ! A.src (H.toValue s) $ ""
2727
28+scriptForModule :: String -> H.Html
29+scriptForModule modul =
30+ makeScript $ "/" ++ map (\c -> if c == '.' then '/' else c) modul ++ ".js"
31+
32+builtInModules =
33+ concat [ map ("Data."++) [ "List", "Char", "Maybe" ]
34+ , map ("Signal."++) [ "Mouse", "Keyboard.Raw"
35+ , "Window", "Time", "HTTP", "Input", "Random" ]
36+ , [ "Element", "Text", "Color", "Line" ]
37+ , [ "Prelude" ]
38+ ]
39+
2840-- |This function compiles Elm code into simple HTML.
2941--
3042-- Usage example:
@@ -36,6 +48,8 @@ generateHtml :: String -- ^ Location of elm-min.js as expected by the browser
3648 -> Html
3749generateHtml libLoc title source =
3850 let modul = initialize source
51+ imports = filter (`notElem` builtInModules) $
52+ either (const []) (\(Module _ _ is _) -> map fst is) modul
3953 js = compileToJS modul
4054 noscript = either id extract modul
4155 in
@@ -44,6 +58,7 @@ generateHtml libLoc title source =
4458 H.meta ! A.charset "UTF-8"
4559 H.title . H.toHtml $ title
4660 makeScript libLoc
61+ mapM scriptForModule imports
4762 H.script ! A.type_ "text/javascript" $ preEscapedToMarkup js
4863 css
4964 H.body $ body noscript