packages feed

haiji 0.3.2.0 → 0.3.3.0

raw patch · 3 files changed

+31/−10 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

haiji.cabal view
@@ -2,7 +2,7 @@ --  see http://haskell.org/cabal/users-guide/  name:                haiji-version:             0.3.2.0+version:             0.3.3.0 synopsis:            A typed template engine, subset of jinja2 description:         Haiji is a template engine which is subset of jinja2.                      This is designed to free from the unintended rendering result
src/Text/Haiji/Syntax/AST.hs view
@@ -259,19 +259,31 @@ -- Right {% if foo %}テスト{% endif %} -- >>> exec "    {%- if foo -%}    テスト    {%- endif -%}    " -- Right (ParserState {parserStateLeadingSpaces = Nothing, parserStateInBaseTemplate = True})+-- >>> eval "{% if foo %}テスト{% elif bar %}hoge{% endif %}"+-- Right {% if foo %}テスト{% else %}{% if bar %}hoge{% endif %}{% endif %}+-- >>> eval "{% if foo %}  テスト  {% elif bar %}  hoge  {% endif %}"+-- Right {% if foo %}  テスト  {% else %}{% if bar %}  hoge  {% endif %}{% endif %}+-- >>> eval "{% if foo -%}  テスト  {%- elif bar -%}  hoge  {%- endif %}"+-- Right {% if foo %}テスト{% else %}{% if bar %}hoge{% endif %}{% endif %} -- condition :: HaijiParser (AST 'Partially)-condition = withLeadingSpacesOf start rest where-  start = statement $ string "if" >> skipMany1 space >> expression+condition = withLeadingSpacesOf (start "if") rest where+  start kwd = statement $ string kwd >> skipMany1 space >> expression   rest cond = do     ifPart <- haijiParser-    mElsePart <- mayElse-    leadingElseSpaces <- getLeadingSpaces-    _ <- statement $ string "endif"-    leadingEndIfSpaces <- getLeadingSpaces-    return $ case mElsePart of-      Nothing       -> Condition cond (ifPart ++ maybeToList leadingEndIfSpaces) Nothing-      Just elsePart -> Condition cond (ifPart ++ maybeToList leadingElseSpaces ) (Just $ elsePart ++ maybeToList leadingEndIfSpaces)+    mElifPart <- option Nothing (Just <$> withLeadingSpacesOf (start "elif") rest)+    case mElifPart of+      Just elif -> do+        leadingElifSpaces <- getLeadingSpaces+        return $ Condition cond (ifPart ++ maybeToList leadingElifSpaces) (Just [elif])+      Nothing -> do+        mElsePart <- mayElse+        leadingElseSpaces <- getLeadingSpaces+        _ <- statement $ string "endif"+        leadingEndIfSpaces <- getLeadingSpaces+        return $ case mElsePart of+          Nothing       -> Condition cond (ifPart ++ maybeToList leadingEndIfSpaces) Nothing+          Just elsePart -> Condition cond (ifPart ++ maybeToList leadingElseSpaces ) (Just $ elsePart ++ maybeToList leadingEndIfSpaces)  mayElse :: HaijiParser (Maybe [AST 'Partially]) mayElse = option Nothing (Just <$> elseParser) where
test/condition.tmpl view
@@ -19,3 +19,12 @@ {% endif %} B {% endif %}+++{% if foo %}+foo+{% elif bar %}+bar+{% else %}+baz+{% endif %}