@@ -6,7 +6,7 @@
7-- | This module contains Shakespearean (see "Text.Shakespeare") templates for Elm.
7-- | This module contains Shakespearean (see "Text.Shakespeare") templates for Elm.
8-- It introduces type-safe compile-time variable and URL interpolation. A typeclass
8-- 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.
11-- Further reading on Shakespearean templates: <http://www.yesodweb.com/book/templates>
11-- Further reading on Shakespearean templates: <http://www.yesodweb.com/book/templates>
@@ -14,8 +14,11 @@
14module Language.Elm.Quasi
14module Language.Elm.Quasi
15 ( -- * Functions
15 ( -- * Functions
16 -- ** Template-Reading Functions
16 -- ** Template-Reading Functions
17− -- | These QuasiQuoter and Template Haskell methods return values of
17+ -- |These QuasiQuoters return functions of the type @(t -> 'Elm')@
18− -- type @'ElmUrl' url@. See the Yesod book for details.
18+ -- where @t@ is the URL rendering function if type-safe URLs are used.
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.
21 , elmFileReload
24 , elmFileReload
@@ -39,7 +42,7 @@ import qualified Data.Text as TS
39import qualified Data.Text.Lazy as TL
42import qualified Data.Text.Lazy as TL
40import Text.Shakespeare
43import Text.Shakespeare
42−-- | Render Elm to lazy Text without route interpolation.
45+-- | Render Elm to lazy Text.
43renderElm :: Elm -> TL.Text
46renderElm :: Elm -> TL.Text
44renderElm (Elm b) = toLazyText b
47renderElm (Elm b) = toLazyText b
@@ -47,7 +50,7 @@ renderElm (Elm b) = toLazyText b
47newtype Elm = Elm { unElm :: Builder }
50newtype Elm = Elm { unElm :: Builder }
48 deriving Monoid
51 deriving Monoid
50−-- | A typeclass for types that can be interpolated in CoffeeScript templates.
53+-- | A typeclass for types that can be interpolated in Elm templates.
51class ToElm a where
54class ToElm a where
52 toElm :: a -> Builder
55 toElm :: a -> Builder
53instance ToElm [Char] where toElm = fromLazyText . TL.pack
56instance ToElm [Char] where toElm = fromLazyText . TL.pack
@@ -64,12 +67,21 @@ elmSettings = do
64 , unwrap = unWrapExp
67 , unwrap = unWrapExp
70+-- |QuasiQuoter for embedding Elm code inside of Haskell code.
73+-- @[elm|main = plaintext "Some elm code"|]@
67elm :: QuasiQuoter
74elm :: QuasiQuoter
68elm = QuasiQuoter { quoteExp = \s -> do
75elm = QuasiQuoter { quoteExp = \s -> do
69 rs <- elmSettings
76 rs <- elmSettings
70 quoteExp (shakespeare rs) s
77 quoteExp (shakespeare rs) s
80+-- |A Template Haskell function for embedding Elm code from external
84+-- @$(elmFile "elm_source/index.elm")@
73elmFile :: FilePath -> Q Exp
85elmFile :: FilePath -> Q Exp
74elmFile fp = do
86elmFile fp = do
75 rs <- elmSettings
87 rs <- elmSettings