Skip to content

Commit

Permalink
print used inside a #{} should now work
Browse files Browse the repository at this point in the history
  • Loading branch information
malgorithms committed Jul 24, 2012
1 parent 120fbc2 commit 8510a12
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
10 changes: 6 additions & 4 deletions lib/view.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "toffee",
"description": "An Express 3.x and 2.x templating language based on CoffeeScript with slicker tokens and syntax. Built with love at OkCupid.",
"version": "0.0.22",
"version": "0.0.23",
"directories": {
"lib": "./lib"
},
Expand Down
14 changes: 9 additions & 5 deletions src/view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ class view
return "\n#{@_space ind}__toffee.lineno = #{n}"

_snippetHasEscapeOverride: (str) ->
for token in ['snippet', 'partial', 'raw', 'html', 'json', '__toffee.raw', '__toffee.html', '__toffee.json', 'JSON.stringify']
for token in ['print',' snippet', 'partial', 'raw', 'html', 'json', '__toffee.raw', '__toffee.html', '__toffee.json', 'JSON.stringify']
if str[0...token.length] is token
return true
if (str.length > token.length) and (str[token.length] in [' ','\t','\n','('])
return true
false

_toCoffeeRecurse: (obj, indent_level, indent_baseline) ->
Expand Down Expand Up @@ -306,9 +307,12 @@ domain.toffeeTemplates["#{@identifier}"] = (locals) ->
#{___}__toffee.out = []
#{___}if not print?
#{___}#{___}print = (txt) ->
#{___}#{___}#{___}__toffee.out.push txt
#{___}#{___}#{___}''
#{___}#{___}print = (txt) ->
#{___}#{___}#{___}if toffee.state is states.COFFEE
#{___}#{___}#{___}#{___}__toffee.out.push txt
#{___}#{___}#{___}#{___}return ''
#{___}#{___}#{___}else
#{___}#{___}#{___}#{___}return txt
#{___}__toffee.json = (o) ->
#{___}#{___}res = (""+JSON.stringify o)
Expand Down
10 changes: 6 additions & 4 deletions toffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -7945,12 +7945,14 @@ if (typeof module !== 'undefined' && require.main === module) {
};

view.prototype._snippetHasEscapeOverride = function(str) {
var token, _i, _len, _ref1;
_ref1 = ['snippet', 'partial', 'raw', 'html', 'json', '__toffee.raw', '__toffee.html', '__toffee.json', 'JSON.stringify'];
var token, _i, _len, _ref1, _ref2;
_ref1 = ['print', ' snippet', 'partial', 'raw', 'html', 'json', '__toffee.raw', '__toffee.html', '__toffee.json', 'JSON.stringify'];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
token = _ref1[_i];
if (str.slice(0, token.length) === token) {
return true;
if ((str.length > token.length) && ((_ref2 = str[token.length]) === ' ' || _ref2 === '\t' || _ref2 === '\n' || _ref2 === '(')) {
return true;
}
}
}
return false;
Expand Down Expand Up @@ -8189,7 +8191,7 @@ if (typeof module !== 'undefined' && require.main === module) {
view.prototype._coffeeHeaders = function() {
var ___;
___ = this._tabAsSpaces();
return "domain = this\ndomain.toffeeTemplates = domain.toffeeTemplates or {}\ndomain.toffeeTemplates[\"" + this.identifier + "\"] = (locals) ->\n" + ___ + "domain = this\n" + ___ + "locals.__toffee = {}\n" + ___ + "`with (locals) {`\n" + ___ + "__toffee.out = []\n\n" + ___ + "if not print?\n" + ___ + ___ + "print = (txt) -> \n" + ___ + ___ + ___ + "__toffee.out.push txt\n" + ___ + ___ + ___ + "''\n\n" + ___ + "__toffee.json = (o) ->\n" + ___ + ___ + "res = (\"\"+JSON.stringify o)\n\n" + ___ + "__toffee.html = (o) ->\n" + ___ + ___ + "res = (\"\"+o).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;')\n\n" + ___ + "__toffee.raw = (o) -> o\n\n" + ___ + "if not raw? then raw = __toffee.raw\n" + ___ + "if not html? then html = __toffee.html\n" + ___ + "if not json? then json = __toffee.json\n\n" + ___ + "if not escape?\n" + ___ + ___ + "escape = (o) ->\n" + ___ + ___ + ___ + "if (not __toffee.autoEscape?) or __toffee.autoEscape\n" + ___ + ___ + ___ + ___ + "return __toffee.html o\n\n" + ___ + "states = " + (JSON.stringify(states));
return "domain = this\ndomain.toffeeTemplates = domain.toffeeTemplates or {}\ndomain.toffeeTemplates[\"" + this.identifier + "\"] = (locals) ->\n" + ___ + "domain = this\n" + ___ + "locals.__toffee = {}\n" + ___ + "`with (locals) {`\n" + ___ + "__toffee.out = []\n\n" + ___ + "if not print?\n" + ___ + ___ + "print = (txt) ->\n" + ___ + ___ + ___ + "if toffee.state is states.COFFEE\n" + ___ + ___ + ___ + ___ + "__toffee.out.push txt\n" + ___ + ___ + ___ + ___ + "return ''\n" + ___ + ___ + ___ + "else\n" + ___ + ___ + ___ + ___ + "return txt\n\n" + ___ + "__toffee.json = (o) ->\n" + ___ + ___ + "res = (\"\"+JSON.stringify o)\n\n" + ___ + "__toffee.html = (o) ->\n" + ___ + ___ + "res = (\"\"+o).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;')\n\n" + ___ + "__toffee.raw = (o) -> o\n\n" + ___ + "if not raw? then raw = __toffee.raw\n" + ___ + "if not html? then html = __toffee.html\n" + ___ + "if not json? then json = __toffee.json\n\n" + ___ + "if not escape?\n" + ___ + ___ + "escape = (o) ->\n" + ___ + ___ + ___ + "if (not __toffee.autoEscape?) or __toffee.autoEscape\n" + ___ + ___ + ___ + ___ + "return __toffee.html o\n\n" + ___ + "states = " + (JSON.stringify(states));
};

view.prototype._coffeeFooters = function() {
Expand Down

0 comments on commit 8510a12

Please sign in to comment.