on master help sign in
Merge pull request #19 from tazjin/master

* fixed script position constraints

commitab43b1d2cc2f5d11da5fe431d7cf0fc50e5372d4 authorEvan Czaplicki <info@elm-lang.org> dateSat 2 Jun 2012, 13:25 (14 years ago) parent2cfa28909ac4ef
4 files changed+29−24
Examples/elm-yesod/Main.hs+19−19 elm/Elm.cabal+2−2 elm/src/GenerateHtml.hs+7−2 elm/src/Language/Elm.hs+1−1
Examples/elm-yesod/Main.hs+19−19
@@ -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
elm/Elm.cabal+2−2
@@ -1,6 +1,6 @@
11
22Name: Elm
3−Version: 0.1.2
3+Version: 0.1.2.1
44Synopsis: The Elm language module.
55Description: Elm aims to make client-side web-development more pleasant.
66 It is a statically/strongly typed, functional reactive
@@ -31,7 +31,7 @@ source-repository head
3131Library
3232 exposed-modules: Language.Elm,
3333 Language.Elm.Quasi
34− ghc-options: -O2 -Wall
34+ ghc-options: -O2
3535 Hs-Source-Dirs: src, src/Parse, src/Types
3636 other-modules: Ast,
3737 CompileToJS,
elm/src/GenerateHtml.hs+7−2
@@ -1,5 +1,5 @@
11{-# LANGUAGE OverloadedStrings #-}
2−module GenerateHtml (generateHtml, body, css) where
2+module GenerateHtml (generateHtml, body, css, widgetBody) where
33
44import Text.Blaze (preEscapedToMarkup)
55import Text.Blaze.Html (Html)
@@ -51,4 +51,9 @@ body noscript = do
5151 H.div ! A.id "widthChecker" ! A.style "width:100%; height:1px; position:absolute; top:-1px;" $ ""
5252 H.span ! A.id "content" $ ""
5353 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)
7171toPartsHelper source = (html, css, js)
7272 where expr = initialize source
7373 js = compileToJS expr
74− html = body $ either id extract expr
74+ html = widgetBody $ either id extract expr