on master help sign in
* documentation for Language.Elm.Yesod
4fa6d80Vincent Ambo
elm-yesod/Language/Elm/Yesod.hs+20−1
@@ -1,5 +1,20 @@
1{-# LANGUAGE QuasiQuotes #-}
1{-# LANGUAGE QuasiQuotes #-}
2+{- | This module provides a function for compiling Elm source code into a Yesod widget.
3+ In order to use this with your Yesod app, you need to define a defaultLayout like
4+ function that embeds the elm-min.js file /in the <head> tag/.
2
5
6+ For example, you could modify your Yesod instance as follows:
7+
8+ > instance Yesod App where
9+ > jsLoader _ = BottomOfHeadBlocking -- moves JS to the <head> tag
10+ > defaultLayout widget = do
11+ > pc <- widgetToPageContent $ do
12+ > addScriptRemote $ "http://somecdn.org/link/to/elm-min.js"
13+ > ...
14+ > ...
15+
16+ A full example implementation is provided in the examples folder of the Elm github repository.
17+-}
3module Language.Elm.Yesod (generateWidget) where
18module Language.Elm.Yesod (generateWidget) where
4
19
5import Text.Blaze (preEscapedToMarkup)
20import Text.Blaze (preEscapedToMarkup)
@@ -21,7 +36,11 @@ a:link, a:visited, a:active { text-decoration: none}
21a:hover {text-decoration: underline; color: #ff8f12;}
36a:hover {text-decoration: underline; color: #ff8f12;}
22|]
37|]
23
38
39+-- |generateWidget takes some Elm code in String format and produces a widget. Usage example:
40+--
41+-- > generateWidget [elmFile|elm-source/somePage.elm|]
42+generateWidget :: String -- ^ The Elm source code
24−generateWidget :: String -> GWidget sub master ()
43+ -> GWidget sub master ()
25generateWidget source =
44generateWidget source =
26 let expr = initialize source
45 let expr = initialize source
27 js = compileToJS expr
46 js = compileToJS expr