Skip to content
Browse files

Missing context inverted sections

Signed-off-by: Alexander Dorofeev <aka.spin@gmail.com>
  • Loading branch information...
1 parent a72b0ed commit 71c5a51df593829d7c9dcf160a695f8c0bd75c73 @akaspin akaspin committed
Showing with 60 additions and 40 deletions.
  1. +58 −40 Text/Hastache.hs
  2. +2 −0 tests/test.hs
View
98 Text/Hastache.hs
@@ -331,9 +331,49 @@ renderBlock contexts symb inTag afterClose otag ctag conf
| symb == ord8 '&' || (symb == ord8 '{' && otag == defOTag) = do
readVar contexts (tail inTag ~> trimAll) ~> addResLZ
next afterClose
- -- section. inverted section
- | symb == ord8 '#' || symb == ord8 '^' =
- let normalSection = symb == ord8 '#' in do
+
+ -- section
+ | symb == ord8 '#' = do
+ case findCloseSection afterClose (tail inTag) otag ctag of
+ Nothing -> next afterClose
+ Just (sectionContent', afterSection') ->
+ let
+ dropNL str =
+ if (length str) > 0 && (head str) == ord8 '\n'
+ then tail str
+ else str
+ sectionContent = dropNL sectionContent'
+ afterSection =
+ if ord8 '\n' `elem` sectionContent
+ then dropNL afterSection'
+ else afterSection'
+ tlInTag = tail inTag
+ readContext = map ($ tlInTag) contexts
+ ~> List.find (not . isMuNothing)
+ in
+ case readContext of
+ Just (MuList []) -> do
+ next afterSection
+ Just (MuList b) -> do
+ mapM_ (\c -> processBlock sectionContent
+ (c:contexts) otag ctag conf) b
+ next afterSection
+ Just (MuBool True) -> do
+ processBlock sectionContent
+ contexts otag ctag conf
+ next afterSection
+ Just (MuLambda func) -> do
+ func sectionContent ~> toLByteString ~> addResLZ
+ next afterSection
+ Just (MuLambdaM func) -> do
+ res <- lift (func sectionContent)
+ toLByteString res ~> addResLZ
+ next afterSection
+ _ -> do
+ next afterSection
+
+ -- inverted section
+ | symb == ord8 '^' = do
case findCloseSection afterClose (tail inTag) otag ctag of
Nothing -> next afterClose
Just (sectionContent', afterSection') ->
@@ -350,44 +390,22 @@ renderBlock contexts symb inTag afterClose otag ctag conf
tlInTag = tail inTag
readContext = map ($ tlInTag) contexts
~> List.find (not . isMuNothing)
- in do
+ in
case readContext of
- Just (MuList []) ->
- if normalSection then do next afterSection
- else do
- processBlock sectionContent
- contexts otag ctag conf
- next afterSection
- Just (MuList b) ->
- if normalSection then do
- mapM_ (\c -> processBlock sectionContent
- (c:contexts) otag ctag conf) b
- next afterSection
- else do next afterSection
- Just (MuBool True) ->
- if normalSection then do
- processBlock sectionContent
- contexts otag ctag conf
- next afterSection
- else do next afterSection
- Just (MuBool False) ->
- if normalSection then do next afterSection
- else do
- processBlock sectionContent
- contexts otag ctag conf
- next afterSection
- Just (MuLambda func) ->
- if normalSection then do
- func sectionContent ~> toLByteString ~> addResLZ
- next afterSection
- else do next afterSection
- Just (MuLambdaM func) ->
- if normalSection then do
- res <- lift (func sectionContent)
- toLByteString res ~> addResLZ
- next afterSection
- else do next afterSection
- _ -> next afterSection
+ Just (MuList []) -> do
+ processBlock sectionContent
+ contexts otag ctag conf
+ next afterSection
+ Just (MuBool False) -> do
+ processBlock sectionContent
+ contexts otag ctag conf
+ next afterSection
+ Nothing -> do
+ processBlock sectionContent
+ contexts otag ctag conf
+ next afterSection
+ _ -> do
+ next afterSection
-- set delimiter
| symb == ord8 '=' =
let
View
2 tests/test.hs
@@ -365,6 +365,7 @@ nestedGenericContextTest = do
\Top variable : {{topDataTop}}\n\
\Nested variable : {{nestedDataNested}}\n\
\{{/topDataItems}}\n\
+ \no context : {{^noCtx}}Should render{{/noCtx}}\n\
\"
context = mkGenericContext $ TopData {
topDataTop = "TOP",
@@ -380,6 +381,7 @@ nestedGenericContextTest = do
\-- Nested section\n\
\Top variable : TOP\n\
\Nested variable : NESTED_TWO\n\
+ \no context : Should render\n\
\"
tests = TestList [

0 comments on commit 71c5a51

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