on master help sign in
Merge pull request #19 from tazjin/master
ab43b1dEvan Czaplicki
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
elm/Elm.cabal+2−2
@@ -1,6 +1,6 @@
1
1
2Name: Elm
2Name: Elm
3−Version: 0.1.2
3+Version: 0.1.2.1
4Synopsis: The Elm language module.
4Synopsis: The Elm language module.
5Description: Elm aims to make client-side web-development more pleasant.
5Description: Elm aims to make client-side web-development more pleasant.
6 It is a statically/strongly typed, functional reactive
6 It is a statically/strongly typed, functional reactive
@@ -31,7 +31,7 @@ source-repository head
31Library
31Library
32 exposed-modules: Language.Elm,
32 exposed-modules: Language.Elm,
33 Language.Elm.Quasi
33 Language.Elm.Quasi
34− ghc-options: -O2 -Wall
34+ ghc-options: -O2
35 Hs-Source-Dirs: src, src/Parse, src/Types
35 Hs-Source-Dirs: src, src/Parse, src/Types
36 other-modules: Ast,
36 other-modules: Ast,
37 CompileToJS,
37 CompileToJS,
elm/src/GenerateHtml.hs+7−2
@@ -1,5 +1,5 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2−module GenerateHtml (generateHtml, body, css) where
2+module GenerateHtml (generateHtml, body, css, widgetBody) where
3
3
4import Text.Blaze (preEscapedToMarkup)
4import Text.Blaze (preEscapedToMarkup)
5import Text.Blaze.Html (Html)
5import Text.Blaze.Html (Html)
@@ -51,4 +51,9 @@ body noscript = do
51 H.div ! A.id "widthChecker" ! A.style "width:100%; height:1px; position:absolute; top:-1px;" $ ""
51 H.div ! A.id "widthChecker" ! A.style "width:100%; height:1px; position:absolute; top:-1px;" $ ""
52 H.span ! A.id "content" $ ""
52 H.span ! A.id "content" $ ""
53 H.script ! A.type_ "text/javascript" $ "Dispatcher.initialize()"
53 H.script ! A.type_ "text/javascript" $ "Dispatcher.initialize()"
54− H.noscript $ preEscapedToMarkup noscript
54+ H.noscript $ preEscapedToMarkup noscript
55+
56+widgetBody noscript = do
57+ H.div ! A.id "widthChecker" ! A.style "width:100%; height:1px; position:absolute; top:-1px;" $ ""
58+ H.span ! A.id "content" $ ""
59+ H.noscript $ preEscapedToMarkup noscript
elm/src/Language/Elm.hs+1−1
@@ -71,4 +71,4 @@ toPartsHelper :: String -> (Html, Html, String)
71toPartsHelper source = (html, css, js)
71toPartsHelper source = (html, css, js)
72 where expr = initialize source
72 where expr = initialize source
73 js = compileToJS expr
73 js = compileToJS expr
74− html = body $ either id extract expr
74+ html = widgetBody $ either id extract expr