@@ -17,7 +17,7 @@ clockPage = $(elmFile "elm_source/clock.elm")
1717shapesPage = [elm|
1818square = rect 200 200 (150,150)
1919circle = oval 140 140 (150,150)
20−pentagon = ngon 5 60 (150,150)
20+pentagon = ngon 5 60 (150,150) --@
2121
2222main = collage 300 300
2323 [ outlined black square
@@ -34,48 +34,48 @@ mkYesod "ElmTest" [parseRoutes|
3434/shapes ShapesR GET
3535|]
3636
37−-- elmWidget takes some elm source code and returns the finished elm widget
38−-- inside the GHandler monad. URL interpolation is done automatically, all
39−-- interpolated variables have to be in scope when the elmWidget call happens.
37+-- Your App data type needs to have an instance of YesodElm (see line 75&76)
38+-- so that toWidget can work with QuasiQuoted elm code. All URL interpolation
39+-- is done automatically. (e.g. lines 28-30 in elm_source/index.elm)
4040getMouseR :: Handler RepHtml
41−getMouseR = do
42− widget <- elmWidget mousePage
43− defaultLayout $ do
41+getMouseR =
42+ defaultLayout $ do
4443 setTitle "Mouse position demo"
45− widget
44+ toWidget mousePage
4645
4746getClockR :: Handler RepHtml
48−getClockR = do
49− widget <- elmWidget clockPage
47+getClockR =
5048 defaultLayout $ do
5149 setTitle "A clock"
52− widget
50+ toWidget clockPage
5351
5452getShapesR :: Handler RepHtml
55−getShapesR = do
56− widget <- elmWidget shapesPage
53+getShapesR =
5754 defaultLayout $ do
5855 setTitle "Simple shapes"
59− widget
56+ toWidget shapesPage
6057
6158getRootR :: Handler RepHtml
62−getRootR = do
63− widget <- elmWidget $(elmFile "elm_source/index.elm")
59+getRootR =
6460 defaultLayout $ do
6561 setTitle "Welcome!"
66− widget
62+ toWidget $(elmFile "elm_source/index.elm")
6763
6864
6965-- 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+
7169instance Yesod ElmTest where
7270 jsLoader _ = BottomOfHeadBlocking
7371 defaultLayout widget = do
7472 mmsg <- getMessage
7573 pc <- widgetToPageContent $ do
76− addScriptRemote $ "http://f.cl.ly/items/2e3Z3r3v29263U393c3x/elm-min.js"
7774 $(whamletFile "templates/default-layout.hamlet")
7875 hamletToRepHtml $(hamletFile "templates/default-layout-wrapper.hamlet")
7976
77+instance YesodElm ElmTest where
78+ urlElmJs _ = Right $ "http://f.cl.ly/items/2e3Z3r3v29263U393c3x/elm-min.js"
79+
8080main :: IO ()
8181main = warpDebug 3000 ElmTest