Skip to content

Commit

Permalink
include straight partial. Maybe fix #32
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani committed Aug 10, 2016
1 parent c796de6 commit c9992d0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ In this way you may want to think of partials as includes, imports,
template expansion, nested templates, or subtemplates, even though
those aren't literally the case here.


The partial specified by `{{< box.tpl }}` is not parsed, rather included as is into the file. This can be much faster.

## Alternatives

Expand Down
8 changes: 5 additions & 3 deletions src/Mustache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ TEMPLATES = Dict{AbstractString, MustacheTokens}()

## Load template from file
function template_from_file(filepath)
f = open(filepath)
tpl = parse(readstring(f))
close(f)
f = open(readall, filepath)
tpl = parse(f)
# f = open(filepath)
# tpl = parse(readstring(f))
# close(f)
return tpl
end

Expand Down
9 changes: 9 additions & 0 deletions src/tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ function renderTokens(io, tokens, writer, context, template)
if isfile(fname)
renderTokens(io, template_from_file(fname).tokens, writer, context, template)
end

elseif token[1] == "<"
## partials without parse
fname = stripWhitepace(tokenValue)
if isfile(fname)
print(io, open(readall, fname))
else
warn("File $fname not found")
end

elseif token[1] == "&"
value = lookup(context, tokenValue)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ nonSpaceRe = r"\S"
eqRe = r"\s*="
curlyRe = r"\s*\}"
#tagRe = r"#|\^|\/|>|\{|&|=|!"
tagRe = r"^[#^/>{&=!]"
tagRe = r"^[#^/<>{&=!]"


isWhitespace(x) = ismatch(whiteRe, x)
Expand Down

0 comments on commit c9992d0

Please sign in to comment.