Skip to content

Commit

Permalink
Minor lint tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Apr 14, 2016
1 parent adb8c04 commit 806ddbe
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 70 deletions.
9 changes: 5 additions & 4 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -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
}
"unused": true
}
30 changes: 15 additions & 15 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -71,51 +71,51 @@ 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: {
options: {
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: {
options: {
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: {
options: {
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: {
Expand All @@ -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']
}
}
},
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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']
}
}
}
Expand Down Expand Up @@ -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]'];
});
```

Expand Down Expand Up @@ -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']
}
}
}
Expand Down Expand Up @@ -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.*
4 changes: 2 additions & 2 deletions docs/jst-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions docs/jst-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
}
}
Expand Down Expand Up @@ -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]'];
});
```

Expand Down
9 changes: 5 additions & 4 deletions tasks/jst.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

'use strict';

var _ = require('lodash');
var chalk = require('chalk');

Expand Down Expand Up @@ -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.');
Expand Down
4 changes: 3 additions & 1 deletion tasks/lib/jst.js
Original file line number Diff line number Diff line change
@@ -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 + ' || {};');
Expand Down
65 changes: 33 additions & 32 deletions test/jst_test.js
Original file line number Diff line number Diff line change
@@ -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();
}
Expand Down

0 comments on commit 806ddbe

Please sign in to comment.