on master help sign in
* documentation for Language.Elm
commitc08f7756c61ae40890271ec1803c527a67868772 authorVincent Ambo <v.ambo@me.com> dateMon 28 May 2012, 18:02 (14 years ago) parent97025a0
2 files changed+39
elm/src/Language/Elm.hs+29 elm/src/Language/Elm/GenerateHtml.hs+10
elm/src/Language/Elm.hs+29
@@ -1,5 +1,10 @@
11{-# LANGUAGE QuasiQuotes, TemplateHaskell #-}
2+{- | This module re-exports the modules necessary for compiling Elm code into the
3+ respective HTML, JS and CSS code.
24
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+-}
38module Language.Elm (
49 module Language.Elm.Initialize,
510 module Language.Elm.CompileToJS,
@@ -15,8 +20,32 @@ import Language.Elm.GenerateHtml
1520import Language.Haskell.TH
1621import Language.Haskell.TH.Quote
1722
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+-}
1837elm :: QuasiQuoter
1938elm = QuasiQuoter {quoteExp = \s -> [|s|] }
2039
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+-}
2150elmFile :: QuasiQuoter
2251elmFile = quoteFile elm
elm/src/Language/Elm/GenerateHtml.hs+10
@@ -2,6 +2,7 @@
22module Language.Elm.GenerateHtml (generateHtml) where
33
44import Text.Blaze (preEscapedToMarkup)
5+import Text.Blaze.Html (Html)
56import qualified Text.Blaze.Html5 as H
67import Text.Blaze.Html5 ((!))
78import qualified Text.Blaze.Html5.Attributes as A
@@ -23,6 +24,15 @@ css = preEscapedToMarkup $
2324makeScript :: String -> H.Html
2425makeScript s = H.script ! A.type_ "text/javascript" ! A.src (H.toValue s) $ ""
2526
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
2636generateHtml libLoc title source =
2737 let expr = initialize source
2838 js = compileToJS expr