Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ignore specific new-lines by ending code fragments with '-%>' to avoi…

…d cluttering the HTML generated with blank lines.
  • Loading branch information...
commit b9dd359052297e308e85af559cfb91334322eb3e 1 parent 5388bf2
@tuxychandru authored
View
6 grasshopper/lib/ghp.js
@@ -54,6 +54,7 @@ exports.configure = function(config) {
};
function compile(text, helpersCount, fileName) {
+ text = skipIgnoredNewlines(text);
var funcBody = "model = model || {};";
for(var i = 0; i < helpersCount; i++) {
@@ -99,6 +100,11 @@ function compile(text, helpersCount, fileName) {
+ '}', fileName);
}
+function skipIgnoredNewlines(text) {
+ return text.split('-%>\r\n').join('%>').split('-%>\n').join('%>')
+ .split('-%>').join('%>');
+}
+
function escapeCode(str) {
return str.split("'").join("\\'").split('\r').join('\\r').split('\n').join('\\n');
}
View
3  test/fixtures/ghp/newline_skipped.txt
@@ -0,0 +1,3 @@
+<% for (var i = 0; i < 3; i++) { -%>
+<%= i %>
+<% } -%>
View
10 test/simple/ghp-test.js
@@ -73,12 +73,20 @@ suite.tests = {
next();
},
- 'Too big template' : function(next) {
+ 'Too big template': function(next) {
var response = new MockResponse();
ghp.fill('../fixtures/ghp/too_big.txt', response, {}, 'utf8', '../fixtures/ghp', 'txt');
assert.equal(response.out.length, 8207);
assert.ok(response.ended);
next();
+ },
+
+ 'Template with certain new-lines ignored': function(next) {
+ var response = new MockResponse();
+ ghp.fill('../fixtures/ghp/newline_skipped.txt', response, {}, 'utf8', '../fixtures/ghp', 'txt');
+ assert.equal(response.out, '0\n1\n2\n');
+ assert.ok(response.ended);
+ next();
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.