packages feed

shakespeare-js 0.10.4 → 1.3.0

raw patch · 9 files changed

Files

LICENSE view
@@ -1,25 +1,20 @@-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:+Copyright (c) 2012 Michael Snoyman, http://www.yesodweb.com/ -* Redistributions of source code must retain the above copyright notice, this-  list of conditions and the following disclaimer.+Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions: -* 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.+The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software. -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.+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
− Text/Coffee.hs
@@ -1,68 +0,0 @@-{-# 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
@@ -1,82 +0,0 @@-{-# 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-    , juliusFileReload-    , jsFileReload-    ) 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--jsFileReload, juliusFileReload :: FilePath -> Q Exp-juliusFileReload = jsFileDebug-jsFileReload = jsFileDebug
shakespeare-js.cabal view
@@ -1,58 +1,31 @@ name:            shakespeare-js-version:         0.10.4-license:         BSD3+version:         1.3.0+license:         MIT 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.+maintainer:      Michael Snoyman <michael@snoyman.com>, Greg Weber <greg@gregweber.info>+synopsis:        Stick your haskell variables into javascript/coffeescript at compile time. (deprecated) 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.+    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.+    shakespeare-javascript is also known as Julius, and passes through plain javascript.     .-    Please see http://docs.yesodweb.com/book/templates for a more thorough description and examples+    There is also a shakespeare version for CoffeeScript, TypeScript, and Roy, all languages that compile down to Javascript. They all expect you to have the appropriate compiler in your path.     .-    shakespeare-js was originally called julius, and shakespeare originated from the hamlet template package.-extra-source-files:-  test/juliuses/external1.coffee-  test/juliuses/external1.julius-  test/juliuses/external2.julius-  test/ShakespeareJsTest.hs-  test.hs+    shakespeare originated from the hamlet template package.+    Please see http://www.yesodweb.com/book/shakespearean-templates for a more thorough description and examples.  category:        Web, Yesod stability:       Stable cabal-version:   >= 1.8 build-type:      Simple-homepage:        http://www.yesodweb.com/book/templates+homepage:        http://www.yesodweb.com/book/shakespearean-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: ../test.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.8     && < 0.10-                 , text             >= 0.7     && < 0.12-+                 ,   shakespeare >= 2.0  source-repository head   type:     git-  location: git://github.com/yesodweb/hamlet.git+  location: git://github.com/yesodweb/shakespeare.git
− test.hs
@@ -1,5 +0,0 @@-import Test.Hspec-import ShakespeareJsTest (specs)--main :: IO ()-main = hspecX $ descriptions [specs]
− test/ShakespeareJsTest.hs
@@ -1,140 +0,0 @@-{-# LANGUAGE QuasiQuotes #-}
-{-# LANGUAGE TemplateHaskell #-}
-module ShakespeareJsTest (specs) where
-
-import Test.HUnit hiding (Test)
-import Test.Hspec
-import Test.Hspec.HUnit ()
-
-import Prelude hiding (reverse)
-import Text.Julius
-import Data.List (intercalate)
-import qualified Data.Text.Lazy as T
-import qualified Data.List
-import qualified Data.List as L
-import Data.Text (Text, pack, unpack)
-import Data.Monoid (mappend)
-
-specs :: [Spec]
-specs = describe "shakespeare-js"
-  [ it "julius" $ do
-    let var = "var"
-    let urlp = (Home, [(pack "p", pack "q")])
-    flip jelper [julius|שלום
-#{var}
-@{Home}
-@?{urlp}
-^{jmixin}
-|] $ intercalate "\r\n"
-        [ "שלום"
-        , var
-        , "url"
-        , "url?p=q"
-        , "var x;"
-        ] ++ "\r\n"
-
-
-  , it "juliusFile" $ do
-    let var = "var"
-    let urlp = (Home, [(pack "p", pack "q")])
-    flip jelper $(juliusFile "test/juliuses/external1.julius") $ unlines
-        [ "שלום"
-        , var
-        , "url"
-        , "url?p=q"
-        , "var x;"
-        ]
-
-
-  , it "juliusFileDebug" $ do
-    let var = "var"
-    let urlp = (Home, [(pack "p", pack "q")])
-    flip jelper $(juliusFileDebug "test/juliuses/external1.julius") $ unlines
-        [ "שלום"
-        , var
-        , "url"
-        , "url?p=q"
-        , "var x;"
-        ]
-
-{- TODO
-  , it "juliusFileDebugChange" $ do
-      let var = "somevar"
-          test result = jelper result $(juliusFileDebug "test/juliuses/external2.julius")
-      writeFile "test/juliuses/external2.julius" "var #{var} = 1;"
-      test "var somevar = 1;"
-      writeFile "test/juliuses/external2.julius" "var #{var} = 2;"
-      test "var somevar = 2;"
-      writeFile "test/juliuses/external2.julius" "var #{var} = 1;"
-      -}
-
-
-  , it "julius module names" $
-    let foo = "foo"
-        double = 3.14 :: Double
-        int = -5 :: Int in
-      jelper "oof oof 3.14 -5"
-        [julius|#{Data.List.reverse foo} #{L.reverse foo} #{show double} #{show int}|]
-
-
-  , it "single dollar at and caret" $ do
-    jelper "$@^" [julius|$@^|]
-    jelper "#{@{^{" [julius|#\{@\{^\{|]
-
-
-  , it "dollar operator" $ do
-    let val = (1 :: Int, (2 :: Int, 3 :: Int))
-    jelper "2" [julius|#{ show $ fst $ snd val }|]
-    jelper "2" [julius|#{ show $ fst $ snd $ val}|]
-  ]
-
-
-
-data Url = Home | Sub SubUrl
-data SubUrl = SubUrl
-render :: Url -> [(Text, Text)] -> Text
-render Home qs = pack "url" `mappend` showParams qs
-render (Sub SubUrl) qs = pack "suburl" `mappend` showParams qs
-
-showParams :: [(Text, Text)] -> Text
-showParams [] = pack ""
-showParams z =
-    pack $ '?' : intercalate "&" (map go z)
-  where
-    go (x, y) = go' x ++ '=' : go' y
-    go' = concatMap encodeUrlChar . unpack
-
--- | Taken straight from web-encodings; reimplemented here to avoid extra
--- dependencies.
-encodeUrlChar :: Char -> String
-encodeUrlChar c
-    -- List of unreserved characters per RFC 3986
-    -- Gleaned from http://en.wikipedia.org/wiki/Percent-encoding
-    | 'A' <= c && c <= 'Z' = [c]
-    | 'a' <= c && c <= 'z' = [c]
-    | '0' <= c && c <= '9' = [c]
-encodeUrlChar c@'-' = [c]
-encodeUrlChar c@'_' = [c]
-encodeUrlChar c@'.' = [c]
-encodeUrlChar c@'~' = [c]
-encodeUrlChar ' ' = "+"
-encodeUrlChar y =
-    let (a, c) = fromEnum y `divMod` 16
-        b = a `mod` 16
-        showHex' x
-            | x < 10 = toEnum $ x + (fromEnum '0')
-            | x < 16 = toEnum $ x - 10 + (fromEnum 'A')
-            | otherwise = error $ "Invalid argument to showHex: " ++ show x
-     in ['%', showHex' b, showHex' c]
-
-
-
-
-jmixin :: JavascriptUrl u
-jmixin = [julius|var x;|]
-
-jelper :: String -> JavascriptUrl Url -> Assertion
-jelper res h = T.pack res @=? renderJavascriptUrl render h
-
-instance Show Url where
-    show _ = "FIXME remove this instance show Url"
− test/juliuses/external1.coffee
@@ -1,5 +0,0 @@-'שלום'-%{var}-'@{Home}'-'@?{urlp}'-^{cofmixin}
− test/juliuses/external1.julius
@@ -1,5 +0,0 @@-שלום-#{var}-@{Home}-@?{urlp}-^{jmixin}
− test/juliuses/external2.julius
@@ -1,1 +0,0 @@-var #{var} = 2;