packages feed

hamlet 0.2.2 → 0.2.3

raw patch · 5 files changed

+46/−10 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Text.Hamlet.Monad: maybeH' :: (Monad m) => Maybe v -> (v -> Hamlet url m ()) -> Maybe (Hamlet url m ()) -> Hamlet url m ()
- Text.Hamlet.Parse: DocMaybe :: Deref -> Ident -> [Doc] -> Doc
+ Text.Hamlet.Parse: DocMaybe :: Deref -> Ident -> [Doc] -> (Maybe [Doc]) -> Doc

Files

Text/Hamlet/Monad.hs view
@@ -21,6 +21,7 @@     , mapH     , condH     , maybeH+    , maybeH'     , printHamlet     , hamletToText     , cdata@@ -222,6 +223,17 @@        -> Hamlet url m () maybeH Nothing _ = return () maybeH (Just v) f = f v++-- | Runs the second argument with the value in the first, if available.+-- Otherwise, runs the third argument, if available.+maybeH' :: Monad m+        => Maybe v+        -> (v -> Hamlet url m ())+        -> Maybe (Hamlet url m ())+        -> Hamlet url m ()+maybeH' Nothing _ Nothing = return ()+maybeH' Nothing _ (Just x) = x+maybeH' (Just v) f _ = f v  -- | Prints a Hamlet to standard out. Good for debugging. printHamlet :: (url -> String) -> Hamlet url IO () -> IO ()
Text/Hamlet/Parse.hs view
@@ -56,6 +56,7 @@           | LineElseIf Deref           | LineElse           | LineMaybe Deref Ident+          | LineNothing           | LineTag             { _lineTagName :: String             , _lineAttr :: [(Maybe Deref, String, [Content])]@@ -98,6 +99,7 @@             (False, y') <- parseIdent' False y             return $ LineMaybe x' y'         _ -> Error $ "Invalid maybe: " ++ rest+parseLine _ "$nothing" = Ok LineNothing parseLine _ x@(c:_) | c `elem` "%#." = do     let (begin, rest) = break (== ' ') x         rest' = dropWhile (== ' ') rest@@ -294,7 +296,7 @@  data Doc = DocForall Deref Ident [Doc]          | DocCond [(Deref, [Doc])] (Maybe [Doc])-         | DocMaybe Deref Ident [Doc]+         | DocMaybe Deref Ident [Doc] (Maybe [Doc])          | DocContent [Content]     deriving (Show, Eq, Read, Data, Typeable) @@ -311,8 +313,14 @@     Ok $ DocCond ifs el : rest'' nestToDoc set (Nest (LineMaybe d i) inside:rest) = do     inside' <- nestToDoc set inside-    rest' <- nestToDoc set rest-    Ok $ DocMaybe d i inside' : rest'+    (nothing, rest') <-+        case rest of+            Nest LineNothing ninside:x -> do+                ninside' <- nestToDoc set ninside+                return (Just ninside', x)+            _ -> return (Nothing, rest)+    rest'' <- nestToDoc set rest'+    Ok $ DocMaybe d i inside' nothing : rest'' nestToDoc set (Nest (LineTag tn attrs content classes) inside:rest) = do     let attrs' =             case classes of@@ -347,13 +355,15 @@     Ok $ DocContent content : inside' ++ rest' nestToDoc _set (Nest (LineElseIf _) _:_) = Error "Unexpected elseif" nestToDoc _set (Nest LineElse _:_) = Error "Unexpected else"+nestToDoc _set (Nest LineNothing _:_) = Error "Unexpected nothing"  compressDoc :: [Doc] -> [Doc] compressDoc [] = [] compressDoc (DocForall d i doc:rest) =     DocForall d i (compressDoc doc) : compressDoc rest-compressDoc (DocMaybe d i doc:rest) =-    DocMaybe d i (compressDoc doc) : compressDoc rest+compressDoc (DocMaybe d i doc mnothing:rest) =+    DocMaybe d i (compressDoc doc) (fmap compressDoc mnothing)+  : compressDoc rest compressDoc (DocCond [(a, x)] Nothing:DocCond [(b, y)] Nothing:rest)     | a == b = compressDoc $ DocCond [(a, x ++ y)] Nothing : rest compressDoc (DocCond x y:rest) =
Text/Hamlet/Quasi.hs view
@@ -48,14 +48,21 @@     dos <- LamE [VarP ident'] <$> (safeDoE $ inside' [])     let stmt = NoBindS $ mh `AppE` dos `AppE` deref''     return (vars', stmts . stmts' . (:) stmt)-docToStmt (vars, stmts) (DocMaybe deref ident@(Ident name) inside) = do+docToStmt (vars, stmts) (DocMaybe deref ident@(Ident name) inside mno) = do     (vars', base, stmts') <- bindDeref vars deref     ident' <- newName name     let vars'' = ([ident], VarE ident') : vars'     (_, inside') <- foldM docToStmt (vars'', id) inside     dos <- LamE [VarP ident'] <$> (safeDoE $ inside' [])-    mh <- [|maybeH|]-    let stmt = NoBindS $ mh `AppE` base `AppE` dos+    ninside <- case mno of+                Nothing -> [|Nothing|]+                Just no -> do+                    (_, ninside') <- foldM docToStmt (vars'', id) no+                    j <- [|Just|]+                    x <- safeDoE $ ninside' []+                    return $ j `AppE` x+    mh <- [|maybeH'|]+    let stmt = NoBindS $ mh `AppE` base `AppE` dos `AppE` ninside     return (vars', stmts . stmts' . (:) stmt) docToStmt (vars, stmts) (DocCond conds final) = do     conds' <- liftConds vars conds id
hamlet.cabal view
@@ -1,5 +1,5 @@ name:            hamlet-version:         0.2.2+version:         0.2.3 license:         BSD3 license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com>
runtests.hs view
@@ -293,8 +293,15 @@ caseAttribOrder = helper "<meta 1 2 3>" [$hamlet|%meta!1!2!3|]  caseNothing :: Assertion-caseNothing = helper "" [$hamlet|+caseNothing = do+    helper "" [$hamlet| $maybe nothing.theArg n+    nothing+|]+    helper "nothing" [$hamlet|+$maybe nothing.theArg n+    something+$nothing     nothing |]