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

Update dependencies (fix npm audit failures); fix tests; update Travis build #169

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,6 @@
{
"rules": {
"pabigot/affixed-ids": "off"
},
"extends": "grunt"
}
3 changes: 0 additions & 3 deletions .jscsrc

This file was deleted.

10 changes: 3 additions & 7 deletions .travis.yml
@@ -1,13 +1,9 @@
sudo: false
language: node_js
node_js:
- "0.10"
- "0.12"
- "4"
- "5"
- "iojs"
before_install:
- if [ "$TRAVIS_NODE_VERSION" = "0.10" ]; then npm install -g npm@2; fi
- "8"
- "10"
- "12"
matrix:
fast_finish: true
cache:
Expand Down
10 changes: 5 additions & 5 deletions Gruntfile.js
Expand Up @@ -23,10 +23,10 @@ module.exports = function(grunt) {
}
},

jscs: {
src: ['tasks/**/*.js', 'test/*.js', 'Gruntfile.js'],
eslint: {
target: ['tasks/**/*.js', 'test/*.js', 'Gruntfile.js'],
options: {
config: '.jscsrc'
config: '.eslintrc.json'
}
},

Expand Down Expand Up @@ -356,11 +356,11 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-internal');
grunt.loadNpmTasks('grunt-jscs');
grunt.loadNpmTasks('grunt-eslint');

// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's task(s), then test the result.
grunt.registerTask('test', ['jshint', 'jscs', 'clean', 'handlebars', 'nodeunit']);
grunt.registerTask('test', ['jshint', 'eslint', 'clean', 'handlebars', 'nodeunit']);

// By default, lint and run all tests.
grunt.registerTask('default', ['test', 'build-contrib']);
Expand Down
8 changes: 5 additions & 3 deletions package.json
Expand Up @@ -16,17 +16,19 @@
"test": "grunt test"
},
"dependencies": {
"handlebars": "~4.0.0",
"chalk": "^1.0.0",
"handlebars": "^4.3.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 4.3.3 at the time of writing

"nsdeclare": "0.1.0"
},
"devDependencies": {
"eslint-config-grunt": "^2.0.1",
"eslint-plugin-pabigot": "^1.1.0",
"grunt": "^1.0.0",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-internal": "^1.1.0",
"grunt-contrib-jshint": "^1.0.0",
"grunt-contrib-nodeunit": "^1.0.0",
"grunt-jscs": "^2.1.0"
"grunt-contrib-nodeunit": "^2.0.0",
"grunt-eslint": "^22.0.0"
},
"keywords": [
"gruntplugin"
Expand Down
102 changes: 54 additions & 48 deletions tasks/handlebars.js
Expand Up @@ -14,18 +14,24 @@ module.exports = function(grunt) {
var _ = grunt.util._;

// content conversion for templates
var defaultProcessContent = function(content) { return content; };
var defaultProcessContent = function(content) {
return content;
};

// AST processing for templates
var defaultProcessAST = function(ast) { return ast; };
var defaultProcessAST = function(ast) {
return ast;
};

// filename conversion for templates
var defaultProcessName = function(name) { return name; };
var defaultProcessName = function(name) {
return name;
};

// filename conversion for partials
var defaultProcessPartialName = function(filepath) {
var pieces = _.last(filepath.split('/')).split('.');
var name = _(pieces).without(_.last(pieces)).join('.'); // strips file extension
var name = _(pieces).without(_.last(pieces)).join('.'); // strips file extension
if (name.charAt(0) === '_') {
name = name.substr(1, name.length); // strips leading _ character
}
Expand Down Expand Up @@ -90,7 +96,7 @@ module.exports = function(grunt) {
var ast, compiled, filename;

// Namespace info for current template
var nsInfo;
var nsInfo; // eslint-disable-line one-var

// Map of already declared namespace parts
var nsDeclarations = {};
Expand Down Expand Up @@ -118,55 +124,55 @@ module.exports = function(grunt) {
}
return true;
})
.forEach(function(filepath) {
var src = processContent(grunt.file.read(filepath), filepath);

var Handlebars = require('handlebars');
try {
// parse the handlebars template into it's AST
ast = processAST(Handlebars.parse(src));
compiled = Handlebars.precompile(ast, compilerOptions);

// if configured to, wrap template in Handlebars.template call
if (options.wrapped === true) {
compiled = 'Handlebars.template(' + compiled + ')';
.forEach(function(filepath) {
var src = processContent(grunt.file.read(filepath), filepath);

var Handlebars = require('handlebars');
try {
// parse the handlebars template into it's AST
ast = processAST(Handlebars.parse(src));
compiled = Handlebars.precompile(ast, compilerOptions);

// if configured to, wrap template in Handlebars.template call
if (options.wrapped === true) {
compiled = 'Handlebars.template(' + compiled + ')';
}
} catch (e) {
grunt.log.error(e);
grunt.fail.warn('Handlebars failed to compile ' + filepath + '.');
}
} catch (e) {
grunt.log.error(e);
grunt.fail.warn('Handlebars failed to compile ' + filepath + '.');
}

// register partial or add template to namespace
if (partialsPathRegex.test(filepath) && isPartialRegex.test(_.last(filepath.split('/')))) {
filename = processPartialName(filepath);
if (options.partialsUseNamespace === true) {
nsInfo = getNamespaceInfo(filepath);
if (nsInfo.declaration) {
declarations.push(nsInfo.declaration);
// register partial or add template to namespace
if (partialsPathRegex.test(filepath) && isPartialRegex.test(_.last(filepath.split('/')))) {
filename = processPartialName(filepath);
if (options.partialsUseNamespace === true) {
nsInfo = getNamespaceInfo(filepath);
if (nsInfo.declaration) {
declarations.push(nsInfo.declaration);
}
partials.push('Handlebars.registerPartial(' + JSON.stringify(filename) + ', ' + nsInfo.namespace +
'[' + JSON.stringify(filename) + '] = ' + compiled + ');');
} else {
partials.push('Handlebars.registerPartial(' + JSON.stringify(filename) + ', ' + compiled + ');');
}
partials.push('Handlebars.registerPartial(' + JSON.stringify(filename) + ', ' + nsInfo.namespace +
'[' + JSON.stringify(filename) + '] = ' + compiled + ');');
} else {
partials.push('Handlebars.registerPartial(' + JSON.stringify(filename) + ', ' + compiled + ');');
}
} else {
if ((options.amd || options.commonjs) && !useNamespace) {
compiled = 'return ' + compiled;
}
filename = processName(filepath);
if (useNamespace) {
nsInfo = getNamespaceInfo(filepath);
if (nsInfo.declaration) {
declarations.push(nsInfo.declaration);
if ((options.amd || options.commonjs) && !useNamespace) {
compiled = 'return ' + compiled;
}
filename = processName(filepath);
if (useNamespace) {
nsInfo = getNamespaceInfo(filepath);
if (nsInfo.declaration) {
declarations.push(nsInfo.declaration);
}
templates.push(nsInfo.namespace + '[' + JSON.stringify(filename) + '] = ' + compiled + ';');
} else if (options.commonjs === true) {
templates.push(compiled + ';');
} else {
templates.push(compiled);
}
templates.push(nsInfo.namespace + '[' + JSON.stringify(filename) + '] = ' + compiled + ';');
} else if (options.commonjs === true) {
templates.push(compiled + ';');
} else {
templates.push(compiled);
}
}
});
});

var output = declarations.concat(partials, templates);
if (output.length < 1) {
Expand Down
4 changes: 2 additions & 2 deletions test/expected/amd_compile.js
Expand Up @@ -2,10 +2,10 @@ define(['handlebars'], function(Handlebars) {

this["JST"] = this["JST"] || {};

this["JST"]["test/fixtures/amd.html"] = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
this["JST"]["test/fixtures/amd.html"] = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "<section class=\"main-app\">\n <h1>Some title</h1>\n <p>I've been compiled with amd support</p>\n</section>";
},"useData":true});

return this["JST"];

});
});
4 changes: 2 additions & 2 deletions test/expected/amd_compile_array.js
@@ -1,7 +1,7 @@
define(['handlebars', 'handlebars.helpers'], function(Handlebars) {

return Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
return Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "<section class=\"main-app\">\n <h1>Some title</h1>\n <p>I've been compiled with amd support</p>\n</section>";
},"useData":true})

});
});
4 changes: 2 additions & 2 deletions test/expected/amd_compile_direct.js
@@ -1,7 +1,7 @@
define(['handlebars'], function(Handlebars) {

return Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
return Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "<section class=\"main-app\">\n <h1>Some title</h1>\n <p>I've been compiled with amd support</p>\n</section>";
},"useData":true})

});
});
4 changes: 2 additions & 2 deletions test/expected/amd_compile_function.js
@@ -1,7 +1,7 @@
define(['handlebars', 'custom dependency'], function(Handlebars) {

return Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
return Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "<section class=\"main-app\">\n <h1>Some title</h1>\n <p>I've been compiled with amd support</p>\n</section>";
},"useData":true})

});
});
4 changes: 2 additions & 2 deletions test/expected/amd_compile_string_deps.js
@@ -1,7 +1,7 @@
define(['handlebars', 'handlebars.helpers'], function(Handlebars) {

return Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
return Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "<section class=\"main-app\">\n <h1>Some title</h1>\n <p>I've been compiled with amd support</p>\n</section>";
},"useData":true})

});
});
4 changes: 2 additions & 2 deletions test/expected/amd_compile_string_path.js
@@ -1,7 +1,7 @@
define(['lib/handlebars'], function(Handlebars) {

return Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
return Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "<section class=\"main-app\">\n <h1>Some title</h1>\n <p>I've been compiled with amd support</p>\n</section>";
},"useData":true})

});
});
4 changes: 2 additions & 2 deletions test/expected/amd_namespace.js
Expand Up @@ -2,10 +2,10 @@ define(['handlebars', 'handlebars.helpers'], function(Handlebars) {

this["foo"] = this["foo"] || {};

this["foo"]["test/fixtures/amd.html"] = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
this["foo"]["test/fixtures/amd.html"] = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "<section class=\"main-app\">\n <h1>Some title</h1>\n <p>I've been compiled with amd support</p>\n</section>";
},"useData":true});

return this["foo"];

});
});
6 changes: 3 additions & 3 deletions test/expected/amd_namespace_as_function.js
Expand Up @@ -6,14 +6,14 @@ this["JST"]["countries"] = this["JST"]["countries"] || {};
this["JST"]["treeNav"] = this["JST"]["treeNav"] || {};
this["JST"]["treeNav"]["leaves"] = this["JST"]["treeNav"]["leaves"] || {};

this["JST"]["countries"]["basic"] = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
this["JST"]["countries"]["basic"] = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "Basic template that does nothing.";
},"useData":true});

this["JST"]["treeNav"]["leaves"]["basic"] = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
this["JST"]["treeNav"]["leaves"]["basic"] = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "Basic template that does nothing.";
},"useData":true});

return this["JST"];

});
});
8 changes: 4 additions & 4 deletions test/expected/amd_partials_no_namespace.js
Expand Up @@ -2,20 +2,20 @@ define(['handlebars'], function(Handlebars) {

this["JST"] = this["JST"] || {};

Handlebars.registerPartial("partial", Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
Handlebars.registerPartial("partial", Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "<span>Canada</span>";
},"useData":true}));

this["JST"]["test/fixtures/one.hbs"] = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
this["JST"]["test/fixtures/one.hbs"] = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, helper;

return "<p>Hello, my name is "
+ container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"name","hash":{},"data":data}) : helper)))
+ container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : container.hooks.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext||{}),{"name":"name","hash":{},"data":data}) : helper)))
+ ". I live in "
+ ((stack1 = container.invokePartial(partials.partial,depth0,{"name":"partial","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
+ "</p>";
},"usePartial":true,"useData":true});

return this["JST"];

});
});
8 changes: 4 additions & 4 deletions test/expected/amd_partials_use_namespace.js
Expand Up @@ -2,20 +2,20 @@ define(['handlebars'], function(Handlebars) {

this["JST"] = this["JST"] || {};

Handlebars.registerPartial("partial", this["JST"]["partial"] = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
Handlebars.registerPartial("partial", this["JST"]["partial"] = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "<span>Canada</span>";
},"useData":true}));

this["JST"]["test/fixtures/one.hbs"] = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
this["JST"]["test/fixtures/one.hbs"] = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, helper;

return "<p>Hello, my name is "
+ container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"name","hash":{},"data":data}) : helper)))
+ container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : container.hooks.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext||{}),{"name":"name","hash":{},"data":data}) : helper)))
+ ". I live in "
+ ((stack1 = container.invokePartial(partials.partial,depth0,{"name":"partial","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
+ "</p>";
},"usePartial":true,"useData":true});

return this["JST"];

});
});
4 changes: 2 additions & 2 deletions test/expected/commonjs_compile.js
Expand Up @@ -2,10 +2,10 @@ module.exports = function(Handlebars) {

this["JST"] = this["JST"] || {};

this["JST"]["test/fixtures/commonjs.html"] = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
this["JST"]["test/fixtures/commonjs.html"] = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "<section class=\"main-app\">\n <h1>Some title</h1>\n <p>I've been compiled with CommonJS support</p>\n</section>\n";
},"useData":true});

return this["JST"];

};
};
4 changes: 2 additions & 2 deletions test/expected/commonjs_compile_direct.js
@@ -1,7 +1,7 @@
module.exports = function(Handlebars) {

return Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
return Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
return "<section class=\"main-app\">\n <h1>Some title</h1>\n <p>I've been compiled with CommonJS support</p>\n</section>\n";
},"useData":true});

};
};