@@ -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/.
6+ For example, you could modify your Yesod instance as follows:
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"
16+ A full example implementation is provided in the examples folder of the Elm github repository.
3module Language.Elm.Yesod (generateWidget) where
18module Language.Elm.Yesod (generateWidget) where
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;}
39+-- |generateWidget takes some Elm code in String format and produces a widget. Usage example:
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