Skip to content
This repository has been archived by the owner on Nov 21, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/0.2.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Solazzi committed Mar 17, 2015
2 parents 6060bd4 + 16a0734 commit 3fa071b
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
node_modules
npm-debug.log
tmp
32 changes: 16 additions & 16 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ module.exports = function(grunt) {
all: [
'Gruntfile.js',
'tasks/*.js',
'<%= nodeunit.tests %>',
'<%= nodeunit.tests %>'
],
options: {
jshintrc: '.jshintrc',
},
jshintrc: '.jshintrc'
}
},

// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp'],
tests: ['tmp']
},

// Configuration to be run (and then tested).
Expand All @@ -39,22 +39,22 @@ module.exports = function(grunt) {
options: {
},
files: {
'tmp/email.html': ['<%= paths.fixtures %>/email.html'],
},
'tmp/email.html': ['<%= paths.fixtures %>/email.html']
}
},
multiple: {
files: {
'tmp/email.html': ['<%= paths.fixtures %>/inexistant.html', '<%= paths.fixtures %>/email.html', '<%= paths.fixtures %>/email-not-tobe-included.html'],
'tmp/email-2.html': ['<%= paths.fixtures %>/email-2.html']
},
}
},
txt: {
options: {
mode: 'txt'
},
files: {
'tmp/email.txt': ['<%= paths.fixtures %>/email.html'],
},
'tmp/email.txt': ['<%= paths.fixtures %>/email.html']
}
},
full: {
options: {
Expand All @@ -67,13 +67,13 @@ module.exports = function(grunt) {
verbose: true
},
files: {
'tmp/email-full.html': ['<%= paths.fixtures %>/email-full.html'],
},
'tmp/email-full.html': ['<%= paths.fixtures %>/email-full.html']
}
},

verbose: {
files: {
'tmp/email-verbose.html': ['<%= paths.fixtures %>/email-verbose.html'],
'tmp/email-verbose.html': ['<%= paths.fixtures %>/email-verbose.html']
}
},

Expand All @@ -82,21 +82,21 @@ module.exports = function(grunt) {
css: ['<%= paths.fixtures %>/css/external-mq.css']
},
files: {
'tmp/email-mq.html': ['<%= paths.fixtures %>/email-mq.html'],
'tmp/email-mq.html': ['<%= paths.fixtures %>/email-mq.html']
}
},

overwrite: {
files: {
'<%= paths.fixtures %>/email-overwrite.html': ['<%= paths.fixtures %>/email-overwrite.html'],
'<%= paths.fixtures %>/email-overwrite.html': ['<%= paths.fixtures %>/email-overwrite.html']
}
}
},

// Unit tests.
nodeunit: {
tests: ['test/*_test.js'],
},
tests: ['test/*_test.js']
}

});

Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ Default value: `false`

Removes HTML comments.

#### options.removeIds
Type: `Boolean`
Default value: `false`

Removes HTML ids.


#### options.preserveStyles
Type: `Boolean`
Expand All @@ -121,6 +127,12 @@ Default value: `false`

Prints additional information at runtime.

#### options.warnLevel
Type: `String`
Default value: `'safe'`

What level of CSS compatibility warnings to show (either `'none'`, `'safe'`, `'poor'`, `'risky'`).

### Usage Examples

#### Default Options
Expand Down Expand Up @@ -169,6 +181,8 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.

## Release History

0.2.13 Added option `warnLevel` and `removeIds`

0.2.12 Dependencies updated. Fixing a bug when source and destination files are the same (#25)

0.2.11 Fixing EventEmitter error (#21)
Expand Down
21 changes: 20 additions & 1 deletion lib/premailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
:remove_comments => false,
:verbose => false,
:line_length => 65,
:preserve_styles => false
:preserve_styles => false,
:escape_url_attributes => true,
:replace_html_entities => false,
:remove_ids => false
}

file_in = nil
Expand Down Expand Up @@ -56,6 +59,10 @@
options[:remove_classes] = v
end

opts.on("--remove-ids", "Remove HTML ids") do |v|
options[:remove_ids] = v
end

opts.on("-j", "--remove-scripts", "Remove HTML scripts") do |v|
options[:remove_scripts] = v
end
Expand All @@ -76,6 +83,18 @@
options[:verbose] = v
end

opts.on("--warn-level N", Integer, "Warning level") do |v|
options[:warn_level] = v
end

opts.on("--replace-html-entities", "Replace HTML entities") do |v|
options[:replace_html_entities] = v
end

opts.on("--escape-url-attributes", "Replace HTML entities") do |v|
options[:escape_url_attributes] = v
end

opts.on("--file-in STRING", String, "Input filename") do |v|
file_in = v
end
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-premailer",
"description": "Grunt wrapper task for premailer",
"version": "0.2.12",
"version": "0.2.13",
"homepage": "https://github.com/dwightjack/grunt-premailer",
"author": {
"name": "Marco Solazzi",
Expand Down Expand Up @@ -46,7 +46,7 @@
"chalk": "~1.0.0",
"dargs": "~4.0.0",
"is-utf8": "^0.2.0",
"lodash": "~3.3.1",
"lodash": "~3.5.0",
"semver": "~4.3.1"
}
}
23 changes: 19 additions & 4 deletions tasks/premailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ module.exports = function(grunt) {
fs = require('fs'),
async = require('async'),
isUtf8 = require('is-utf8'),
_ = require('lodash');
_ = require('lodash'),
warnLevels;

warnLevels = {
none: 0,
safe: 1,
poor: 2,
risky: 3
};

grunt.registerMultiTask('premailer', 'Grunt wrapper task for premailer', function() {
// Merge task-specific and/or target-specific options with these defaults.
Expand All @@ -34,10 +42,13 @@ module.exports = function(grunt) {
lineLength: 65,
ioException: false,
verbose: false,
mode: 'html'
mode: 'html',
warnLevel: 'safe',
removeIds: false,
replaceHtmlEntities: false,
escapeUrlAttributes: true
});


var keys = Object.keys(options);

// Remove bundleExec from arguments
Expand All @@ -50,11 +61,15 @@ module.exports = function(grunt) {
if (typeof val === 'string') {
val = grunt.template.process(val);
}
if ((typeof val === 'object' && !_.isEmpty(val)) || (typeof val !== 'object' && !! val)) {
//warn level could be 0, preserve it
if ((typeof val === 'object' && !_.isEmpty(val)) || (typeof val !== 'object' && !!val)) {
args[key] = val;
}
});

//convert warn level
args.warnLevel = _.has(warnLevels, args.warnLevel) ? warnLevels[args.warnLevel] : 0;

//also manage properly the css option
if (_.has(args, 'css') && Array.isArray(args.css)) {
args.css = _(args.css)
Expand Down
2 changes: 1 addition & 1 deletion test/premailer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ exports.premailer = {
test.ok(actual.indexOf('<body style="color: red') !== -1, 'Content is preserved.');

test.done();
},
}
};

0 comments on commit 3fa071b

Please sign in to comment.