packages feed

hamlet 0.7.0.1 → 0.7.0.2

raw patch · 5 files changed

+43/−9 lines, 5 filesdep +blaze-builderdep +json-enumeratordep +json-typesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependencies added: blaze-builder, json-enumerator, json-types

API changes (from Hackage documentation)

+ Text.Julius: instance ToJavascript Root
+ Text.Julius: instance ToJavascript Value

Files

Text/Cassius.hs view
@@ -248,6 +248,7 @@     c' <- c vt     return $ TupE [d', c' `AppE` derefToExp [] d]   where+    c :: VarType -> Q Exp     c VTPlain = [|CDPlain . toCss|]     c VTUrl = [|CDUrl|]     c VTUrlParam = [|CDUrlParam|]
Text/Hamlet/Parse.hs view
@@ -145,6 +145,7 @@         case cr of             InQuotes -> char '"' >> return ()             NotInQuotes -> return ()+            NotInQuotesAttr -> return ()             InContent -> eol         return $ cc x       where@@ -170,18 +171,19 @@             Right deref -> return $ ContentEmbed deref     contentReg InContent = (ContentRaw . return) <$> noneOf "#@^\r\n"     contentReg NotInQuotes = (ContentRaw . return) <$> noneOf "@^#. \t\n\r>"+    contentReg NotInQuotesAttr = (ContentRaw . return) <$> noneOf "@^ \t\n\r>"     contentReg InQuotes = (ContentRaw . return) <$> noneOf "#@^\\\"\n\r>"-    tagAttribValue = do-        cr <- (char '"' >> return InQuotes) <|> return NotInQuotes+    tagAttribValue notInQuotes = do+        cr <- (char '"' >> return InQuotes) <|> return notInQuotes         content cr-    tagIdent = char '#' >> TagIdent <$> tagAttribValue-    tagClass = char '.' >> TagClass <$> tagAttribValue+    tagIdent = char '#' >> TagIdent <$> tagAttribValue NotInQuotes+    tagClass = char '.' >> TagClass <$> tagAttribValue NotInQuotes     tagAttrib = do         cond <- (Just <$> tagAttribCond) <|> return Nothing-        s <- many1 $ noneOf " \t.!=\r\n>"+        s <- many1 $ noneOf " \t=\r\n>"         v <- (do             _ <- char '='-            s' <- tagAttribValue+            s' <- tagAttribValue NotInQuotesAttr             return s') <|> return []         return $ TagAttrib (cond, s, v)     tagAttribCond = do@@ -214,7 +216,7 @@               | TagAttrib (Maybe Deref, String, [Content])     deriving Show -data ContentRule = InQuotes | NotInQuotes | InContent+data ContentRule = InQuotes | NotInQuotes | NotInQuotesAttr | InContent  data Nest = Nest Line [Nest] 
Text/Julius.hs view
@@ -28,6 +28,10 @@ import qualified Data.Text.Lazy as TL import Text.Hamlet.Quasi (readUtf8File) import Text.Shakespeare+import qualified Data.JSON.Types as J+import qualified Text.JSON.Enumerator as JE+import Data.Text.Lazy.Encoding (decodeUtf8)+import Blaze.ByteString.Builder (toLazyByteString)  renderJavascript :: Javascript -> TL.Text renderJavascript (Javascript b) = toLazyText b@@ -44,6 +48,11 @@ instance ToJavascript [Char] where toJavascript = fromLazyText . TL.pack instance ToJavascript TS.Text where toJavascript = fromText instance ToJavascript TL.Text where toJavascript = fromLazyText+instance ToJavascript J.Root where+    toJavascript (J.RootObject o) = toJavascript $ J.ValueObject o+    toJavascript (J.RootArray o) = toJavascript $ J.ValueArray o+instance ToJavascript J.Value where+    toJavascript = fromLazyText . decodeUtf8 . toLazyByteString . JE.renderValue  data Content = ContentRaw String              | ContentVar Deref@@ -137,6 +146,7 @@     c' <- c vt     return $ TupE [d', c' `AppE` derefToExp [] d]   where+    c :: VarType -> Q Exp     c VTPlain = [|JDPlain . toJavascript|]     c VTUrl = [|JDUrl|]     c VTUrlParam = [|JDUrlParam|]
hamlet.cabal view
@@ -1,5 +1,5 @@ name:            hamlet-version:         0.7.0.1+version:         0.7.0.2 license:         BSD3 license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com>@@ -47,6 +47,9 @@                    , failure          >= 0.1     && < 0.2                    , text             >= 0.7     && < 0.12                    , containers       >= 0.2     && < 0.5+                   , json-types       >= 0.1     && < 0.2+                   , json-enumerator  >= 0.0     && < 0.1+                   , blaze-builder    >= 0.2     && < 0.3     exposed-modules: Text.Hamlet                      Text.Hamlet.RT                      Text.Cassius
runtests.hs view
@@ -12,6 +12,8 @@ import qualified Data.Text.Lazy as T
 import qualified Data.List
 import qualified Data.List as L
+import qualified Data.JSON.Types as J
+import qualified Data.Map as Map
 
 main :: IO ()
 main = defaultMain [testSuite]
@@ -94,6 +96,7 @@     , testCase "in a row" caseInARow
     , testCase "embedded slash" caseEmbeddedSlash
     , testCase "string literals" caseStringLiterals
+    , testCase "embed json" caseEmbedJson
     ]
 
 data Url = Home | Sub SubUrl
@@ -172,10 +175,15 @@ caseStatic = helper "some static content" [$hamlet|some static content|]
 
 caseTag :: Assertion
-caseTag = helper "<p class=\"foo\"><div id=\"bar\">baz</div></p>" [$hamlet|
+caseTag = do
+    helper "<p class=\"foo\"><div id=\"bar\">baz</div></p>" [$hamlet|
 <p .foo
   <#bar>baz
 |]
+    helper "<p class=\"foo.bar\"><div id=\"bar\">baz</div></p>" [$hamlet|
+<p class=foo.bar
+  <#bar>baz
+|]
 
 caseVar :: Assertion
 caseVar = do
@@ -882,3 +890,13 @@     helper "gnirts" [$hamlet|#{L.reverse $ id "string"}|]
     helper "str&quot;ing" [$hamlet|#{"str\"ing"}|]
     helper "str&lt;ing" [$hamlet|#{"str<ing"}|]
+
+caseEmbedJson :: Assertion
+caseEmbedJson = do
+    let v = J.ValueObject $ Map.fromList
+                [ ( T.pack "foo", J.ValueArray
+                    [ J.ValueAtom $ J.AtomText $ T.pack "bar"
+                    , J.ValueAtom $ J.AtomNumber 5
+                    ])
+                ]
+    jelper "{\"foo\":[\"bar\",5.0]}" [$julius|#{v}|]