Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[*]
charset=utf-8
end_of_line=lf
insert_final_newline=false
indent_style=space
indent_size=2

[{.babelrc,.stylelintrc,.eslintrc,*.bowerrc,*.jsb3,*.jsb2,*.json}]
indent_style=space
indent_size=2

[{jshint.json,*.jshintrc}]
indent_style=space
indent_size=2

[{*.yml,*.yaml}]
indent_style=space
indent_size=2

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
npm-debug.log
tmp
grunt-angular-templates.iml
.idea
50 changes: 39 additions & 11 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@ module.exports = function(grunt) {
src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
dest: 'tmp/custom_htmlmin.js',
options: {
htmlmin: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
}
htmlmin: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
}
}
},

Expand Down Expand Up @@ -307,7 +307,9 @@ module.exports = function(grunt) {
options: {
merge: false
}
}
},


}
});

Expand Down Expand Up @@ -355,6 +357,32 @@ module.exports = function(grunt) {
grunt.task.run(tasks);
});

grunt.registerTask('throwsOnErrorForHtmlminTest', function() {
grunt.config.merge(
{
ngtemplates: {
throwsOnErrorForHtmlminTest: {
options: {
htmlminThrowOnError: true,
htmlmin: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
}
},
src: ['test/fixtures/htmlmin-throw-on-error.html'],
dest: 'tmp/htmlmin-throw-on-error.js'
}
}
});
grunt.task.run('ngtemplates:throwsOnErrorForHtmlminTest');
});

// Load local tasks.
grunt.loadTasks('tasks');
grunt.loadNpmTasks('grunt-contrib-clean');
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ htmlmin: {
}
```


###htmlminThrowOnError
Default: ```false```

> If you set it to ```true```, it will throw an error. It is good for a build.


### module

> `String` of the `angular.module` to register templates with.
Expand Down
4 changes: 3 additions & 1 deletion tasks/angular-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ module.exports = function(grunt) {
usemin: null,
append: false,
quotes: 'double',
merge: true
merge: true,
htmlminThrowOnError: false,
});


grunt.verbose.writeflags(options, 'Options');

this.files.forEach(function(file) {
Expand Down
3 changes: 3 additions & 0 deletions tasks/lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ var Compiler = function(grunt, options, cwd, expanded) {
source = minify(source, options.htmlmin);
} catch (err) {
grunt.log.error(err + '\n\n' + source + '\n\n');
if (options.htmlminThrowOnError) {
throw err;
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/angular-templates_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,29 @@ exports.ngtemplates = {
test.equal(grunt.file.read('tmp/unmerged/test/fixtures/unmerged/level2/html5.js'), grunt.file.read('test/expected/unmerged_files/html5.js'));
test.equal(grunt.file.read('tmp/unmerged/test/fixtures/unmerged/level2/level3/one.js'), grunt.file.read('test/expected/unmerged_files/one.js'));
test.done();
},

throwsOnErrorForHtmlminTest: function (test) {
var findsError = 'Aborted due to warnings.';

var child = grunt.util.spawn({
cmd: 'grunt',
args: ['throwsOnErrorForHtmlminTest'],
}, function() {});

var result = '';
child.stdout.on('data', function (data) {
result += data;
});

child.stdout.on('end', function () {
// console.log(result);
if (result.indexOf(findsError) === -1) {
test.fail();
}
test.done();
});

}

};
2 changes: 2 additions & 0 deletions test/fixtures/htmlmin-throw-on-error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
this shows an error
<button