on master help sign in
* elm-yesod Example compiles (not yet using true URL interpolation)
commitc10efa0e2a4457ece7cb35bb173e633630e56360 authorVincent Ambo <v.ambo@me.com> dateWed 30 May 2012, 19:59 (14 years ago) parente0aa5c5
3 files changed+13−11
Examples/elm-yesod/Main.hs+4−7 Examples/elm-yesod/elm_source/index.elm+3−3 elm/src/Language/Elm.hs+6−1
Examples/elm-yesod/Main.hs+4−7
@@ -1,19 +1,16 @@
11{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedStrings, TypeFamilies, MultiParamTypeClasses #-}
22
33import Language.Elm
4+import Language.Elm.Quasi
45import Language.Elm.Yesod
56import Yesod
67import Text.Hamlet
78
89data ElmTest = ElmTest
910
10−-- embedding an external elm file (note: no spaces!)
11−rootPage :: Show a => a -> a -> a -> String
12−rootPage mouse clock shapes = [elmFile|elm_source/index.elm|]
11+mousePage = $(elmFile "elm_source/mouse.elm")
1312
14−mousePage = [elmFile|elm_source/mouse.elm|]
15−
16−clockPage = [elmFile|elm_source/clock.elm|]
13+clockPage = $(elmFile "elm_source/clock.elm")
1714
1815-- embedding elm code inside Haskell using the QuasiQuoter:
1916shapesPage = [elm|
@@ -63,7 +60,7 @@ getRootR = do
6360 clock = render ClockR
6461 shapes = render ShapesR
6562 setTitle "Welcome!"
66− elmWidget $ rootPage mouse clock shapes
63+ elmWidget $(elmFile "elm_source/index.elm")
6764
6865
6966-- Our Yesod instance contains the default layout, which inserts the elm-min.js
Examples/elm-yesod/elm_source/index.elm+3−3
@@ -25,9 +25,9 @@ info w = List.map (\f -> f ()) . List.intersperse (\x -> plainText "&nbsp;") . L
2525 toText ". Since you are looking at this page it is safe to assume that you already have the example code. "
2626 , text $ toText "Type-safe URLs are rendered using simple QuasiQuoter variable interpolation."
2727 , section "More examples:"
28− , text $ toText "- " ++ link ^{mouse} (toText "A simple mouse input example")
29− , text $ toText "- " ++ link ^{clock} (toText "An animated analog clock")
30− , text $ toText "- " ++ link ^{shapes} (toText "Some simple rendered shapes")
28+ , text $ toText "- " ++ link "#{mouse}" (toText "A simple mouse input example")
29+ , text $ toText "- " ++ link "#{clock}" (toText "An animated analog clock")
30+ , text $ toText "- " ++ link "#{shapes}" (toText "Some simple rendered shapes")
3131 ]
3232
3333body outer inner = width outer . box 2 . flow down . (:) (plainText "&nbsp;") $ info inner
elm/src/Language/Elm.hs+6−1
@@ -1,4 +1,4 @@
1−{-# LANGUAGE TypeSynonymInstances #-}
1+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
22{- | This module exports the functions necessary for compiling Elm code into the
33 respective HTML, JS and CSS code.
44
@@ -43,6 +43,11 @@ instance ElmSource TL.Text where
4343 toParts = toPartsHelper . TL.unpack
4444 toHtml elmL title = generateHtml elmL title . TL.unpack
4545
46+instance ElmSource (t -> Elm) where
47+ toParts s = toPartsHelper $ TL.unpack $ renderElm $ s undefined
48+ toHtml elmL title s = generateHtml elmL title $ TL.unpack $ renderElm $ s undefined
49+
50+
4651-- build helper to avoid boilerplate repetition
4752toPartsHelper :: String -> (Html, Html, String)
4853toPartsHelper source = (html, css, js)