Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

don't create a function wrapper when there are no vars

This allows type declarations with TypeScript
  • Loading branch information...
commit 58360e79651fbd9d63b58ccd57fe76dccb0cfef0 1 parent 983d3a4
@gregwebs gregwebs authored
View
10 shakespeare-js/Text/Coffee.hs
@@ -13,12 +13,20 @@
-- 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)
--
--- Changes to your coffeescript code:
+-- Function wrapper added to your coffeescript code:
--
-- > ((yesod_var_a) =>
-- > b = 1
View
16 shakespeare-js/Text/TypeScript.hs
@@ -9,9 +9,10 @@
--
-- To use this module, @tsc@ must be installed on your system.
--
--- The template is first wrapped with javascript variable representing Yesod
--- variables, then compiled with tsc, and then the value of the variables
--- are applied.
+-- 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@.
@@ -29,10 +30,13 @@
-- > })(#{a});
--
--
--- Important Warnings!
+-- Important Warnings! This integration is not ideal.
--
--- * All type declarations must be in separate .d.ts files
--- * This does not work cross-platform!
+-- 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.
+--
+-- 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
View
2  shakespeare/Text/Shakespeare.hs
@@ -239,6 +239,7 @@ preFilter ShakespeareSettings {..} template =
shakespeare_var_conversion err = error $ "did not expect: " <> err
applyVars Nothing _ str = str
+ applyVars _ [] str = str
applyVars (Just WrapInsertion {..}) vars str =
reverse (dropWhile (\c -> c == ';' || isSpace c) (reverse str))
<> wrapInsertionApplyBegin
@@ -246,6 +247,7 @@ preFilter ShakespeareSettings {..} template =
<> wrapInsertionApplyClose
addVars Nothing _ str = str
+ addVars _ [] str = str
addVars (Just WrapInsertion {..}) vars str =
wrapInsertionStartBegin
<> (mconcat $ intersperse wrapInsertionSeparator $ map shakespeare_var_conversion vars)
View
2  shakespeare/test/ShakespeareBaseTest.hs
@@ -34,7 +34,7 @@ specs = describe "shakespeare-js" $ do
it "preFilter ignore comments" $ do
preFilter preConversionSettings templateCommented
- `shouldReturn` "(function(){unchanged & '#{var}' @{url} '^{int}'})()"
+ `shouldReturn` "unchanged & '#{var}' @{url} '^{int}'"
where
varString = parseVarString '%'

0 comments on commit 58360e7

Please sign in to comment.
Something went wrong with that request. Please try again.