Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support whitespace around variable names #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mustache.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (tmpl *Template) parseSection(section *sectionElement) error {
case '{':
if tag[len(tag)-1] == '}' {
//use a raw tag
section.elems = append(section.elems, &varElement{tag[1 : len(tag)-1], true})
section.elems = append(section.elems, &varElement{strings.TrimSpace(tag[1 : len(tag)-1]), true})
}
default:
section.elems = append(section.elems, &varElement{tag, false})
Expand Down Expand Up @@ -282,7 +282,7 @@ func (tmpl *Template) parse() error {
case '{':
//use a raw tag
if tag[len(tag)-1] == '}' {
tmpl.elems = append(tmpl.elems, &varElement{tag[1 : len(tag)-1], true})
tmpl.elems = append(tmpl.elems, &varElement{strings.TrimSpace(tag[1 : len(tag)-1]), true})
}
default:
tmpl.elems = append(tmpl.elems, &varElement{tag, false})
Expand Down
2 changes: 2 additions & 0 deletions mustache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ var tests = []Test{
{`hello world`, nil, "hello world"},
{`hello {{name}}`, map[string]string{"name": "world"}, "hello world"},
{`{{var}}`, map[string]string{"var": "5 > 2"}, "5 > 2"},
{`{{ var }}`, map[string]string{"var": "5 > 2"}, "5 > 2"},
{`{{{var}}}`, map[string]string{"var": "5 > 2"}, "5 > 2"},
{`{{{ var }}}`, map[string]string{"var": "5 > 2"}, "5 > 2"},
{`{{a}}{{b}}{{c}}{{d}}`, map[string]string{"a": "a", "b": "b", "c": "c", "d": "d"}, "abcd"},
{`0{{a}}1{{b}}23{{c}}456{{d}}89`, map[string]string{"a": "a", "b": "b", "c": "c", "d": "d"}, "0a1b23c456d89"},
{`hello {{! comment }}world`, map[string]string{}, "hello world"},
Expand Down