on master help sign in
* documentation for Language.Elm
c08f775Vincent Ambo
elm/src/Language/Elm.hs+29
@@ -1,5 +1,10 @@
1{-# LANGUAGE QuasiQuotes, TemplateHaskell #-}
1{-# LANGUAGE QuasiQuotes, TemplateHaskell #-}
2+{- | This module re-exports the modules necessary for compiling Elm code into the
3+ respective HTML, JS and CSS code.
2
4
5+ It also provides a predefined generateHtml function for use with the Blaze markup library
6+ as well as a simple QuasiQuoter for embedding literal elm code in a Haskell file.
7+-}
3module Language.Elm (
8module Language.Elm (
4 module Language.Elm.Initialize,
9 module Language.Elm.Initialize,
5 module Language.Elm.CompileToJS,
10 module Language.Elm.CompileToJS,
@@ -15,8 +20,32 @@ import Language.Elm.GenerateHtml
15import Language.Haskell.TH
20import Language.Haskell.TH
16import Language.Haskell.TH.Quote
21import Language.Haskell.TH.Quote
17
22
23+{- | This QuasiQuoter allows for literal embedding of elm source code within
24+ Haskell files. It is not responsible for the actual compilation Process.
25+ Usage:
26+
27+ @
28+ elmPage = [elm|
29+ main = image \"someImage.jpg\"
30+ |]
31+ @
32+
33+ How the elm code is compiled depends on how you intend to use it.
34+ Example uses are the included 'generateHtml' function as well as the
35+ "Language.Elm.Yesod" module.
36+-}
18elm :: QuasiQuoter
37elm :: QuasiQuoter
19elm = QuasiQuoter {quoteExp = \s -> [|s|] }
38elm = QuasiQuoter {quoteExp = \s -> [|s|] }
20
39
40+{- | elmFile is a quoteFile wrapper around the 'elm' QuasiQuoter and allows for
41+ external elm source files to be embedded.
42+ Usage:
43+
44+ @
45+ [elmFile|elm-source/page.elm|]
46+ @
47+
48+ Please note that no spaces should be added before and after the filename.
49+-}
21elmFile :: QuasiQuoter
50elmFile :: QuasiQuoter
22elmFile = quoteFile elm
51elmFile = quoteFile elm
elm/src/Language/Elm/GenerateHtml.hs+10
@@ -2,6 +2,7 @@
2module Language.Elm.GenerateHtml (generateHtml) where
2module Language.Elm.GenerateHtml (generateHtml) where
3
3
4import Text.Blaze (preEscapedToMarkup)
4import Text.Blaze (preEscapedToMarkup)
5+import Text.Blaze.Html (Html)
5import qualified Text.Blaze.Html5 as H
6import qualified Text.Blaze.Html5 as H
6import Text.Blaze.Html5 ((!))
7import Text.Blaze.Html5 ((!))
7import qualified Text.Blaze.Html5.Attributes as A
8import qualified Text.Blaze.Html5.Attributes as A
@@ -23,6 +24,15 @@ css = preEscapedToMarkup $
23makeScript :: String -> H.Html
24makeScript :: String -> H.Html
24makeScript s = H.script ! A.type_ "text/javascript" ! A.src (H.toValue s) $ ""
25makeScript s = H.script ! A.type_ "text/javascript" ! A.src (H.toValue s) $ ""
25
26
27+-- |This function compiles Elm code into simple HTML.
28+--
29+-- Usage example:
30+--
31+-- > generateHtml "/elm-min.js" "Some title" [elmFile|elm-source/somePage.elm|]
32+generateHtml :: String -- ^ Location of elm-min.js as expected by the browser
33+ -> String -- ^ The page title
34+ -> String -- ^ The elm source code.
35+ -> Html
26generateHtml libLoc title source =
36generateHtml libLoc title source =
27 let expr = initialize source
37 let expr = initialize source
28 js = compileToJS expr
38 js = compileToJS expr