From ff3bb3435b7ee203a50e12dc066610aa30732090 Mon Sep 17 00:00:00 2001 From: jverzani Date: Sat, 3 Nov 2018 11:12:12 -0400 Subject: [PATCH] address issue #82, comment on issue #83 --- src/tokens.jl | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/tokens.jl b/src/tokens.jl index bd0754b..c0be3fd 100644 --- a/src/tokens.jl +++ b/src/tokens.jl @@ -449,9 +449,8 @@ function renderTokensByValue(value, io, token, writer, context, template) end ## Helper function for dispatch based on value in renderTokens -function _renderTokensByValue(value::Dict, io, token, writer, context, template) +function _renderTokensByValue(value::AbstractDict, io, token, writer, context, template) renderTokens(io, token.collector, writer, ctx_push(context, value), template) - # renderTokens(io, token.collector, writer,context, template) end @@ -544,15 +543,10 @@ function renderTokens(io, tokens, writer, context, template) token = tokens[i] tokenValue = token.value - println("Type = $(token._type)") - if token._type == "#" || token._type == "|" ## iterate over value if Dict, Array or DataFrame, ## or display conditionally value = lookup(context, tokenValue) - println("value=$value") - println("---") - println("context=$context") if !isa(value, AnIndex) context = Context(value, context) end @@ -577,23 +571,22 @@ function renderTokens(io, tokens, writer, context, template) elseif token._type == ">" ## partials: desc: Each line of the partial should be indented before rendering. fname = stripWhitespace(tokenValue) + value = lookup(context, tokenValue) + + tpl_string = "" if isfile(fname) + found_partial = true indent = token.indent buf = IOBuffer() for (rowno, l) in enumerate(eachline(fname, keep=true)) # we don't strip indent from first line, so we don't indent that print(buf, rowno > 0 ? indent : "", l) end - tpl = parse(String(take!(buf))) - @info "read in $tpl" - - renderTokens(io, tpl, writer, context, template) - close(buf) + tpl_string = String(take!(buf)) else value = lookup(context, fname) if !falsy(value) - indent = token.indent slashn = "" # don't indent if last \n @@ -604,12 +597,24 @@ function renderTokens(io, tokens, writer, context, template) buf = IOBuffer() l = split(value, r"[\n]") print(buf, indent*join(l, "\n"*indent)) - tpl = String(take!(buf)) * slashn - renderTokens(io, parse(tpl), writer, context, template) + tpl_string = String(take!(buf)) * slashn close(buf) end end + if tpl_string != "" + ## Delimiters set in a parent template should not affect a partial. + ## Delimiters set in a partial should not affect the parent template. + tpl = parse(tpl_string, ("{{", "}}")) + ## Issue 82, what context to pass along to the partial + ## this makes "scope" of partial just the immediate value, not + ## the parent + renderTokens(io, tpl, writer, Context(value, Context(context.view,nothing)), template) + else + # can't find partial. Issue #83 requests signal, but this doesn't + # seem to match spec. Signal would go here. + end + elseif token._type == "<" ## partials without parse fname = stripWhitespace(tokenValue)