elm-yesod (empty) → 0.1
raw patch · 5 files changed
+127/−0 lines, 5 filesdep +Elmdep +basedep +blaze-markupsetup-changed
Dependencies added: Elm, base, blaze-markup, shakespeare-js, text, yesod-core
Files
- LICENSE +30/−0
- Language/Elm/Yesod.hs +57/−0
- README.md +4/−0
- Setup.hs +2/−0
- elm-yesod.cabal +34/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2012, Vincent Ambo++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Vincent Ambo nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Language/Elm/Yesod.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE QuasiQuotes, TypeSynonymInstances #-}+{- | This module provides a function for compiling Elm source code into a Yesod widget.+ In order to use this with your Yesod app, you need to define a defaultLayout like+ function that embeds the elm-min.js file /in the <head> tag/.++ For example, you could modify your Yesod instance as follows:++ > instance Yesod App where+ > jsLoader _ = BottomOfHeadBlocking -- moves JS to the <head> tag+ > defaultLayout widget = do+ > pc <- widgetToPageContent $ do+ > addScriptRemote $ "http://somecdn.org/link/to/elm-min.js"+ > ...+ > ...++ A full example implementation is provided in the examples folder of the Elm github repository.+-}+module Language.Elm.Yesod (+ elmWidget+ , ElmUrl) where++import Control.Monad (liftM)+import Text.Blaze (preEscapedToMarkup)+import Text.Julius+import Yesod.Core (Route (..))+import Yesod.Handler (getUrlRenderParams, GHandler (..))+import Yesod.Widget+import Language.Elm+import Language.Elm.Quasi++import qualified Data.Text as TS+import qualified Data.Text.Lazy as TL++-- |elmWidget returns a Yesod widget from some Elm source code+-- with URL interpolation.+elmWidget :: ElmUrl (Route master) -- ^ Elm source code+ -> GHandler sub master (GWidget sub master())+elmWidget source = do+ urlF <- getUrlRenderParams+ return $ mkElmWidget source urlF+++mkElmWidget :: ElmUrl (Route master) -- ^ Elm source code+ -> RenderFn (Route master) -- ^ URL rendering function+ -> GWidget sub master ()+mkElmWidget source urlFn =+ let (html, css, js) = toParts (urlFn, source) in+ do toWidgetHead css+ toWidgetHead [julius| #{js} |]+ toWidgetBody html+++-- | Return type of template-reading functions.+type ElmUrl url = (url -> [(TS.Text, TS.Text)] -> TS.Text) -> Elm++-- | Readability synonym for render function+type RenderFn url = (url -> [(TS.Text, TS.Text)] -> TS.Text)
+ README.md view
@@ -0,0 +1,4 @@+elm-yesod+=========++elm-yesod contains the Language.Elm.Yesod module for embedding Elm code in Yesod applications.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ elm-yesod.cabal view
@@ -0,0 +1,34 @@+Name: elm-yesod+Version: 0.1+Synopsis: The Elm language Yesod compatibility module.+Description: This module provides a simple function to embed Elm code+ as a Yesod widget.++Homepage: http://elm-lang.org++License: BSD3+License-file: LICENSE++Author: Vincent Ambo+Maintainer: geva@humac.com+Copyright: Copyright: (c) 2011-2012 Vincent Ambo++Category: Web, Yesod++Build-type: Simple++Extra-source-files: README.md+Cabal-version: >=1.6++source-repository head+ type: git+ location: git://github.com/tazjin/elm-yesod.git++Library+ exposed-modules: Language.Elm.Yesod+ Build-depends: base >=4.2 && <5,+ blaze-markup == 0.5.*,+ Elm == 0.1.2.*,+ yesod-core >= 1,+ shakespeare-js,+ text