shakespeare-js (empty) → 0.10.1
raw patch · 5 files changed
+229/−0 lines, 5 filesdep +HUnitdep +basedep +hspecsetup-changed
Dependencies added: HUnit, base, hspec, process, shakespeare, shakespeare-js, template-haskell, text
Files
- LICENSE +25/−0
- Setup.lhs +8/−0
- Text/Coffee.hs +68/−0
- Text/Julius.hs +76/−0
- shakespeare-js.cabal +52/−0
+ LICENSE view
@@ -0,0 +1,25 @@+The following license covers this documentation, and the source code, except+where otherwise indicated.++Copyright 2009, Michael Snoyman. 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.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "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 HOLDERS 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.
+ Setup.lhs view
@@ -0,0 +1,8 @@+#!/usr/bin/env runhaskell++> module Main where+> import Distribution.Simple+> import System.Cmd (system)++> main :: IO ()+> main = defaultMain
+ Text/Coffee.hs view
@@ -0,0 +1,68 @@+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE CPP #-}+{-# OPTIONS_GHC -fno-warn-missing-fields #-}+module Text.Coffee+ ( ToCoffee (..)+ , CoffeeUrl+ , Coffeescript+ , coffee+ , coffeeFile+ , coffeeFileDebug+ , renderCoffee+ ) where++import Language.Haskell.TH.Quote (QuasiQuoter (..))+import Language.Haskell.TH.Syntax+import Data.Text.Lazy.Builder (Builder, fromText, toLazyText, fromLazyText)+import qualified Data.Text as TS+import qualified Data.Text.Lazy as TL+import System.Process (readProcess)+import Data.Monoid+import Text.Shakespeare++renderCoffee :: (url -> [(TS.Text, TS.Text)] -> TS.Text) -> CoffeeUrl url -> IO TL.Text+renderCoffee r s = do+ out <- readProcess "coffee" ["-epb", TL.unpack $ toLazyText $ unCoffee $ s r] []+ return $ TL.pack out+ where unCoffee (Coffeescript c) = c++newtype Coffeescript = Coffeescript { unCoffeescript :: Builder }+ deriving Monoid++type CoffeeUrl url = (url -> [(TS.Text, TS.Text)] -> TS.Text) -> Coffeescript++-- the types that can be placed in a template+class ToCoffee c where+ toCoffee :: c -> Builder+instance ToCoffee [Char] where toCoffee = fromLazyText . TL.pack+instance ToCoffee TS.Text where toCoffee = fromText+instance ToCoffee TL.Text where toCoffee = fromLazyText++settings :: Q ShakespeareSettings+settings = do+ toExp <- [|toCoffee|]+ wrapExp <- [|Coffeescript|]+ unWrapExp <- [|unCoffeescript|]+ return $ defaultShakespeareSettings { varChar = '%'+ , toBuilder = toExp+ , wrap = wrapExp+ , unwrap = unWrapExp+ }++coffee :: QuasiQuoter+coffee = QuasiQuoter { quoteExp = \s -> do+ rs <- settings+ quoteExp (shakespeare rs) s+ }++coffeeFile :: FilePath -> Q Exp+coffeeFile fp = do+ rs <- settings+ shakespeareFile rs fp++coffeeFileDebug :: FilePath -> Q Exp+coffeeFileDebug fp = do+ rs <- settings+ shakespeareFileDebug rs fp
+ Text/Julius.hs view
@@ -0,0 +1,76 @@+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE CPP #-}+{-# OPTIONS_GHC -fno-warn-missing-fields #-}+-- | This module is currently in an identity crisis. Originally called Julius, now being changed to just Javascript (shakespeare-javascript)+module Text.Julius+ ( JavascriptUrl+ , Javascript (..)+ , ToJavascript (..)+ , renderJavascript+ , renderJavascriptUrl+ , js+ , julius+ , juliusFile+ , jsFile+ , juliusFileDebug+ , jsFileDebug+ ) where++import Language.Haskell.TH.Quote (QuasiQuoter (..))+import Language.Haskell.TH.Syntax+import Data.Text.Lazy.Builder (Builder, fromText, toLazyText, fromLazyText)+import Data.Monoid+import qualified Data.Text as TS+import qualified Data.Text.Lazy as TL+import Text.Shakespeare++renderJavascript :: Javascript -> TL.Text+renderJavascript (Javascript b) = toLazyText b++renderJavascriptUrl :: (url -> [(TS.Text, TS.Text)] -> TS.Text) -> JavascriptUrl url -> TL.Text+renderJavascriptUrl r s = renderJavascript $ s r++newtype Javascript = Javascript { unJavascript :: Builder }+ deriving Monoid+type JavascriptUrl url = (url -> [(TS.Text, TS.Text)] -> TS.Text) -> Javascript++class ToJavascript a where+ toJavascript :: a -> Builder+instance ToJavascript [Char] where toJavascript = fromLazyText . TL.pack+instance ToJavascript TS.Text where toJavascript = fromText+instance ToJavascript TL.Text where toJavascript = fromLazyText++settings :: Q ShakespeareSettings+settings = do+ toJExp <- [|toJavascript|]+ wrapExp <- [|Javascript|]+ unWrapExp <- [|unJavascript|]+ return $ defaultShakespeareSettings { toBuilder = toJExp+ , wrap = wrapExp+ , unwrap = unWrapExp+ }++js, julius :: QuasiQuoter+js = QuasiQuoter { quoteExp = \s -> do+ rs <- settings+ quoteExp (shakespeare rs) s+ }++julius = js++jsFile, juliusFile :: FilePath -> Q Exp+jsFile fp = do+ rs <- settings+ shakespeareFile rs fp++juliusFile = jsFile+++jsFileDebug, juliusFileDebug :: FilePath -> Q Exp+jsFileDebug fp = do+ rs <- settings+ shakespeareFileDebug rs fp++juliusFileDebug = jsFileDebug
+ shakespeare-js.cabal view
@@ -0,0 +1,52 @@+name: shakespeare-js+version: 0.10.1+license: BSD3+license-file: LICENSE+author: Michael Snoyman <michael@snoyman.com>+maintainer: Michael Snoyman <michael@snoyman.com>+synopsis: Stick your haskell variables into javascript/coffeescript at compile time.+description:+ Shakespeare is a template family for type-safe, efficient templates with simple variable interpolation . Shakespeare templates can be used inline with a quasi-quoter or in an external file. Shakespeare interpolates variables according to the type being inserted.+ In this case, the variable type needs a ToJavascript instance.+ .+ There is also shakespeare-coffeescript for coffeescript templates. Coffescript is a language that compiles down to javascript. It expects a coffeescript compiler in your path, and variable should be a ToCoffee instance.+ .+ Please see http://docs.yesodweb.com/book/templates for a more thorough description and examples+ .+ shakespeare-js was originally called julius, and shakespeare originated from the hamlet template package.++category: Web, Yesod+stability: Stable+cabal-version: >= 1.8+build-type: Simple+homepage: http://www.yesodweb.com/book/templates++library+ build-depends: base >= 4 && < 5+ , shakespeare >= 0.10 && < 0.11+ , template-haskell+ , text >= 0.7 && < 0.12+ , process >= 1.0 && < 1.2++ exposed-modules:+ Text.Julius+ Text.Coffee+ ghc-options: -Wall++test-suite test+ hs-source-dirs: test+ main-is: main.hs+ type: exitcode-stdio-1.0++ ghc-options: -Wall+ build-depends: shakespeare-js >= 0.10 && < 0.11+ , shakespeare >= 0.10 && < 0.11+ , base >= 4 && < 5+ , HUnit+ , hspec >= 0.6.1 && < 0.7+ , text >= 0.7 && < 0.12+++source-repository head+ type: git+ location: git://github.com/yesodweb/hamlet.git