Skip to content

Commit

Permalink
close #156, issue with functions and alternate tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani committed Oct 31, 2023
1 parent 6261408 commit e631c1d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
Tables = "1"
julia = "1.0"
Printf = "1.6"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
3 changes: 2 additions & 1 deletion src/tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ function _renderTokensByValue(value::Function, io, token, writer, context, templ
## Supposed to be called value(sec_value, render+context) but
## we call render(value(sec_value), context)
push_task_local_storage(view)
_render = x -> render(x, view)
tags = (token.ltag, token.rtag)
_render = x -> render(parse(x, tags), view)
out = try
value(sec_value, _render)
catch err
Expand Down
20 changes: 20 additions & 0 deletions test/Mustache_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,24 @@ tpl2 = mt"""

## Issue #143 look up key before checking for dotted
@test render("Hello, {{ values.name }}!", Dict("values.name"=>"world")) == "Hello, world!"

## Issue 156 function calls with other tags
tpla = """
<<#:vec>>
- <<{name}>>
- <<#:uppercase>><<{name}>><</:uppercase>>
<</:vec>>
"""
tplb = """
{{#:vec}}
- {{{name}}}
- {{#:uppercase}}{{{name}}}{{/:uppercase}}
{{/:vec}}
"""
view = [Dict("name" => x) for x in ("a", "b")]
_uppercase(str, render) = uppercase(render(str))
a = Mustache.render(Mustache.parse(tpla, ("<<", ">>")); vec, uppercase=_uppercase)
b = Mustache.render(Mustache.parse(tplb); vec, uppercase=_uppercase)
@test a == b

end

0 comments on commit e631c1d

Please sign in to comment.