From 807bf6d7e0814f563886e52940c41b5ceac87755 Mon Sep 17 00:00:00 2001 From: Marco Solazzi Date: Tue, 17 Mar 2015 10:06:06 +0100 Subject: [PATCH 1/2] added options --- .gitignore | 1 + lib/premailer.rb | 21 ++++++++++++++++++++- tasks/premailer.js | 20 ++++++++++++++++---- test/premailer_test.js | 2 +- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index b785247..7cbf173 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea node_modules npm-debug.log tmp diff --git a/lib/premailer.rb b/lib/premailer.rb index 4f6bb45..ef761dc 100644 --- a/lib/premailer.rb +++ b/lib/premailer.rb @@ -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 @@ -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 @@ -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 diff --git a/tasks/premailer.js b/tasks/premailer.js index 6e60dfd..bde82b2 100644 --- a/tasks/premailer.js +++ b/tasks/premailer.js @@ -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. @@ -34,10 +42,13 @@ module.exports = function(grunt) { lineLength: 65, ioException: false, verbose: false, - mode: 'html' + mode: 'html', + warnLevel: warnLevels.none, + removeIds: false, + replaceHtmlEntities: false, + escapeUrlAttributes: true }); - var keys = Object.keys(options); // Remove bundleExec from arguments @@ -50,7 +61,8 @@ 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 (key === 'warnLevel' || (typeof val === 'object' && !_.isEmpty(val)) || (typeof val !== 'object' && !!val)) { args[key] = val; } }); diff --git a/test/premailer_test.js b/test/premailer_test.js index 3e13e1a..b7cd318 100644 --- a/test/premailer_test.js +++ b/test/premailer_test.js @@ -105,5 +105,5 @@ exports.premailer = { test.ok(actual.indexOf('