on master help sign in
Merge branch 'master' of https://github.com/evancz/Elm
commitfa502cd620f0eaba1e5c5795074091ef2d13367a authorevancz <info@elm-lang.org> dateSat 2 Jun 2012, 15:45 (14 years ago) parentb4d56e0ab43b1d
5 files changed+56−30
Examples/elm-yesod/Main.hs+19−19 README.md+27−6 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
README.md+27−6
@@ -3,8 +3,11 @@ Elm
33
44This is the Elm compiler and server, allowing you to develop Elm applications that run in any modern browser.
55
6−Installation Process
7−--------------------
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+
9+Installation for General Use
10+----------------------------
811
912Download 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:
1013
@@ -12,7 +15,7 @@ Download the [Haskell Platform](http://hackage.haskell.org/platform/). This will
1215
1316This will ensure that the elm package is available. Then install Elm with:
1417
15− cabal install elm
18+ cabal install elm-server
1619
1720Assuming everything goes correctly (potential problems are discussed later), this will build two executables on your machine:
1821
@@ -30,11 +33,29 @@ That is almost everything. Now, we will create a simple Elm project. The followi
3033 echo main = lift asText Mouse.position > main.elm
3134 elm-server
3235
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+--------------------------------------
3455
56+* Try `cabal install elm`. This will give you access to the `elm` executable (but not `elm-server`).
3557
36−Potential problems and their solutions:
37−---------------------------------------
58+These problems all appeared before Elm version 0.1.1.4:
3859
3960* 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"`
4061* 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 @@
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