Skip to content

Instantly share code, notes, and snippets.

@tenodi
Last active October 10, 2015 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenodi/652f1383eeb6e27ccb9b to your computer and use it in GitHub Desktop.
Save tenodi/652f1383eeb6e27ccb9b to your computer and use it in GitHub Desktop.
Using html-minifier customAttrSurround for allowing swig template
/**
* This is RegEx which is needed to be used if we want to catch something like:
<tr data-url="/beach"
{% if weather.isHot() %}
class="clickableRow"
{% endif %}
>
* Important notes:
* - We need \s* for catching all the whitespace before and after.
* - You can't make this for multiple attributes! In case you have multiple
* attributes, you need to make multiple if's too.
* - This is only RegEx for if-else. For blocks, swig values inside HTML
* elements, RegExs are not needed.
* - Multiple if's can be only separated by whitespace.
*/
var open = /\s*\{%\s*if\s.+?%\}\s*/;
var close = /\s*\{%\s*endif\s*%\}\s*/;
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
htmlmin: {
dev: {
options: {
removeComments: true,
collapseWhitespace: true,
customAttrSurround: [[open, close]]
},
files: [{
// define your files here
}]
}
}
});
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.registerTask('default', ['htmlmin']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment