shakespeare 2.0.22 → 2.0.23
raw patch · 5 files changed
+36/−2 lines, 5 files
Files
- ChangeLog.md +4/−0
- Text/Shakespeare.hs +4/−1
- shakespeare.cabal +2/−1
- test/Text/Shakespeare/BuilderQQ.hs +18/−0
- test/Text/Shakespeare/TextSpec.hs +8/−0
ChangeLog.md view
@@ -1,5 +1,9 @@ # ChangeLog for shakespeare +### 2.0.23++* Add support to use caret interpolation in only var shakespeares [#242](https://github.com/yesodweb/shakespeare/issues/242)+ ### 2.0.22 * Add `stextFile` to `Text.Shakespeare.Text`, which can be used to produce `Text` directly in the same way `shamletFile` can be used to produce `Html` directly. [#240](https://github.com/yesodweb/shakespeare/pull/240)
Text/Shakespeare.hs view
@@ -360,7 +360,10 @@ up <- [|\r' (u, p) -> r' u p|] return $ wrap rs `AppE` (ts `AppE` (up `AppE` VarE r `AppE` derefToExp [] d)) contentToBuilder r (ContentMix d) =- return $ derefToExp [] d `AppE` VarE r+ return $+ if justVarInterpolation rs+ then derefToExp [] d+ else derefToExp [] d `AppE` VarE r shakespeare :: ShakespeareSettings -> QuasiQuoter shakespeare r = QuasiQuoter { quoteExp = shakespeareFromString r }
shakespeare.cabal view
@@ -1,5 +1,5 @@ name: shakespeare-version: 2.0.22+version: 2.0.23 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -108,6 +108,7 @@ other-modules: Text.Shakespeare.BaseSpec Text.Shakespeare.I18NSpec Text.Shakespeare.TextSpec+ Text.Shakespeare.BuilderQQ Text.CssSpec Text.HamletSpec Text.JuliusSpec
+ test/Text/Shakespeare/BuilderQQ.hs view
@@ -0,0 +1,18 @@+{-# LANGUAGE TemplateHaskellQuotes #-}+module Text.Shakespeare.BuilderQQ (builderQQ) where++import Prelude+import Language.Haskell.TH.Quote (QuasiQuoter(..))+import Language.Haskell.TH.Syntax (Exp(..))+import Text.Shakespeare+import Text.Shakespeare.Text (ToText(..))++builderQQ :: QuasiQuoter+builderQQ =+ shakespeare $+ defaultShakespeareSettings+ { justVarInterpolation = True+ , toBuilder = VarE 'toText+ , wrap = VarE 'id+ , unwrap = VarE 'id+ }
test/Text/Shakespeare/TextSpec.hs view
@@ -10,11 +10,14 @@ import Data.List (intercalate) import qualified Data.Text as T import qualified Data.Text.Lazy as TL +import Data.Text.Lazy.Builder (toLazyText) import qualified Data.List import qualified Data.List as L import Data.Text (Text, pack, unpack) import Data.Monoid (mappend) +import Text.Shakespeare.BuilderQQ + spec :: Spec spec = do it "text" $ do @@ -114,6 +117,11 @@ |#{val} |1 |] + + it "caret operation with justVarInterpolation = True" $ do + let val = 2 :: Int + let bld = [builderQQ|#{ show val }|] + simpT "2" $ toLazyText [builderQQ|^{ bld }|] simpT :: String -> TL.Text -> Assertion simpT a b = nocrlf (pack a) @=? nocrlf (TL.toStrict b)