Skip to content

Commit

Permalink
* added the elmFile QuasiQuoter for embedding .elm files
Browse files Browse the repository at this point in the history
the elm-yesod example contains an example for how to use the elmFile QQ.

Note: No spaces before and after the filename!
  • Loading branch information
Vincent Ambo committed May 28, 2012
1 parent c6bd8bf commit bdb3a63
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
19 changes: 5 additions & 14 deletions Examples/elm-yesod/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,27 @@ import Text.Julius

data ElmTest = ElmTest

-- our Elm code
mousePage = [elm|
niceBlue = rgb 0 (1/3) (2/3)
clearGreen = rgba (1/9) (8/9) (3/9) (1/2)

scene (x,y) (w,h) =
collage w h [ filled niceBlue . rotate ((x+y)/1000) $ ngon 4 100 (200,200)
, filled clearGreen $ ngon 5 30 (x,y)
]

main = lift2 scene Mouse.position Window.dimensions
|]
-- embedding an external elm file (note: no spaces!)
mousePage = [elmFile|elm_source/mouse.elm|]

-- embedding elm code in our Haskell file
rootPage = [elm|
main = plainText "Welcome!"
|]

-- our Yesod App

mkYesod "ElmTest" [parseRoutes|
/ RootR GET
/mouse MouseR GET
|]

-- generateWidget is called with the result of an Elm QuasiQuoter (which is just a
-- string containing some Elm code, with proper newline escaping)
getMouseR :: Handler RepHtml
getMouseR = defaultLayout $ do
setTitle "Mouse position demo"
generateWidget mousePage


getRootR :: Handler RepHtml
getRootR = defaultLayout $ do
setTitle "Welcome!"
Expand Down
9 changes: 9 additions & 0 deletions Examples/elm-yesod/elm_source/mouse.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
niceBlue = rgb 0 (1/3) (2/3)
clearGreen = rgba (1/9) (8/9) (3/9) (1/2)

scene (x,y) (w,h) =
collage w h [ filled niceBlue . rotate ((x+y)/1000) $ ngon 4 100 (200,200)
, filled clearGreen $ ngon 5 30 (x,y)
]

main = lift2 scene Mouse.position Window.dimensions
6 changes: 5 additions & 1 deletion elm/src/Language/Elm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Language.Elm (
module Language.Elm.CompileToJS,
module Language.Elm.ExtractNoscript,
generateHtml,
elm) where
elm,
elmFile) where

import Language.Elm.CompileToJS
import Language.Elm.ExtractNoscript
Expand All @@ -16,3 +17,6 @@ import Language.Haskell.TH.Quote

elm :: QuasiQuoter
elm = QuasiQuoter {quoteExp = \s -> [|s|] }

elmFile :: QuasiQuoter
elmFile = quoteFile elm

0 comments on commit bdb3a63

Please sign in to comment.