@@ -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/.
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.
18−module Language.Elm.Yesod (
22−import Control.Monad (liftM)
23−import Text.Blaze (preEscapedToMarkup)
25−import Yesod.Core (Route (..))
26−import Yesod.Handler (getUrlRenderParams, GHandler (..))
29−import Language.Elm.Quasi
31−import qualified Data.Text as TS
32−import qualified Data.Text.Lazy as TL
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())
39− urlF <- getUrlRenderParams
40− return $ mkElmWidget source urlF
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
49− toWidgetHead [julius| #{js} |]
53−-- | Return type of template-reading functions.
54−type ElmUrl url = (url -> [(TS.Text, TS.Text)] -> TS.Text) -> Elm
56−-- | Readability synonym for render function
57−type RenderFn url = (url -> [(TS.Text, TS.Text)] -> TS.Text)