on master help sign in
* updated documentation
commit231bedd0413815de80d4b7846895bec77d128d28 authorVincent Ambo <v.ambo@me.com> dateWed 30 May 2012, 21:49 (14 years ago) parentc6f9c18
5 files changed+30−11
Examples/elm-happstack/Main.hs+3 Examples/elm-yesod/Main.hs+4−4 elm-yesod/Language/Elm/Yesod.hs+2 elm/src/Language/Elm.hs+4−2 elm/src/Language/Elm/Quasi.hs+17−5
Examples/elm-happstack/Main.hs+3
@@ -8,6 +8,9 @@ import Language.Elm.Quasi
88elmLoc :: String
99elmLoc = "http://f.cl.ly/items/2e3Z3r3v29263U393c3x/elm-min.js"
1010
11+-- elmResponse is a "nice to have" helper function for compiling
12+-- Elm code when using Elm with Happstack. At some point this might
13+-- be moved to an elm-happstack package.
1114elmResponse :: ElmSource a
1215 => String -- ^ Page title
1316 -> a -- ^ elm source
Examples/elm-yesod/Main.hs+4−4
@@ -8,6 +8,7 @@ import Text.Hamlet
88
99data ElmTest = ElmTest
1010
11+-- loading external elm code
1112mousePage = $(elmFile "elm_source/mouse.elm")
1213
1314clockPage = $(elmFile "elm_source/clock.elm")
@@ -33,8 +34,9 @@ mkYesod "ElmTest" [parseRoutes|
3334/shapes ShapesR GET
3435|]
3536
36−-- generateWidget is called with the result of an Elm QuasiQuoter (which is just a
37−-- string containing some Elm code, with proper newline escaping)
37+-- elmWidget takes some elm source code and returns the finished elm widget
38+-- inside the GHandler monad. URL interpolation is done automatically, all
39+-- interpolated variables have to be in scope when the elmWidget call happens.
3840getMouseR :: Handler RepHtml
3941getMouseR = do
4042 widget <- elmWidget mousePage
@@ -56,8 +58,6 @@ getShapesR = do
5658 setTitle "Simple shapes"
5759 widget
5860
59−-- URLs are rendered manually and then passed on to the function containing
60−-- the elm QuasiQuoter.
6161getRootR :: Handler RepHtml
6262getRootR = do
6363 widget <- elmWidget $(elmFile "elm_source/index.elm")
elm-yesod/Language/Elm/Yesod.hs+2
@@ -31,6 +31,8 @@ import Language.Elm.Quasi
3131import qualified Data.Text as TS
3232import qualified Data.Text.Lazy as TL
3333
34+-- |elmWidget returns a Yesod widget from some Elm source code
35+-- with URL interpolation.
3436elmWidget :: ElmUrl (Route master) -- ^ Elm source code
3537 -> GHandler sub master (GWidget sub master())
3638elmWidget source = do
elm/src/Language/Elm.hs+4−2
@@ -2,8 +2,9 @@
22{- | This module exports the functions necessary for compiling Elm code into the
33 respective HTML, JS and CSS code.
44
5− It also provides a predefined compileToHtml function for use with the Blaze markup library
6− as well as a simple QuasiQuoter for embedding literal elm code in a Haskell file.
5+ The type class @'ElmSource'@ requires an instance for all types that the Elm compiler
6+ understands. The provided instances for String, Text and QuasiQuoted Elm source code
7+ should be sufficient.
78
89 The documentation for the Elm language is available at <http://elm-lang.org/Documentation.elm>
910-}
@@ -25,6 +26,7 @@ class ElmSource a where
2526 -- and JavaScript. The HTML is only the contents of the body, so the three
2627 -- parts must be combined in a basic HTML skeleton.
2728 toParts :: a -> (Html, Html, String)
29+
2830 -- |This function compiles Elm code into a full HTML page.
2931 toHtml :: String -- ^ Location of elm-min.js as expected by the browser
3032 -> String -- ^ The page title
elm/src/Language/Elm/Quasi.hs+17−5
@@ -6,7 +6,7 @@
66
77-- | This module contains Shakespearean (see "Text.Shakespeare") templates for Elm.
88-- It introduces type-safe compile-time variable and URL interpolation. A typeclass
9−-- 'ToElm' is provided for interpolated variables.
9+-- @'ToElm'@ is provided for interpolated variables.
1010--
1111-- Further reading on Shakespearean templates: <http://www.yesodweb.com/book/templates>
1212--
@@ -14,8 +14,11 @@
1414module Language.Elm.Quasi
1515 ( -- * Functions
1616 -- ** Template-Reading Functions
17− -- | These QuasiQuoter and Template Haskell methods return values of
18− -- type @'ElmUrl' url@. See the Yesod book for details.
17+ -- |These QuasiQuoters return functions of the type @(t -> 'Elm')@
18+ -- where @t@ is the URL rendering function if type-safe URLs are used.
19+ --
20+ -- A usage example for both type-safe (Yesod) and standard path segment (Happstack)
21+ -- URLs is provided in the Examples folder in the Git repository.
1922 elm
2023 , elmFile
2124 , elmFileReload
@@ -39,7 +42,7 @@ import qualified Data.Text as TS
3942import qualified Data.Text.Lazy as TL
4043import Text.Shakespeare
4144
42−-- | Render Elm to lazy Text without route interpolation.
45+-- | Render Elm to lazy Text.
4346renderElm :: Elm -> TL.Text
4447renderElm (Elm b) = toLazyText b
4548
@@ -47,7 +50,7 @@ renderElm (Elm b) = toLazyText b
4750newtype Elm = Elm { unElm :: Builder }
4851 deriving Monoid
4952
50−-- | A typeclass for types that can be interpolated in CoffeeScript templates.
53+-- | A typeclass for types that can be interpolated in Elm templates.
5154class ToElm a where
5255 toElm :: a -> Builder
5356instance ToElm [Char] where toElm = fromLazyText . TL.pack
@@ -64,12 +67,21 @@ elmSettings = do
6467 , unwrap = unWrapExp
6568 }
6669
70+-- |QuasiQuoter for embedding Elm code inside of Haskell code.
71+--
72+-- Usage:
73+-- @[elm|main = plaintext "Some elm code"|]@
6774elm :: QuasiQuoter
6875elm = QuasiQuoter { quoteExp = \s -> do
6976 rs <- elmSettings
7077 quoteExp (shakespeare rs) s
7178 }
7279
80+-- |A Template Haskell function for embedding Elm code from external
81+-- .elm files.
82+--
83+-- Usage:
84+-- @$(elmFile "elm_source/index.elm")@
7385elmFile :: FilePath -> Q Exp
7486elmFile fp = do
7587 rs <- elmSettings