Skip to content

Commit

Permalink
Capitalization view helper doesn't kick in if suffix helpers already …
Browse files Browse the repository at this point in the history
…did. Fixes #2
  • Loading branch information
machty committed Feb 1, 2013
1 parent 5c0b100 commit be3c733
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
11 changes: 10 additions & 1 deletion dist/emblem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2318,10 +2318,19 @@ Emblem.Parser = (function() {

if(ret.mustache) {
// Block. Modify inner MustacheNode and return.

// Make sure a suffix modifier hasn't already been applied.
var ch = ret.mustache.id.string.charAt(0);
if(!ch.match(/[A-Z]/)) return ret;

ret.mustache = unshiftParam(ret.mustache, defaultCapitalizedHelper);
return ret;
} else {
// ret is the MustacheNode

// Make sure a suffix modifier hasn't already been applied.
var ch = ret.id.string.charAt(0);
if(!ch.match(/[A-Z]/)) return ret;

return unshiftParam(ret, defaultCapitalizedHelper);
}
},
Expand Down
2 changes: 1 addition & 1 deletion dist/emblem.min.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,19 @@ Emblem.Parser = (function() {

if(ret.mustache) {
// Block. Modify inner MustacheNode and return.

// Make sure a suffix modifier hasn't already been applied.
var ch = ret.mustache.id.string.charAt(0);
if(!ch.match(/[A-Z]/)) return ret;

ret.mustache = unshiftParam(ret.mustache, defaultCapitalizedHelper);
return ret;
} else {
// ret is the MustacheNode

// Make sure a suffix modifier hasn't already been applied.
var ch = ret.id.string.charAt(0);
if(!ch.match(/[A-Z]/)) return ret;

return unshiftParam(ret, defaultCapitalizedHelper);
}
},
Expand Down
8 changes: 7 additions & 1 deletion spec/qunit_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ test "should not kick in explicit {{mustache}}", ->
shouldCompileTo emblem, { SomeView: 'erp' }, '<p>Yeah erp</p>'



# TODO test overriding the default helper name (instead of always "view")


Expand Down Expand Up @@ -890,6 +889,13 @@ test "line number is provided for preprocessor error", ->

suite "misc."

test "capitalized view helper should not kick in if suffix modifiers present", ->
emblem =
"""
Foo!
"""
shouldCompileToString emblem, '<unbound class="Foo">Foo</unbound>'

test "Emblem has a VERSION defined", ->
ok(Emblem.VERSION, "Emblem.VERSION should be defined")

6 changes: 6 additions & 0 deletions spec/qunit_spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,19 @@ capitalizedLineStarterMustache

if(ret.mustache) {
// Block. Modify inner MustacheNode and return.

// Make sure a suffix modifier hasn't already been applied.
var ch = ret.mustache.id.string.charAt(0);
if(!ch.match(/[A-Z]/)) return ret;

ret.mustache = unshiftParam(ret.mustache, defaultCapitalizedHelper);
return ret;
} else {
// ret is the MustacheNode

// Make sure a suffix modifier hasn't already been applied.
var ch = ret.id.string.charAt(0);
if(!ch.match(/[A-Z]/)) return ret;

return unshiftParam(ret, defaultCapitalizedHelper);
}
}
Expand Down

0 comments on commit be3c733

Please sign in to comment.