on master help sign in
* elm-yesod Example compiles (not yet using true URL interpolation)
c10efa0Vincent Ambo
Examples/elm-yesod/Main.hs+4−7
@@ -1,19 +1,16 @@
1{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedStrings, TypeFamilies, MultiParamTypeClasses #-}
1{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedStrings, TypeFamilies, MultiParamTypeClasses #-}
2
2
3import Language.Elm
3import Language.Elm
4+import Language.Elm.Quasi
4import Language.Elm.Yesod
5import Language.Elm.Yesod
5import Yesod
6import Yesod
6import Text.Hamlet
7import Text.Hamlet
7
8
8data ElmTest = ElmTest
9data ElmTest = ElmTest
9
10
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")
13
12
14−mousePage = [elmFile|elm_source/mouse.elm|]
15−
16−clockPage = [elmFile|elm_source/clock.elm|]
13+clockPage = $(elmFile "elm_source/clock.elm")
17
14
18-- embedding elm code inside Haskell using the QuasiQuoter:
15-- embedding elm code inside Haskell using the QuasiQuoter:
19shapesPage = [elm|
16shapesPage = [elm|
@@ -63,7 +60,7 @@ getRootR = do
63 clock = render ClockR
60 clock = render ClockR
64 shapes = render ShapesR
61 shapes = render ShapesR
65 setTitle "Welcome!"
62 setTitle "Welcome!"
66− elmWidget $ rootPage mouse clock shapes
63+ elmWidget $(elmFile "elm_source/index.elm")
67
64
68
65
69-- Our Yesod instance contains the default layout, which inserts the elm-min.js
66-- 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 " ") . L
25 toText ". Since you are looking at this page it is safe to assume that you already have the example code. "
25 toText ". Since you are looking at this page it is safe to assume that you already have the example code. "
26 , text $ toText "Type-safe URLs are rendered using simple QuasiQuoter variable interpolation."
26 , text $ toText "Type-safe URLs are rendered using simple QuasiQuoter variable interpolation."
27 , section "More examples:"
27 , section "More examples:"
28− , text $ toText "- " ++ link ^{mouse} (toText "A simple mouse input example")
28+ , text $ toText "- " ++ link "#{mouse}" (toText "A simple mouse input example")
29− , text $ toText "- " ++ link ^{clock} (toText "An animated analog clock")
29+ , text $ toText "- " ++ link "#{clock}" (toText "An animated analog clock")
30− , text $ toText "- " ++ link ^{shapes} (toText "Some simple rendered shapes")
30+ , text $ toText "- " ++ link "#{shapes}" (toText "Some simple rendered shapes")
31 ]
31 ]
32
32
33body outer inner = width outer . box 2 . flow down . (:) (plainText " ") $ info inner
33body outer inner = width outer . box 2 . flow down . (:) (plainText " ") $ info inner
elm/src/Language/Elm.hs+6−1
@@ -1,4 +1,4 @@
1−{-# LANGUAGE TypeSynonymInstances #-}
1+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
2{- | This module exports the functions necessary for compiling Elm code into the
2{- | This module exports the functions necessary for compiling Elm code into the
3 respective HTML, JS and CSS code.
3 respective HTML, JS and CSS code.
4
4
@@ -43,6 +43,11 @@ instance ElmSource TL.Text where
43 toParts = toPartsHelper . TL.unpack
43 toParts = toPartsHelper . TL.unpack
44 toHtml elmL title = generateHtml elmL title . TL.unpack
44 toHtml elmL title = generateHtml elmL title . TL.unpack
45
45
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+
46-- build helper to avoid boilerplate repetition
51-- build helper to avoid boilerplate repetition
47toPartsHelper :: String -> (Html, Html, String)
52toPartsHelper :: String -> (Html, Html, String)
48toPartsHelper source = (html, css, js)
53toPartsHelper source = (html, css, js)