diff --git a/.jshintrc b/.jshintrc index fc19146..507f912 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,13 +1,14 @@ { + "boss": true, "curly": true, "eqeqeq": true, + "eqnull": true, "immed": true, "latedef": true, "newcap": true, "noarg": true, + "node": true, "sub": true, "undef": true, - "boss": true, - "eqnull": true, - "node": true -} \ No newline at end of file + "unused": true +} diff --git a/Gruntfile.js b/Gruntfile.js index c33654b..09a16bd 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -37,7 +37,7 @@ module.exports = function(grunt) { } }, files: { - "tmp/jst.js": ["test/fixtures/template.html"] + 'tmp/jst.js': ['test/fixtures/template.html'] } }, pretty_amd: { @@ -49,7 +49,7 @@ module.exports = function(grunt) { amd: true }, files: { - "tmp/pretty_amd.js": ["test/fixtures/template.html"] + 'tmp/pretty_amd.js': ['test/fixtures/template.html'] } }, prettify: { @@ -60,7 +60,7 @@ module.exports = function(grunt) { prettify: true }, files: { - "tmp/pretty.js": ["test/fixtures/template.html"] + 'tmp/pretty.js': ['test/fixtures/template.html'] } }, amd_wrapper: { @@ -71,7 +71,7 @@ module.exports = function(grunt) { amd:true }, files: { - "tmp/amd_wrapper.js": ["test/fixtures/template.html"] + 'tmp/amd_wrapper.js': ['test/fixtures/template.html'] } }, amd_wrapper_no_ns: { @@ -79,21 +79,21 @@ module.exports = function(grunt) { templateSettings: { variable: 'obj' }, - amd:true, - namespace:false + amd: true, + namespace: false }, files: { - "tmp/amd_wrapper_no_ns.js": ["test/fixtures/template.html"] + 'tmp/amd_wrapper_no_ns.js': ['test/fixtures/template.html'] } }, uglyfile: { options: { templateSettings: { variable: 'obj' - }, + } }, files: { - "tmp/uglyfile.js": ["test/fixtures/*bad-filename*"] + 'tmp/uglyfile.js': ['test/fixtures/*bad-filename*'] } }, ns_nested: { @@ -101,10 +101,10 @@ module.exports = function(grunt) { templateSettings: { variable: 'obj' }, - namespace: "MyApp.JST.Main" + namespace: 'MyApp.JST.Main' }, files: { - "tmp/ns_nested.js": ["test/fixtures/template.html"] + 'tmp/ns_nested.js': ['test/fixtures/template.html'] } }, ns_nested_this: { @@ -112,10 +112,10 @@ module.exports = function(grunt) { templateSettings: { variable: 'obj' }, - namespace: "this.MyApp.JST.Main" + namespace: 'this.MyApp.JST.Main' }, files: { - "tmp/ns_nested_this.js": ["test/fixtures/template.html"] + 'tmp/ns_nested_this.js': ['test/fixtures/template.html'] } }, process_content: { @@ -128,12 +128,12 @@ module.exports = function(grunt) { } }, files: { - "tmp/process_content.js": ["test/fixtures/indent_template.html"] + 'tmp/process_content.js': ['test/fixtures/indent_template.html'] } }, local_scope: { files: { - "tmp/local_scope.js": ["test/fixtures/template_local_scope.html"] + 'tmp/local_scope.js': ['test/fixtures/template_local_scope.html'] } } }, diff --git a/README.md b/README.md index bf0ed27..60d50eb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# grunt-contrib-jst v1.0.0 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-jst.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-jst) +# grunt-contrib-jst v1.0.0 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-jst.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-jst) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/mxt7687c8r7bn7ab/branch/master?svg=true)](https://ci.appveyor.com/project/gruntjs/grunt-contrib-jst/branch/master) > Precompile Underscore templates to JST file @@ -67,11 +67,11 @@ jst: { compile: { options: { templateSettings: { - interpolate : /\{\{(.+?)\}\}/g + interpolate: /\{\{(.+?)\}\}/g } }, files: { - "path/to/compiled/templates.js": ["path/to/source/**/*.html"] + 'path/to/compiled/templates.js': ['path/to/source/**/*.html'] } } } @@ -99,8 +99,8 @@ Wraps the output file with an AMD define function and returns the compiled templ ```js define(function() { - //...// - return this['[template namespace]']; + //...// + return this['[template namespace]']; }); ``` @@ -134,11 +134,11 @@ jst: { compile: { options: { templateSettings: { - interpolate : /\{\{(.+?)\}\}/g + interpolate: /\{\{(.+?)\}\}/g } }, files: { - "path/to/compiled/templates.js": ["path/to/source/**/*.html"] + 'path/to/compiled/templates.js': ['path/to/source/**/*.html'] } } } @@ -166,4 +166,4 @@ Note that the `interpolate: /\{\{(.+?)\}\}/g` setting above is simply an example Task submitted by [Tim Branyen](http://tbranyen.com) -*This file was generated on Fri Mar 04 2016 17:18:07.* +*This file was generated on Thu Apr 14 2016 09:40:42.* diff --git a/docs/jst-examples.md b/docs/jst-examples.md index cf6fa0b..16d175d 100644 --- a/docs/jst-examples.md +++ b/docs/jst-examples.md @@ -5,11 +5,11 @@ jst: { compile: { options: { templateSettings: { - interpolate : /\{\{(.+?)\}\}/g + interpolate: /\{\{(.+?)\}\}/g } }, files: { - "path/to/compiled/templates.js": ["path/to/source/**/*.html"] + 'path/to/compiled/templates.js': ['path/to/source/**/*.html'] } } } diff --git a/docs/jst-options.md b/docs/jst-options.md index f6a3e8a..a176b3d 100644 --- a/docs/jst-options.md +++ b/docs/jst-options.md @@ -37,11 +37,11 @@ jst: { compile: { options: { templateSettings: { - interpolate : /\{\{(.+?)\}\}/g + interpolate: /\{\{(.+?)\}\}/g } }, files: { - "path/to/compiled/templates.js": ["path/to/source/**/*.html"] + 'path/to/compiled/templates.js': ['path/to/source/**/*.html'] } } } @@ -69,8 +69,8 @@ Wraps the output file with an AMD define function and returns the compiled templ ```js define(function() { - //...// - return this['[template namespace]']; + //...// + return this['[template namespace]']; }); ``` diff --git a/tasks/jst.js b/tasks/jst.js index 2306d82..2d1ff74 100644 --- a/tasks/jst.js +++ b/tasks/jst.js @@ -7,6 +7,7 @@ */ 'use strict'; + var _ = require('lodash'); var chalk = require('chalk'); @@ -73,16 +74,16 @@ module.exports = function(grunt) { if (options.amd) { if (options.prettify) { output.forEach(function(line, index) { - output[index] = " " + line; + output[index] = ' ' + line; }); } - output.unshift("define(function(){"); + output.unshift('define(function(){'); if (options.namespace !== false) { // Namespace has not been explicitly set to false; the AMD // wrapper will return the object containing the template. - output.push(" return " + nsInfo.namespace + ";"); + output.push(' return ' + nsInfo.namespace + ';'); } - output.push("});"); + output.push('});'); } grunt.file.write(f.dest, output.join(grunt.util.normalizelf(options.separator))); grunt.log.writeln('File ' + chalk.cyan(f.dest) + ' created.'); diff --git a/tasks/lib/jst.js b/tasks/lib/jst.js index 8b6df2e..7921cb1 100644 --- a/tasks/lib/jst.js +++ b/tasks/lib/jst.js @@ -1,9 +1,11 @@ +'use strict'; + exports.getNamespaceDeclaration = function(ns) { var output = []; var curPath = 'this'; if (ns !== 'this') { var nsParts = ns.split('.'); - nsParts.forEach(function(curPart, index) { + nsParts.forEach(function(curPart) { if (curPart !== 'this') { curPath += '[' + JSON.stringify(curPart) + ']'; output.push(curPath + ' = ' + curPath + ' || {};'); diff --git a/test/jst_test.js b/test/jst_test.js index 390e0c0..1abad6b 100644 --- a/test/jst_test.js +++ b/test/jst_test.js @@ -1,52 +1,53 @@ +'use strict'; + var grunt = require('grunt'); -exports['jst'] = { +exports.jst = { main: function(test) { - 'use strict'; var expect, result; test.expect(10); - expect = grunt.file.read("test/expected/jst.js"); - result = grunt.file.read("tmp/jst.js"); - test.equal(expect, result, "should compile underscore templates into JST"); + expect = grunt.file.read('test/expected/jst.js'); + result = grunt.file.read('tmp/jst.js'); + test.equal(expect, result, 'should compile underscore templates into JST'); - expect = grunt.file.read("test/expected/uglyfile.js"); - result = grunt.file.read("tmp/uglyfile.js"); - test.equal(expect, result, "should escape single quotes in filenames"); + expect = grunt.file.read('test/expected/uglyfile.js'); + result = grunt.file.read('tmp/uglyfile.js'); + test.equal(expect, result, 'should escape single quotes in filenames'); - expect = grunt.file.read("test/expected/ns_nested.js"); - result = grunt.file.read("tmp/ns_nested.js"); - test.equal(expect, result, "should define parts of nested namespaces"); + expect = grunt.file.read('test/expected/ns_nested.js'); + result = grunt.file.read('tmp/ns_nested.js'); + test.equal(expect, result, 'should define parts of nested namespaces'); - expect = grunt.file.read("test/expected/ns_nested.js"); // same as previous test - result = grunt.file.read("tmp/ns_nested_this.js"); - test.equal(expect, result, "should define parts of nested namespaces, ignoring this."); + expect = grunt.file.read('test/expected/ns_nested.js'); // same as previous test + result = grunt.file.read('tmp/ns_nested_this.js'); + test.equal(expect, result, 'should define parts of nested namespaces, ignoring this.'); - expect = grunt.file.read("test/expected/pretty.js"); - result = grunt.file.read("tmp/pretty.js"); - test.equal(expect, result, "should make the output be 1 line per template, making the output less ugly"); + expect = grunt.file.read('test/expected/pretty.js'); + result = grunt.file.read('tmp/pretty.js'); + test.equal(expect, result, 'should make the output be 1 line per template, making the output less ugly'); - expect = grunt.file.read("test/expected/amd_wrapper.js"); - result = grunt.file.read("tmp/amd_wrapper.js"); - test.equal(expect, result, "should wrap the template with define for AMD pattern"); + expect = grunt.file.read('test/expected/amd_wrapper.js'); + result = grunt.file.read('tmp/amd_wrapper.js'); + test.equal(expect, result, 'should wrap the template with define for AMD pattern'); - expect = grunt.file.read("test/expected/amd_wrapper_no_ns.js"); - result = grunt.file.read("tmp/amd_wrapper_no_ns.js"); - test.equal(expect, result, "should wrap the template with define for AMD pattern and return the function itself with no namespace"); + expect = grunt.file.read('test/expected/amd_wrapper_no_ns.js'); + result = grunt.file.read('tmp/amd_wrapper_no_ns.js'); + test.equal(expect, result, 'should wrap the template with define for AMD pattern and return the function itself with no namespace'); - expect = grunt.file.read("test/expected/pretty_amd.js"); - result = grunt.file.read("tmp/pretty_amd.js"); - test.equal(expect, result, "should make the AMD wrapper output pretty"); + expect = grunt.file.read('test/expected/pretty_amd.js'); + result = grunt.file.read('tmp/pretty_amd.js'); + test.equal(expect, result, 'should make the AMD wrapper output pretty'); - expect = grunt.file.read("test/expected/process_content.js"); - result = grunt.file.read("tmp/process_content.js"); - test.equal(expect, result, "should convert file content"); + expect = grunt.file.read('test/expected/process_content.js'); + result = grunt.file.read('tmp/process_content.js'); + test.equal(expect, result, 'should convert file content'); - expect = grunt.file.read("test/expected/local_scope.js"); - result = grunt.file.read("tmp/local_scope.js"); - test.equal(expect, result, "should add `with` block when templateSettings.variable is undefined"); + expect = grunt.file.read('test/expected/local_scope.js'); + result = grunt.file.read('tmp/local_scope.js'); + test.equal(expect, result, 'should add `with` block when templateSettings.variable is undefined'); test.done(); }