lymar/hastache — Issue #4: [bug] Context visibility in list sections
Author: akaspin
Created: 2011-10-09 08:24:02+00:00
State: open

Up-level context is not visible from List sections.

Original from [mustache demo](http://mustache.github.com/#demo)
---------------------------------------------------------------

Template:

Top variable : {{top}}
{{#items}}
-- Nested section
Top variable : {{top}}
Nested variable : {{nested}}
{{/items}}

Context:

{
"top": "TOP",
"items": [
{"nested": "NESTED_ONE"},
{"nested": "NESTED_TWO"}
]
}

Output:

Top variable : TOP
-- Nested section
Top variable : TOP
Nested variable : NESTED_ONE
-- Nested section
Top variable : TOP
Nested variable : NESTED_TWO

Hastache with same template
---------------------------

data TopData = TopData {
top :: String,
items :: [NestedData]
} deriving (Data, Typeable)

data NestedData = NestedData {
nested :: String
} deriving (Data, Typeable)

test_genericContext = do
res <- hastacheStr defaultConfig (encodeStr template)
(mkGenericContext context)
putStrLn $ decodeStrLBS res
where
template = "\
\Top variable : {{top}}\n\
\{{#items}}\n\
\ -- Nested section\n\
\ Top variable : {{top}}\n\
\ Nested variable : {{nested}}\n\
\{{/items}}\n\
\"
context = TopData {
top = "TOP",
items = [NestedData "NESTED_ONE",
NestedData "NESTED_TWO"]
}

Output:

Top variable : TOP
-- Nested section
Top variable :
Nested variable : NESTED_ONE
-- Nested section
Top variable :
Nested variable : NESTED_TWO