on master help sign in
* updated elm-yesod example for elm-yesod 0.1.2
38b4894Vincent Ambo
Examples/elm-yesod/Main.hs+19−19
@@ -17,7 +17,7 @@ clockPage = $(elmFile "elm_source/clock.elm")
17shapesPage = [elm|
17shapesPage = [elm|
18square = rect 200 200 (150,150)
18square = rect 200 200 (150,150)
19circle = oval 140 140 (150,150)
19circle = oval 140 140 (150,150)
20−pentagon = ngon 5 60 (150,150)
20+pentagon = ngon 5 60 (150,150) --@
21
21
22main = collage 300 300
22main = collage 300 300
23 [ outlined black square
23 [ outlined black square
@@ -34,48 +34,48 @@ mkYesod "ElmTest" [parseRoutes|
34/shapes ShapesR GET
34/shapes ShapesR GET
35|]
35|]
36
36
37−-- elmWidget takes some elm source code and returns the finished elm widget
37+-- Your App data type needs to have an instance of YesodElm (see line 75&76)
38−-- inside the GHandler monad. URL interpolation is done automatically, all
38+-- so that toWidget can work with QuasiQuoted elm code. All URL interpolation
39−-- interpolated variables have to be in scope when the elmWidget call happens.
39+-- is done automatically. (e.g. lines 28-30 in elm_source/index.elm)
40getMouseR :: Handler RepHtml
40getMouseR :: Handler RepHtml
41−getMouseR = do
41+getMouseR =
42− widget <- elmWidget mousePage
43− defaultLayout $ do
42+ defaultLayout $ do
44 setTitle "Mouse position demo"
43 setTitle "Mouse position demo"
45− widget
44+ toWidget mousePage
46
45
47getClockR :: Handler RepHtml
46getClockR :: Handler RepHtml
48−getClockR = do
47+getClockR =
49− widget <- elmWidget clockPage
50 defaultLayout $ do
48 defaultLayout $ do
51 setTitle "A clock"
49 setTitle "A clock"
52− widget
50+ toWidget clockPage
53
51
54getShapesR :: Handler RepHtml
52getShapesR :: Handler RepHtml
55−getShapesR = do
53+getShapesR =
56− widget <- elmWidget shapesPage
57 defaultLayout $ do
54 defaultLayout $ do
58 setTitle "Simple shapes"
55 setTitle "Simple shapes"
59− widget
56+ toWidget shapesPage
60
57
61getRootR :: Handler RepHtml
58getRootR :: Handler RepHtml
62−getRootR = do
59+getRootR =
63− widget <- elmWidget $(elmFile "elm_source/index.elm")
64 defaultLayout $ do
60 defaultLayout $ do
65 setTitle "Welcome!"
61 setTitle "Welcome!"
66− widget
62+ toWidget $(elmFile "elm_source/index.elm")
67
63
68
64
69-- Our Yesod instance contains the default layout, which inserts the elm-min.js
65-- Our Yesod instance contains the default layout, which inserts the elm-min.js
70−-- file in the site's <head> tag.
66+-- file in the site's <head> tag. The YesodElm instance defines the location of
67+-- elm-min.js
68+
71instance Yesod ElmTest where
69instance Yesod ElmTest where
72 jsLoader _ = BottomOfHeadBlocking
70 jsLoader _ = BottomOfHeadBlocking
73 defaultLayout widget = do
71 defaultLayout widget = do
74 mmsg <- getMessage
72 mmsg <- getMessage
75 pc <- widgetToPageContent $ do
73 pc <- widgetToPageContent $ do
76− addScriptRemote $ "http://f.cl.ly/items/2e3Z3r3v29263U393c3x/elm-min.js"
77 $(whamletFile "templates/default-layout.hamlet")
74 $(whamletFile "templates/default-layout.hamlet")
78 hamletToRepHtml $(hamletFile "templates/default-layout-wrapper.hamlet")
75 hamletToRepHtml $(hamletFile "templates/default-layout-wrapper.hamlet")
79
76
77+instance YesodElm ElmTest where
78+ urlElmJs _ = Right $ "http://f.cl.ly/items/2e3Z3r3v29263U393c3x/elm-min.js"
79+
80main :: IO ()
80main :: IO ()
81main = warpDebug 3000 ElmTest
81main = warpDebug 3000 ElmTest