@@ -1,57 +0,0 @@
1−{-# LANGUAGE QuasiQuotes, TypeSynonymInstances #-}
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/.
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−-}
18−module Language.Elm.Yesod (
19− elmWidget
20− , ElmUrl) where
21−
22−import Control.Monad (liftM)
23−import Text.Blaze (preEscapedToMarkup)
24−import Text.Julius
25−import Yesod.Core (Route (..))
26−import Yesod.Handler (getUrlRenderParams, GHandler (..))
27−import Yesod.Widget
28−import Language.Elm
29−import Language.Elm.Quasi
30−
31−import qualified Data.Text as TS
32−import qualified Data.Text.Lazy as TL
33−
34−-- |elmWidget returns a Yesod widget from some Elm source code
35−-- with URL interpolation.
36−elmWidget :: ElmUrl (Route master) -- ^ Elm source code
37− -> GHandler sub master (GWidget sub master())
38−elmWidget source = do
39− urlF <- getUrlRenderParams
40− return $ mkElmWidget source urlF
41−
42−
43−mkElmWidget :: ElmUrl (Route master) -- ^ Elm source code
44− -> RenderFn (Route master) -- ^ URL rendering function
45− -> GWidget sub master ()
46−mkElmWidget source urlFn =
47− let (html, css, js) = toParts (urlFn, source) in
48− do toWidgetHead css
49− toWidgetHead [julius| #{js} |]
50− toWidgetBody html
51−
52−
53−-- | Return type of template-reading functions.
54−type ElmUrl url = (url -> [(TS.Text, TS.Text)] -> TS.Text) -> Elm
55−
56−-- | Readability synonym for render function
57−type RenderFn url = (url -> [(TS.Text, TS.Text)] -> TS.Text)