on master help sign in
Merge pull request #13 from tazjin/master
8185420Evan Czaplicki
Examples/elm-yesod/Main.hs+7−9
@@ -1,20 +1,18 @@
1{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedStrings, TypeFamilies, MultiParamTypeClasses #-}
1{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedStrings, TypeFamilies, MultiParamTypeClasses #-}
2
2
3−import Data.Text (Text)
4import Language.Elm
3import Language.Elm
5import Language.Elm.Yesod
4import Language.Elm.Yesod
6import Yesod
5import Yesod
7−import Yesod.Default.Util
8import Text.Hamlet
6import Text.Hamlet
9−import Text.Julius
10
7
11data ElmTest = ElmTest
8data ElmTest = ElmTest
12
9
13-- embedding an external elm file (note: no spaces!)
10-- embedding an external elm file (note: no spaces!)
14−mousePage = [elmFile|elm_source/mouse.elm|]
11+rootPage :: Show a => a -> a -> a -> String
15−
16rootPage mouse clock shapes = [elmFile|elm_source/index.elm|]
12rootPage mouse clock shapes = [elmFile|elm_source/index.elm|]
17
13
14+mousePage = [elmFile|elm_source/mouse.elm|]
15+
18clockPage = [elmFile|elm_source/clock.elm|]
16clockPage = [elmFile|elm_source/clock.elm|]
19
17
20-- embedding elm code inside Haskell using the QuasiQuoter:
18-- embedding elm code inside Haskell using the QuasiQuoter:
@@ -43,17 +41,17 @@ mkYesod "ElmTest" [parseRoutes|
43getMouseR :: Handler RepHtml
41getMouseR :: Handler RepHtml
44getMouseR = defaultLayout $ do
42getMouseR = defaultLayout $ do
45 setTitle "Mouse position demo"
43 setTitle "Mouse position demo"
46− generateWidget mousePage
44+ elmWidget mousePage
47
45
48getClockR :: Handler RepHtml
46getClockR :: Handler RepHtml
49getClockR = defaultLayout $ do
47getClockR = defaultLayout $ do
50 setTitle "A clock"
48 setTitle "A clock"
51− generateWidget clockPage
49+ elmWidget clockPage
52
50
53getShapesR :: Handler RepHtml
51getShapesR :: Handler RepHtml
54getShapesR = defaultLayout $ do
52getShapesR = defaultLayout $ do
55 setTitle "Simple shapes"
53 setTitle "Simple shapes"
56− generateWidget shapesPage
54+ elmWidget shapesPage
57
55
58-- URLs are rendered manually and then passed on to the function containing
56-- URLs are rendered manually and then passed on to the function containing
59-- the elm QuasiQuoter.
57-- the elm QuasiQuoter.
@@ -65,7 +63,7 @@ getRootR = do
65 clock = render ClockR
63 clock = render ClockR
66 shapes = render ShapesR
64 shapes = render ShapesR
67 setTitle "Welcome!"
65 setTitle "Welcome!"
68− generateWidget $ rootPage mouse clock shapes
66+ elmWidget $ rootPage mouse clock shapes
69
67
70
68
71-- Our Yesod instance contains the default layout, which inserts the elm-min.js
69-- Our Yesod instance contains the default layout, which inserts the elm-min.js
elm-yesod/Language/Elm/Yesod.hs+7−8
@@ -15,21 +15,20 @@
15
15
16 A full example implementation is provided in the examples folder of the Elm github repository.
16 A full example implementation is provided in the examples folder of the Elm github repository.
17-}
17-}
18−module Language.Elm.Yesod (toWidget) where
18+module Language.Elm.Yesod (elmWidget) where
19
19
20import Text.Blaze (preEscapedToMarkup)
20import Text.Blaze (preEscapedToMarkup)
21−import Text.Hamlet
22import Text.Julius
21import Text.Julius
23−import Yesod.Widget (toWidgetHead, whamlet, GWidget)
22+import Yesod.Widget (toWidgetHead, toWidgetBody, GWidget)
24import Language.Elm
23import Language.Elm
25
24
26-- |toWidget takes some Elm code in String format and produces a widget. Usage example:
25-- |toWidget takes some Elm code in String format and produces a widget. Usage example:
27--
26--
28-- > toWidget [elmFile|elm-source/somePage.elm|]
27-- > toWidget [elmFile|elm-source/somePage.elm|]
29−toWidget :: String -- ^ The Elm source code
28+elmWidget :: String -- ^ The Elm source code
30− -> GWidget sub master ()
29+ -> GWidget sub master ()
31−toWidget source =
30+elmWidget source =
32 let (html, css, js) = toParts source in
31 let (html, css, js) = toParts source in
33− do toWidgetHead [hamlet| #{css} |]
32+ do toWidgetHead css
34 toWidgetHead [julius| #{js} |]
33 toWidgetHead [julius| #{js} |]
35− [whamlet| ^{html} |]
34+ toWidgetBody html
elm/Elm.cabal+9−4
@@ -29,8 +29,9 @@ source-repository head
29 location: git://github.com/evancz/Elm.git
29 location: git://github.com/evancz/Elm.git
30
30
31Library
31Library
32− exposed-modules: Language.Elm
32+ exposed-modules: Language.Elm,
33+ Language.Elm.Quasi
33− ghc-options: -O2
34+ ghc-options: -O2 -Wall
34 Hs-Source-Dirs: src, src/Parse, src/Types
35 Hs-Source-Dirs: src, src/Parse, src/Types
35 other-modules: Ast,
36 other-modules: Ast,
36 CompileToJS,
37 CompileToJS,
@@ -60,11 +61,15 @@ Library
60 parsec >= 3.1.1,
61 parsec >= 3.1.1,
61 blaze-html == 0.5.0.*,
62 blaze-html == 0.5.0.*,
62 blaze-markup == 0.5.1.*,
63 blaze-markup == 0.5.1.*,
63− deepseq
64+ deepseq,
65+ text,
66+ attoparsec >= 0.10,
67+ template-haskell,
68+ haskell-src-meta
64
69
65Executable elm
70Executable elm
66 Main-is: Compiler.hs
71 Main-is: Compiler.hs
67− ghc-options: -O2
72+ ghc-options: -O2 -Wall
68 Hs-Source-Dirs: src, src/Parse, src/Types
73 Hs-Source-Dirs: src, src/Parse, src/Types
69 other-modules: Ast,
74 other-modules: Ast,
70 CompileToJS,
75 CompileToJS,
elm/src/Language/Elm.hs+5−1
@@ -8,13 +8,17 @@
8-}
8-}
9module Language.Elm (
9module Language.Elm (
10 toHtml,
10 toHtml,
11− toParts) where
11+ toParts,
12+ elm,
13+ elmFile) where
12
14
13import CompileToJS
15import CompileToJS
14import ExtractNoscript
16import ExtractNoscript
15import GenerateHtml
17import GenerateHtml
16import Initialize
18import Initialize
17import Text.Blaze.Html (Html)
19import Text.Blaze.Html (Html)
20+import Language.Elm.Quasi
21+
18
22
19-- |This function compiles Elm code into a full HTML page.
23-- |This function compiles Elm code into a full HTML page.
20--
24--