shakespeare-js 1.1.4.1 → 1.3.0
raw patch · 11 files changed
Files
- Text/Coffee.hs +0/−113
- Text/Julius.hs +0/−148
- Text/Roy.hs +0/−98
- Text/TypeScript.hs +0/−116
- shakespeare-js.cabal +5/−69
- test.hs +0/−5
- test/Quoter.hs +0/−45
- test/ShakespeareJsTest.hs +0/−196
- test/juliuses/external1.coffee +0/−5
- test/juliuses/external1.julius +0/−5
- test/juliuses/external2.julius +0/−1
− Text/Coffee.hs
@@ -1,113 +0,0 @@-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE CPP #-}-{-# OPTIONS_GHC -fno-warn-missing-fields #-}--- | A Shakespearean module for CoffeeScript, introducing type-safe,--- compile-time variable and url interpolation. It is exactly the same as--- "Text.Julius", except that the template is first compiled to Javascript with--- the system tool @coffee@.------ To use this module, @coffee@ must be installed on your system.------ @#{...}@ is the Shakespearean standard for variable interpolation, but--- CoffeeScript already uses that sequence for string interpolation. Therefore,--- Shakespearean interpolation is introduced with @%{...}@.------ If you interpolate variables,--- the template is first wrapped with a function containing javascript variables representing shakespeare variables,--- then compiled with @coffee@,--- and then the value of the variables are applied to the function.--- This means that in production the template can be compiled--- once at compile time and there will be no dependency in your production--- system on @coffee@. ------ Your code:------ > b = 1--- > console.log(#{a} + b)------ Function wrapper added to your coffeescript code:------ > ((shakespeare_var_a) =>--- > b = 1--- > console.log(shakespeare_var_a + b)--- > )------ This is then compiled down to javascript, and the variables are applied:------ > ;(function(shakespeare_var_a){--- > var b = 1;--- > console.log(shakespeare_var_a + b);--- > })(#{a});--------- Further reading:------ 1. Shakespearean templates: <http://www.yesodweb.com/book/templates>------ 2. CoffeeScript: <http://coffeescript.org/>-module Text.Coffee- ( -- * Functions- -- ** Template-Reading Functions- -- | These QuasiQuoter and Template Haskell methods return values of- -- type @'JavascriptUrl' url@. See the Yesod book for details.- coffee- , coffeeFile- , coffeeFileReload- , coffeeFileDebug--#ifdef TEST_EXPORT- , coffeeSettings-#endif- ) where--import Language.Haskell.TH.Quote (QuasiQuoter (..))-import Language.Haskell.TH.Syntax-import Text.Shakespeare-import Text.Julius--coffeeSettings :: Q ShakespeareSettings-coffeeSettings = do- jsettings <- javascriptSettings- return $ jsettings { varChar = '%'- , preConversion = Just PreConvert {- preConvert = ReadProcess "coffee" ["-spb"]- , preEscapeIgnoreBalanced = "'\"`" -- don't insert backtacks for variable already inside strings or backticks.- , preEscapeIgnoreLine = "#" -- ignore commented lines- , wrapInsertion = Just WrapInsertion { - wrapInsertionIndent = Just " "- , wrapInsertionStartBegin = "("- , wrapInsertionSeparator = ", "- , wrapInsertionStartClose = ") =>"- , wrapInsertionEnd = ""- , wrapInsertionAddParens = False- }- }- }---- | Read inline, quasiquoted CoffeeScript.-coffee :: QuasiQuoter-coffee = QuasiQuoter { quoteExp = \s -> do- rs <- coffeeSettings- quoteExp (shakespeare rs) s- }---- | Read in a CoffeeScript template file. This function reads the file once, at--- compile time.-coffeeFile :: FilePath -> Q Exp-coffeeFile fp = do- rs <- coffeeSettings- shakespeareFile rs fp---- | Read in a CoffeeScript template file. This impure function uses--- unsafePerformIO to re-read the file on every call, allowing for rapid--- iteration.-coffeeFileReload :: FilePath -> Q Exp-coffeeFileReload fp = do- rs <- coffeeSettings- shakespeareFileReload rs fp---- | Deprecated synonym for 'coffeeFileReload'-coffeeFileDebug :: FilePath -> Q Exp-coffeeFileDebug = coffeeFileReload-{-# DEPRECATED coffeeFileDebug "Please use coffeeFileReload instead." #-}
− Text/Julius.hs
@@ -1,148 +0,0 @@-{-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE CPP #-}-{-# OPTIONS_GHC -fno-warn-missing-fields #-}--- | A Shakespearean module for Javascript templates, introducing type-safe,--- compile-time variable and url interpolation.-------- You might consider trying 'Text.Typescript' or 'Text.Coffee' which compile down to Javascript.------ Further reading: <http://www.yesodweb.com/book/templates>-module Text.Julius- ( -- * Functions- -- ** Template-Reading Functions- -- | These QuasiQuoter and Template Haskell methods return values of- -- type @'JavascriptUrl' url@. See the Yesod book for details.- js- , julius- , juliusFile- , jsFile- , juliusFileDebug- , jsFileDebug- , juliusFileReload- , jsFileReload-- -- * Datatypes- , JavascriptUrl- , Javascript (..)- , RawJavascript (..)-- -- * Typeclass for interpolated variables- , ToJavascript (..)- , RawJS (..)-- -- ** Rendering Functions- , renderJavascript- , renderJavascriptUrl-- -- ** internal, used by 'Text.Coffee'- , javascriptSettings- -- ** internal- , juliusUsedIdentifiers- ) 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-import Data.Aeson (Value)-import Data.Aeson.Encode (fromValue)--renderJavascript :: Javascript -> TL.Text-renderJavascript (Javascript b) = toLazyText b---- | render with route interpolation. If using this module standalone, apart--- from type-safe routes, a dummy renderer can be used:--- --- > renderJavascriptUrl (\_ _ -> undefined) javascriptUrl------ When using Yesod, a renderer is generated for you, which can be accessed--- within the GHandler monad: 'Yesod.Handler.getUrlRenderParams'.-renderJavascriptUrl :: (url -> [(TS.Text, TS.Text)] -> TS.Text) -> JavascriptUrl url -> TL.Text-renderJavascriptUrl r s = renderJavascript $ s r---- | Newtype wrapper of 'Builder'.-newtype Javascript = Javascript { unJavascript :: Builder }- deriving Monoid---- | Return type of template-reading functions.-type JavascriptUrl url = (url -> [(TS.Text, TS.Text)] -> TS.Text) -> Javascript--asJavascriptUrl :: JavascriptUrl url -> JavascriptUrl url-asJavascriptUrl = id---- | A typeclass for types that can be interpolated in CoffeeScript templates.-class ToJavascript a where- toJavascript :: a -> Builder-#if 0-instance ToJavascript [Char] where toJavascript = fromLazyText . TL.pack-instance ToJavascript TS.Text where toJavascript = fromText-instance ToJavascript TL.Text where toJavascript = fromLazyText-instance ToJavascript Javascript where toJavascript = unJavascript-instance ToJavascript Builder where toJavascript = id-#endif-instance ToJavascript Bool where toJavascript = fromText . TS.toLower . TS.pack . show-instance ToJavascript Value where toJavascript = fromValue--newtype RawJavascript = RawJavascript Builder-instance ToJavascript RawJavascript where- toJavascript (RawJavascript a) = a--class RawJS a where- rawJS :: a -> RawJavascript--instance RawJS [Char] where rawJS = RawJavascript . fromLazyText . TL.pack-instance RawJS TS.Text where rawJS = RawJavascript . fromText-instance RawJS TL.Text where rawJS = RawJavascript . fromLazyText-instance RawJS Builder where rawJS = RawJavascript-instance RawJS Bool where rawJS = RawJavascript . toJavascript--javascriptSettings :: Q ShakespeareSettings-javascriptSettings = do- toJExp <- [|toJavascript|]- wrapExp <- [|Javascript|]- unWrapExp <- [|unJavascript|]- asJavascriptUrl' <- [|asJavascriptUrl|]- return $ defaultShakespeareSettings { toBuilder = toJExp- , wrap = wrapExp- , unwrap = unWrapExp- , modifyFinalValue = Just asJavascriptUrl'- }--js, julius :: QuasiQuoter-js = QuasiQuoter { quoteExp = \s -> do- rs <- javascriptSettings- quoteExp (shakespeare rs) s- }--julius = js--jsFile, juliusFile :: FilePath -> Q Exp-jsFile fp = do- rs <- javascriptSettings- shakespeareFile rs fp--juliusFile = jsFile---jsFileReload, juliusFileReload :: FilePath -> Q Exp-jsFileReload fp = do- rs <- javascriptSettings- shakespeareFileReload rs fp--juliusFileReload = jsFileReload--jsFileDebug, juliusFileDebug :: FilePath -> Q Exp-juliusFileDebug = jsFileReload-{-# DEPRECATED juliusFileDebug "Please use juliusFileReload instead." #-}-jsFileDebug = jsFileReload-{-# DEPRECATED jsFileDebug "Please use jsFileReload instead." #-}---- | Determine which identifiers are used by the given template, useful for--- creating systems like yesod devel.-juliusUsedIdentifiers :: String -> [(Deref, VarType)]-juliusUsedIdentifiers = shakespeareUsedIdentifiers defaultShakespeareSettings
− Text/Roy.hs
@@ -1,98 +0,0 @@-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE CPP #-}-{-# OPTIONS_GHC -fno-warn-missing-fields #-}--- | A Shakespearean module for Roy, introducing type-safe,--- compile-time variable and url interpolation. It is exactly the same as--- "Text.Julius", except that the template is first compiled to Javascript with--- the system tool @roy@.------ To use this module, @roy@ must be installed on your system.------ If you interpolate variables,--- the template is first wrapped with a function containing javascript variables representing shakespeare variables,--- then compiled with @roy@,--- and then the value of the variables are applied to the function.--- This means that in production the template can be compiled--- once at compile time and there will be no dependency in your production--- system on @roy@. ------ Your code:------ > let b = 1--- > console.log(#{a} + b)------ Final Result:------ > ;(function(shakespeare_var_a){--- > var b = 1;--- > console.log(shakespeare_var_a + b);--- > })(#{a});------ Further reading:------ 1. Shakespearean templates: <http://www.yesodweb.com/book/templates>------ 2. Roy: <http://http://roy.brianmckenna.org/>-module Text.Roy- ( -- * Functions- -- ** Template-Reading Functions- -- | These QuasiQuoter and Template Haskell methods return values of- -- type @'JavascriptUrl' url@. See the Yesod book for details.- roy- , royFile- , royFileReload--#ifdef TEST_EXPORT- , roySettings-#endif- ) where--import Language.Haskell.TH.Quote (QuasiQuoter (..))-import Language.Haskell.TH.Syntax-import Text.Shakespeare-import Text.Julius---- | The Roy language compiles down to Javascript.--- We do this compilation once at compile time to avoid needing to do it during the request.--- We call this a preConversion because other shakespeare modules like Lucius use Haskell to compile during the request instead rather than a system call.-roySettings :: Q ShakespeareSettings-roySettings = do- jsettings <- javascriptSettings- return $ jsettings { varChar = '#'- , preConversion = Just PreConvert {- preConvert = ReadProcess "roy" ["--stdio", "--browser"]- , preEscapeIgnoreBalanced = "'\""- , preEscapeIgnoreLine = "//"- , wrapInsertion = Just WrapInsertion {- wrapInsertionIndent = Just " "- , wrapInsertionStartBegin = "(\\"- , wrapInsertionSeparator = " "- , wrapInsertionStartClose = " ->\n"- , wrapInsertionEnd = ")"- , wrapInsertionAddParens = True- }- }- }---- | Read inline, quasiquoted Roy.-roy :: QuasiQuoter-roy = QuasiQuoter { quoteExp = \s -> do- rs <- roySettings- quoteExp (shakespeare rs) s- }---- | Read in a Roy template file. This function reads the file once, at--- compile time.-royFile :: FilePath -> Q Exp-royFile fp = do- rs <- roySettings- shakespeareFile rs fp---- | Read in a Roy template file. This impure function uses--- unsafePerformIO to re-read the file on every call, allowing for rapid--- iteration.-royFileReload :: FilePath -> Q Exp-royFileReload fp = do- rs <- roySettings- shakespeareFileReload rs fp
− Text/TypeScript.hs
@@ -1,116 +0,0 @@-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE CPP #-}-{-# OPTIONS_GHC -fno-warn-missing-fields #-}--- | A Shakespearean module for TypeScript, introducing type-safe,--- compile-time variable and url interpolation. It is exactly the same as--- "Text.Julius", except that the template is first compiled to Javascript with--- the system tool @tsc@.------ To use this module, @tsc@ must be installed on your system.------ If you interpolate variables,--- the template is first wrapped with a function containing javascript variables representing shakespeare variables,--- then compiled with @tsc@,--- and then the value of the variables are applied to the function.--- This means that in production the template can be compiled--- once at compile time and there will be no dependency in your production--- system on @tsc@. ------ Your code:------ > var b = 1--- > console.log(#{a} + b)------ Final Result:------ > ;(function(shakespeare_var_a){--- > var b = 1;--- > console.log(shakespeare_var_a + b);--- > })(#{a});--------- Important Warnings! This integration is not ideal.------ Due to the function wrapper, all type declarations must be in separate .d.ts files.--- However, if you don't interpolate variables, no function wrapper will be--- created, and you can make type declarations in the same file.------ This does not work cross-platform!------ Unfortunately tsc does not support stdin and stdout.--- So a hack of writing to temporary files using the mktemp--- command is used. This works on my version of Linux, but not for windows--- unless perhaps you install a mktemp utility, which I have not tested.--- Please vote up this bug: <http://typescript.codeplex.com/workitem/600>------ Making this work on Windows would not be very difficult, it will just require a new--- package with a dependency on a package like temporary.------ Further reading:------ 1. Shakespearean templates: <http://www.yesodweb.com/book/templates>------ 2. TypeScript: <http://typescript.codeplex.com/>-module Text.TypeScript- ( -- * Functions- -- ** Template-Reading Functions- -- | These QuasiQuoter and Template Haskell methods return values of- -- type @'JavascriptUrl' url@. See the Yesod book for details.- tsc- , typeScriptFile- , typeScriptFileReload--#ifdef TEST_EXPORT- , typeScriptSettings-#endif- ) where--import Language.Haskell.TH.Quote (QuasiQuoter (..))-import Language.Haskell.TH.Syntax-import Text.Shakespeare-import Text.Julius---- | The TypeScript language compiles down to Javascript.--- We do this compilation once at compile time to avoid needing to do it during the request.--- We call this a preConversion because other shakespeare modules like Lucius use Haskell to compile during the request instead rather than a system call.-typeScriptSettings :: Q ShakespeareSettings-typeScriptSettings = do- jsettings <- javascriptSettings- return $ jsettings { varChar = '#'- , preConversion = Just PreConvert {- preConvert = ReadProcess "sh" ["-c", "TMP_IN=$(mktemp XXXXXXXXXX.ts); TMP_OUT=$(mktemp XXXXXXXXXX.js); cat /dev/stdin > ${TMP_IN} && tsc --out ${TMP_OUT} ${TMP_IN} && cat ${TMP_OUT}; rm ${TMP_IN} && rm ${TMP_OUT}"]- , preEscapeIgnoreBalanced = "'\""- , preEscapeIgnoreLine = "//"- , wrapInsertion = Just WrapInsertion { - wrapInsertionIndent = Nothing- , wrapInsertionStartBegin = ";(function("- , wrapInsertionSeparator = ", "- , wrapInsertionStartClose = "){"- , wrapInsertionEnd = "})"- , wrapInsertionAddParens = False- }- }- }---- | Read inline, quasiquoted TypeScript-tsc :: QuasiQuoter-tsc = QuasiQuoter { quoteExp = \s -> do- rs <- typeScriptSettings- quoteExp (shakespeare rs) s- }---- | Read in a TypeScript template file. This function reads the file once, at--- compile time.-typeScriptFile :: FilePath -> Q Exp-typeScriptFile fp = do- rs <- typeScriptSettings- shakespeareFile rs fp---- | Read in a Roy template file. This impure function uses--- unsafePerformIO to re-read the file on every call, allowing for rapid--- iteration.-typeScriptFileReload :: FilePath -> Q Exp-typeScriptFileReload fp = do- rs <- typeScriptSettings- shakespeareFileReload rs fp
shakespeare-js.cabal view
@@ -1,27 +1,20 @@ name: shakespeare-js-version: 1.1.4.1+version: 1.3.0 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com> maintainer: Michael Snoyman <michael@snoyman.com>, Greg Weber <greg@gregweber.info>-synopsis: Stick your haskell variables into javascript/coffeescript at compile time.+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. In this case, the variable type needs a ToJavascript instance. .- shakespeare-javascript is alson known as Julius, and passes through plain javascript+ shakespeare-javascript is also known as Julius, and passes through plain javascript. . 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 originated from the hamlet template package.- Please see http://www.yesodweb.com/book/shakespearean-templates for a more thorough description and examples- .-extra-source-files:- test/juliuses/external1.coffee- test/juliuses/external1.julius- test/juliuses/external2.julius- test/ShakespeareJsTest.hs- test.hs+ Please see http://www.yesodweb.com/book/shakespearean-templates for a more thorough description and examples. category: Web, Yesod stability: Stable@@ -31,64 +24,7 @@ library build-depends: base >= 4 && < 5- , shakespeare >= 1.0.5 && < 1.1- , template-haskell- , text >= 0.7- , aeson >= 0.5-- exposed-modules:- Text.Julius- Text.Coffee- Text.Roy- Text.TypeScript- ghc-options: -Wall- if impl(ghc >= 7.4)- cpp-options: -DGHC_7_4-- if flag(test_coffee)- cpp-options: -DTEST_COFFEE-- if flag(test_roy)- cpp-options: -DTEST_ROY-- if flag(test_export)- cpp-options: -DTEST_EXPORT--flag test_export- default: False--flag test_coffee- description: render tests through coffeescript render function- -- cabal configure --enable-tests -ftest_coffee && cabal build && dist/build/test/test- default: False--flag test_roy- description: render tests through coffeescript render function- -- cabal configure --enable-tests -ftest_coffee && cabal build && dist/build/test/test- default: False--test-suite test- hs-source-dirs: test ./- main-is: ../test.hs- other-modules: Quoter- type: exitcode-stdio-1.0-- ghc-options: -Wall- build-depends:- shakespeare- , base- , HUnit- , hspec >= 1.3- , text- , template-haskell- , aeson-- cpp-options: -DTEST_EXPORT- if flag(test_coffee)- cpp-options: -DTEST_COFFEE- if flag(test_roy)- cpp-options: -DTEST_ROY-+ , shakespeare >= 2.0 source-repository head type: git
− test.hs
@@ -1,5 +0,0 @@-import Test.Hspec-import ShakespeareJsTest (specs)--main :: IO ()-main = hspec specs
− test/Quoter.hs
@@ -1,45 +0,0 @@-{-# LANGUAGE CPP #-}-{-# OPTIONS_GHC -fno-warn-missing-fields #-}-module Quoter (quote, quoteFile, quoteFileReload) where--import Language.Haskell.TH.Syntax-import Language.Haskell.TH.Quote (QuasiQuoter (..))--#ifdef TEST_COFFEE-import Text.Coffee-import Text.Coffee (coffeeSettings)-import Text.Shakespeare (shakespeare)-#else-# ifdef TEST_ROY-import Text.Roy-# else-import Text.Julius-# endif-#endif--quote :: QuasiQuoter-quoteFile :: FilePath -> Q Exp-quoteFileReload :: FilePath -> Q Exp-#ifdef TEST_COFFEE-translate ('#':'{':rest) = translate $ '%':'{':translate rest-translate (c:other) = c:translate other-translate [] = []--quote = QuasiQuoter { quoteExp = \s -> do- rs <- coffeeSettings- quoteExp (shakespeare rs) (translate s)- }--quoteFile = coffeeFile-quoteFileReload = coffeeFileReload-#else-# ifdef TEST_ROY-quote = roy-quoteFile = royFile-quoteFileReload = royFileReload-# else-quote = julius-quoteFile = juliusFile-quoteFileReload = juliusFileReload-# endif-#endif
− test/ShakespeareJsTest.hs
@@ -1,196 +0,0 @@-{-# LANGUAGE QuasiQuotes #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE CPP #-} -module ShakespeareJsTest (specs) where - -import Test.HUnit hiding (Test) -import Test.Hspec - -import Prelude hiding (reverse) -#ifdef TEST_COFFEE -import Text.Coffee -#endif -import Text.Julius -import Quoter (quote, quoteFile, quoteFileReload) -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) -import Data.Aeson (toJSON) - -join :: [String] -> String -#ifdef TEST_COFFEE -join l = (intercalate ";\n" l) -#else -join = intercalate "\n" -#endif - -specs :: Spec -specs = describe "shakespeare-js" $ do -#if !(defined TEST_COFFEE || defined TEST_ROY) - it "julius" $ do - let var = "x=2" - let urlp = (Home, [(pack "p", pack "q")]) - flip jelper [quote|['שלום', @{Home}, #{rawJS var}, '@?{urlp}', ^{jmixin} ]|] - $ intercalate " " - [ "['שלום'," - , "url, " ++ var ++ "," - , "'url?p=q'," - , "f(2) ]" - ] - - - it "juliusFile" $ do - let var = "x=2" - let urlp = (Home, [(pack "p", pack "q")]) - flip jelper $(quoteFile "test/juliuses/external1.julius") $ join - [ "שלום" - , var - , "url" - , "url?p=q" - , "f(2)" - ] ++ "\n" - - - it "juliusFileReload" $ do - let var = "x=2" - let urlp = (Home, [(pack "p", pack "q")]) - flip jelper $(quoteFileReload "test/juliuses/external1.julius") $ join - [ "שלום" - , var - , "url" - , "url?p=q" - , "f(2)" - ] ++ "\n" -#endif - -{- 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 -#ifdef TEST_COFFEE - in jelper "var _this = this;\n\n(function(shakespeare_var_rawJSDataListreversefoo, shakespeare_var_rawJSLreversefoo, shakespeare_var_rawJSshowdouble, shakespeare_var_rawJSshowint) {\n return [shakespeare_var_rawJSDataListreversefoo, shakespeare_var_rawJSLreversefoo, shakespeare_var_rawJSshowdouble, shakespeare_var_rawJSshowint];\n})(oof, oof, 3.14, -5);\n" -#else -# ifdef TEST_ROY - in jelper "(function(shakespeare_var_rawJSDataListreversefoo, shakespeare_var_rawJSLreversefoo, shakespeare_var_rawJSshowdouble, shakespeare_var_rawJSshowint) {\n return [shakespeare_var_rawJSDataListreversefoo, shakespeare_var_rawJSLreversefoo, shakespeare_var_rawJSshowdouble, shakespeare_var_rawJSshowint];\n})(oof, oof, 3.14, -5);\n" -# else - in jelper "[oof, oof, 3.14, -5]" -# endif -#endif - [quote|[#{rawJS $ Data.List.reverse foo}, #{rawJS $ L.reverse foo}, #{rawJS $ show double}, #{rawJS $ show int}]|] - - --- not valid coffeescript -#if !(defined TEST_COFFEE || defined TEST_ROY) - it "single dollar at and caret" $ do - jelper "$@^" [quote|$@^|] - jelper "#{@{^{" [quote|#\{@\{^\{|] -#endif - - it "dollar operator" $ do - let val = (1 :: Int, (2 :: Int, 3 :: Int)) -#if (defined TEST_COFFEE) - jelper "var _this = this;\n\n(function(shakespeare_var_rawJSshowfstsndval) {\n return shakespeare_var_rawJSshowfstsndval;\n})(2);\n" [quote|#{ rawJS $ show $ fst $ snd val }|] - jelper "var _this = this;\n\n(function(shakespeare_var_rawJSshowfstsndval) {\n return shakespeare_var_rawJSshowfstsndval;\n})(2);\n" [quote|#{ rawJS $ show $ fst $ snd val }|] -#else - -# if (defined TEST_ROY) - jelper "(function(shakespeare_var_rawJSshowfstsndval) {\n return shakespeare_var_rawJSshowfstsndval;\n})(2);\n" [quote|#{ rawJS $ show $ fst $ snd val }|] - jelper "(function(shakespeare_var_rawJSshowfstsndval) {\n return shakespeare_var_rawJSshowfstsndval;\n})(2);\n" [quote|#{ rawJS $ show $ fst $ snd val }|] - -# else - jelper "2" [quote|#{ rawJS $ show $ fst $ snd val }|] - jelper "2" [quote|#{ rawJS $ show $ fst $ snd $ val}|] -# endif -#endif - -#if (defined TEST_ROY) - it "roy function wrapper" $ do - let royInsert = rawJS "\"royInsert\"" - jelper "(function(shakespeare_var_royInsert) {\n var roy = {\n \"royInsert\": shakespeare_var_royInsert\n };\n return console.log(roy);\n})(\"royInsert\");\n" [quote| -let roy = { royInsert: #{royInsert} } -console.log roy -|] -#endif - it "empty file" $ jelper "" [quote||] - - it "JSON data" $ jelper "\"Hello \\\"World!\\\"\"" [julius|#{toJSON "Hello \"World!\""}|] - - it "boolean interpolation" $ jelper - "true false true false true false" - [julius|#{True} #{False} #{toJSON True} #{toJSON False} #{rawJS True} #{rawJS False}|] - - it "^\\ should not be escaped" $ jelper - "var re = /[^\\r]/;" - [julius|var re = /[^\r]/;|] - - it "^\\{ should be escaped" $ jelper - "var re = /[^{]/;" - [julius|var re = /[^\{]/;|] - - -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] - - - - -#ifndef TEST_ROY -jmixin :: JavascriptUrl u -jmixin = [quote|f(2)|] -#endif - -jelper :: String -> JavascriptUrl Url -> Assertion -jelper res h = do - 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 @@-שלום-#{rawJS var}-@{Home}-@?{urlp}-^{jmixin}
− test/juliuses/external2.julius
@@ -1,1 +0,0 @@-var #{var} = 2;