on master help sign in
Merge branch 'master' of https://github.com/evancz/Elm
fa502cdevancz
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
README.md+27−6
@@ -3,8 +3,11 @@ Elm
3
3
4This is the Elm compiler and server, allowing you to develop Elm applications that run in any modern browser.
4This is the Elm compiler and server, allowing you to develop Elm applications that run in any modern browser.
5
5
6+If you intend to serve Elm code with a Haskell backend, be sure to read all the way to the "Installation for Haskell-Users" section.
7+
8+
6−Installation Process
9+Installation for General Use
7−--------------------
10+----------------------------
8
11
9Download the [Haskell Platform](http://hackage.haskell.org/platform/). This will give you access to the Haskell compiler (needed to build Elm) and Haskell's package distribution system (to make installation of Elm easier). Once installed (even if it already was), you must update your listing of Haskell packages with:
12Download the [Haskell Platform](http://hackage.haskell.org/platform/). This will give you access to the Haskell compiler (needed to build Elm) and Haskell's package distribution system (to make installation of Elm easier). Once installed (even if it already was), you must update your listing of Haskell packages with:
10
13
@@ -12,7 +15,7 @@ Download the [Haskell Platform](http://hackage.haskell.org/platform/). This will
12
15
13This will ensure that the elm package is available. Then install Elm with:
16This will ensure that the elm package is available. Then install Elm with:
14
17
15− cabal install elm
18+ cabal install elm-server
16
19
17Assuming everything goes correctly (potential problems are discussed later), this will build two executables on your machine:
20Assuming everything goes correctly (potential problems are discussed later), this will build two executables on your machine:
18
21
@@ -30,11 +33,29 @@ That is almost everything. Now, we will create a simple Elm project. The followi
30 echo main = lift asText Mouse.position > main.elm
33 echo main = lift asText Mouse.position > main.elm
31 elm-server
34 elm-server
32
35
33−The first two commands create a new directory and navigate into it. Then next command (`wget`) downloads the [elm-mini.js](https://raw.github.com/evancz/Elm/master/elm-mini.js) file which is the Elm runtime system and must be in the root directory of your Elm project. If you do not have wget, just follow [this link](https://raw.github.com/evancz/Elm/master/elm-mini.js) and download it directly. The `echo` command places a simple program into `main.elm`. The final command starts the Elm server at [localhost](http://localhost:8000/), allowing you to navigate to `main.elm` and see your first program in action.
36+The first two commands create a new directory and navigate into it. Then next command (`wget`) downloads the [elm-mini.js](https://raw.github.com/evancz/Elm/master/elm-mini.js) file which is the Elm runtime system and must be in the root directory of your Elm project. If you do not have wget, just follow [this link](https://raw.github.com/evancz/Elm/master/elm-mini.js) and download it directly. The `echo` command places a simple program into `main.elm` (do this manually if you do not have `echo`). The final command starts the Elm server at [localhost](http://localhost:8000/), allowing you to navigate to `main.elm` and see your first program in action.
37+
38+
39+Installation for Haskell-users
40+------------------------------
41+
42+Elm as described in the previous section is actually split into two packages: `elm` which contains the guts of the compiler and `elm-server` which provides a simple HAppStack-based server to simplify development. Those of you planning to write your own server in Haskell only need the `elm` package:
43+
44+ cabal install elm
45+
46+The `elm` package provides support for [compilation of Elm code directly in Haskell](http://hackage.haskell.org/packages/archive/Elm/0.1.2/doc/html/Language-Elm.html) and [QuasiQuoting](http://hackage.haskell.org/packages/archive/Elm/0.1.2/doc/html/Language-Elm-Quasi.html). See the [Examples/](https://github.com/evancz/Elm/tree/master/Examples) directory for information and examples on how to get started with Elm+Haskell.
47+
48+Yesod users should also install the `elm-yesod` package which provides functions for idiomatically embedding Elm in Yesod:
49+
50+ cabal install elm-yesod
51+
52+
53+Potential problems and their solutions
54+--------------------------------------
34
55
56+* Try `cabal install elm`. This will give you access to the `elm` executable (but not `elm-server`).
35
57
36−Potential problems and their solutions:
58+These problems all appeared before Elm version 0.1.1.4:
37−---------------------------------------
38
59
39* Install errors having to do with `happstack-server-7.0.2`. This version of `happstack-server` has stricter dependency restrictions that conflict with other libraries required by Elm. Try installing with an earlier version of `happstack-server` with the following command: `cabal install elm --constrain="happstack-server<7.0.2"`
60* Install errors having to do with `happstack-server-7.0.2`. This version of `happstack-server` has stricter dependency restrictions that conflict with other libraries required by Elm. Try installing with an earlier version of `happstack-server` with the following command: `cabal install elm --constrain="happstack-server<7.0.2"`
40* When installing on Debian, `blaze-html-0.4.3.2` fails to compile. You must install `blaze-html-0.4.3.1` instead.
61* When installing on Debian, `blaze-html-0.4.3.2` fails to compile. You must install `blaze-html-0.4.3.1` instead.
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