Skip to content

Commit

Permalink
address issue #82, comment on issue #83
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani committed Nov 3, 2018
1 parent bd22052 commit ff3bb34
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit ff3bb34

Please sign in to comment.