Skip to content

Commit

Permalink
Fixes for pug@2.0.0-alpha3
Browse files Browse the repository at this point in the history
  • Loading branch information
shama committed Apr 14, 2016
1 parent 866841a commit 563653d
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 93 deletions.
1 change: 0 additions & 1 deletion Gruntfile.js
Expand Up @@ -145,7 +145,6 @@ module.exports = function(grunt) {
}
},


// Unit tests.
nodeunit: {
tests: ['test/*_test.js']
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -17,7 +17,7 @@
},
"dependencies": {
"chalk": "^1.0.0",
"pug": "^0.1.0"
"pug": "^2.0.0-alpha3"
},
"devDependencies": {
"grunt": "^1.0.0",
Expand Down
4 changes: 3 additions & 1 deletion tasks/pug.js
Expand Up @@ -69,8 +69,10 @@ module.exports = function(grunt) {
f.orig.data = data;
}
if (options.filters) {
if (!f.orig.data.filters) f.orig.data.filters = {};
Object.keys(options.filters).forEach(function(filter) {
pug.filters[filter] = options.filters[filter].bind(f.orig);
f.orig.data.filters[filter] = options.filters[filter].bind(f.orig);
options.filters[filter] = options.filters[filter].bind(f.orig);
});
}
// if in client mode, return function source
Expand Down
17 changes: 5 additions & 12 deletions test/expected/amd/pug.js
@@ -1,16 +1,9 @@
define(['pug'], function(pug) { if(pug && pug['runtime'] !== undefined) { pug = pug.runtime; }

return function template(locals) {
var buf = [];
var pug_mixins = {};
var pug_interp;
;var locals_for_with = (locals || {});(function (test) {
buf.push("<div id=\"test\" class=\"test\"><span id=\"data\">data</span>");
if ( test)
{
buf.push("<div>testing</div>");
}
buf.push("</div>");}.call(this,"test" in locals_for_with?locals_for_with.test:typeof test!=="undefined"?test:undefined));;return buf.join("");
return function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;;var locals_for_with = (locals || {});(function (test) {pug_html = pug_html + "\u003Cdiv class=\"test\" id=\"test\"\u003E\u003Cspan id=\"data\"\u003Edata\u003C\u002Fspan\u003E";
if (test) {
pug_html = pug_html + "\u003Cdiv\u003Etesting\u003C\u002Fdiv\u003E";
}
pug_html = pug_html + "\u003C\u002Fdiv\u003E";}.call(this,"test" in locals_for_with?locals_for_with.test:typeof test!=="undefined"?test:undefined));;return pug_html;}

});
});
15 changes: 4 additions & 11 deletions test/expected/amd/pug2.js
@@ -1,16 +1,9 @@
define(['pug'], function(pug) { if(pug && pug['runtime'] !== undefined) { pug = pug.runtime; }

return function template(locals) {
var buf = [];
var pug_mixins = {};
var pug_interp;
;var locals_for_with = (locals || {});(function (test) {
buf.push("<div id=\"test\" class=\"test\"><span id=\"data\">data</span>");
if ( test)
{
buf.push("<div>testing 2</div>");
}
buf.push("</div>");}.call(this,"test" in locals_for_with?locals_for_with.test:typeof test!=="undefined"?test:undefined));;return buf.join("");
return function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;;var locals_for_with = (locals || {});(function (test) {pug_html = pug_html + "\u003Cdiv class=\"test\" id=\"test\"\u003E\u003Cspan id=\"data\"\u003Edata\u003C\u002Fspan\u003E";
if (test) {
pug_html = pug_html + "\u003Cdiv\u003Etesting 2\u003C\u002Fdiv\u003E";
}
pug_html = pug_html + "\u003C\u002Fdiv\u003E";}.call(this,"test" in locals_for_with?locals_for_with.test:typeof test!=="undefined"?test:undefined));;return pug_html;}

});
11 changes: 3 additions & 8 deletions test/expected/amd/pugInclude.js
@@ -1,13 +1,8 @@
define(['pug'], function(pug) { if(pug && pug['runtime'] !== undefined) { pug = pug.runtime; }

return function template(locals) {
var buf = [];
var pug_mixins = {};
var pug_interp;

buf.push("<html><head><title>TEST</title></head><body></body></html>");
return function pug_escape(e){var a=""+e,t=pug_match_html.exec(a);if(!t)return e;var r,c,n,s="";for(r=t.index,c=0;r<a.length;r++){switch(a.charCodeAt(r)){case 34:n="&quot;";break;case 38:n="&amp;";break;case 60:n="&lt;";break;case 62:n="&gt;";break;default:continue}c!==r&&(s+=a.substring(c,r)),c=r+1,s+=n}return c!==r?s+a.substring(c,r):s}
var pug_match_html=/["&<>]/;function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;pug_html = pug_html + "\u003Chtml\u003E\u003Chead\u003E\u003Ctitle\u003ETEST\u003C\u002Ftitle\u003E\u003C\u002Fhead\u003E\u003Cbody\u003E\u003C\u002Fbody\u003E\u003C\u002Fhtml\u003E";
var a = 'hello pug test'
buf.push("<p>" + (pug.escape(null == (pug_interp = a) ? "" : pug_interp)) + "</p>");;return buf.join("");
}
pug_html = pug_html + "\u003Cp\u003E" + (pug_escape(null == (pug_interp = a) ? "" : pug_interp)) + "\u003C\u002Fp\u003E";;return pug_html;}

});
9 changes: 2 additions & 7 deletions test/expected/amd/pugTemplate.js

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

15 changes: 4 additions & 11 deletions test/expected/jst/pug.js
@@ -1,14 +1,7 @@
this["JST"] = this["JST"] || {};

this["JST"]["pug"] = function template(locals) {
var buf = [];
var pug_mixins = {};
var pug_interp;
;var locals_for_with = (locals || {});(function (test) {
buf.push("<div id=\"test\" class=\"test\"><span id=\"data\">data</span>");
if ( test)
{
buf.push("<div>testing</div>");
this["JST"]["pug"] = function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;;var locals_for_with = (locals || {});(function (test) {pug_html = pug_html + "\u003Cdiv class=\"test\" id=\"test\"\u003E\u003Cspan id=\"data\"\u003Edata\u003C\u002Fspan\u003E";
if (test) {
pug_html = pug_html + "\u003Cdiv\u003Etesting\u003C\u002Fdiv\u003E";
}
buf.push("</div>");}.call(this,"test" in locals_for_with?locals_for_with.test:typeof test!=="undefined"?test:undefined));;return buf.join("");
};
pug_html = pug_html + "\u003C\u002Fdiv\u003E";}.call(this,"test" in locals_for_with?locals_for_with.test:typeof test!=="undefined"?test:undefined));;return pug_html;};
15 changes: 4 additions & 11 deletions test/expected/jst/pug2.js
@@ -1,14 +1,7 @@
this["JST"] = this["JST"] || {};

this["JST"]["pug2"] = function template(locals) {
var buf = [];
var pug_mixins = {};
var pug_interp;
;var locals_for_with = (locals || {});(function (test) {
buf.push("<div id=\"test\" class=\"test\"><span id=\"data\">data</span>");
if ( test)
{
buf.push("<div>testing 2</div>");
this["JST"]["pug2"] = function template(locals) {var pug_html = "", pug_mixins = {}, pug_interp;;var locals_for_with = (locals || {});(function (test) {pug_html = pug_html + "\u003Cdiv class=\"test\" id=\"test\"\u003E\u003Cspan id=\"data\"\u003Edata\u003C\u002Fspan\u003E";
if (test) {
pug_html = pug_html + "\u003Cdiv\u003Etesting 2\u003C\u002Fdiv\u003E";
}
buf.push("</div>");}.call(this,"test" in locals_for_with?locals_for_with.test:typeof test!=="undefined"?test:undefined));;return buf.join("");
};
pug_html = pug_html + "\u003C\u002Fdiv\u003E";}.call(this,"test" in locals_for_with?locals_for_with.test:typeof test!=="undefined"?test:undefined));;return pug_html;};
11 changes: 3 additions & 8 deletions test/expected/jst/pugInclude.js

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

9 changes: 2 additions & 7 deletions test/expected/jst/pugTemplate.js

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

2 changes: 1 addition & 1 deletion test/expected/pug.html
@@ -1 +1 @@
<div id="test" class="test"><span id="data">data</span><div>testing</div></div>
<div class="test" id="test"><span id="data">data</span><div>testing</div></div>
2 changes: 1 addition & 1 deletion test/expected/pug2.html
@@ -1 +1 @@
<div id="test" class="test"><span id="data">data</span><div>testing 2</div></div>
<div class="test" id="test"><span id="data">data</span><div>testing 2</div></div>
2 changes: 1 addition & 1 deletion test/fixtures/pugUsingmixin.pug
@@ -1,2 +1,2 @@
include mixins
include mixins.pug
+themixin
11 changes: 11 additions & 0 deletions test/helpers.js
@@ -0,0 +1,11 @@
var helpers = module.exports = {};

var grunt = require('grunt');

helpers.read = function(src) {
var result = grunt.util.normalizelf(grunt.file.read(src));
if (result.slice(-1) === '\n') {
result = result.slice(0, -1);
}
return result;
};
5 changes: 1 addition & 4 deletions test/pug_amd_test.js
@@ -1,10 +1,7 @@
'use strict';

var grunt = require('grunt');

var read = function(src) {
return grunt.util.normalizelf(grunt.file.read(src));
};
var read = require('./helpers').read;

exports.pug = {
compile: function(test) {
Expand Down
5 changes: 1 addition & 4 deletions test/pug_jst_test.js
@@ -1,10 +1,7 @@
'use strict';

var grunt = require('grunt');

var read = function(src) {
return grunt.util.normalizelf(grunt.file.read(src));
};
var read = require('./helpers').read;

exports.pug = {
compile: function(test) {
Expand Down
5 changes: 1 addition & 4 deletions test/pug_test.js
@@ -1,10 +1,7 @@
'use strict';

var grunt = require('grunt');

var read = function(src) {
return grunt.util.normalizelf(grunt.file.read(src));
};
var read = require('./helpers').read;

exports.pug = {
compile: function(test) {
Expand Down

0 comments on commit 563653d

Please sign in to comment.