premailer 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/premailer +21 -22
- data/lib/premailer.rb +2 -2
- data/lib/premailer/premailer.rb +9 -8
- metadata +3 -3
data/bin/premailer
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'rubygems'
|
5
|
-
require 'premailer'
|
6
|
-
require 'fcntl'
|
5
|
+
require File.expand_path(File.join(__FILE__) + '/../../lib/premailer.rb')
|
7
6
|
|
8
7
|
# defaults
|
9
8
|
options = {
|
@@ -17,8 +16,8 @@ options = {
|
|
17
16
|
mode = :html
|
18
17
|
|
19
18
|
opts = OptionParser.new do |opts|
|
20
|
-
opts.banner = "Improve the rendering of HTML emails by making CSS inline,
|
21
|
-
opts.define_head "Usage: premailer <uri|path> [options]"
|
19
|
+
opts.banner = "Improve the rendering of HTML emails by making CSS inline among other things. Takes a path to a local file, a URL or a pipe as input.\n\n"
|
20
|
+
opts.define_head "Usage: premailer <optional uri|optional path> [options]"
|
22
21
|
opts.separator ""
|
23
22
|
opts.separator "Examples:"
|
24
23
|
opts.separator " premailer http://example.com/ > out.html"
|
@@ -28,15 +27,15 @@ opts = OptionParser.new do |opts|
|
|
28
27
|
opts.separator ""
|
29
28
|
opts.separator "Options:"
|
30
29
|
|
31
|
-
opts.on("--mode
|
30
|
+
opts.on("--mode MODE", [:html, :txt], "Output: html or txt") do |v|
|
32
31
|
mode = v
|
33
32
|
end
|
34
33
|
|
35
|
-
opts.on("-b", "--base-url", String, "
|
34
|
+
opts.on("-b", "--base-url", String, "Base URL, useful for local files") do |v|
|
36
35
|
options[:base_url] = v
|
37
36
|
end
|
38
37
|
|
39
|
-
opts.on("-q", "--query-string STRING", String, "Query string to append to links
|
38
|
+
opts.on("-q", "--query-string STRING", String, "Query string to append to links") do |v|
|
40
39
|
options[:link_query_string] = v
|
41
40
|
end
|
42
41
|
|
@@ -44,11 +43,11 @@ opts = OptionParser.new do |opts|
|
|
44
43
|
options[:css] = v
|
45
44
|
end
|
46
45
|
|
47
|
-
opts.on("-r", "--remove-classes", "Remove
|
46
|
+
opts.on("-r", "--remove-classes", "Remove HTML classes") do |v|
|
48
47
|
options[:remove_classes] = v
|
49
48
|
end
|
50
49
|
|
51
|
-
opts.on("-l", "--line-length N", Integer, "
|
50
|
+
opts.on("-l", "--line-length N", Integer, "Line length for plaintext (default: #{options[:line_length].to_s})") do |v|
|
52
51
|
options[:line_length] = v
|
53
52
|
end
|
54
53
|
|
@@ -75,26 +74,26 @@ opts.parse!
|
|
75
74
|
$stderr.puts "Processing in #{mode} mode with options #{options.inspect}" if options[:verbose]
|
76
75
|
|
77
76
|
premailer = nil
|
77
|
+
input = nil
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
io = STDIN.to_io
|
82
|
-
premailer = Premailer.new(io, options)
|
79
|
+
if $stdin.tty?
|
80
|
+
input = ARGV.shift
|
83
81
|
else
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
puts opts
|
88
|
-
exit 1
|
89
|
-
end
|
82
|
+
input = $stdin
|
83
|
+
options[:with_html_string] = true
|
84
|
+
end
|
90
85
|
|
91
|
-
|
86
|
+
if input
|
87
|
+
premailer = Premailer.new(input, options)
|
88
|
+
else
|
89
|
+
puts opts
|
90
|
+
exit 1
|
92
91
|
end
|
93
92
|
|
94
93
|
if mode == :txt
|
95
|
-
|
94
|
+
print premailer.to_plain_text
|
96
95
|
else
|
97
|
-
|
96
|
+
print premailer.to_inline_css
|
98
97
|
end
|
99
98
|
|
100
99
|
exit
|
data/lib/premailer.rb
CHANGED
@@ -3,5 +3,5 @@ require 'open-uri'
|
|
3
3
|
require 'cgi'
|
4
4
|
require 'hpricot'
|
5
5
|
require 'css_parser'
|
6
|
-
require 'premailer/html_to_plain_text'
|
7
|
-
require 'premailer/premailer'
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + '/premailer/html_to_plain_text')
|
7
|
+
require File.expand_path(File.dirname(__FILE__) + '/premailer/premailer')
|
data/lib/premailer/premailer.rb
CHANGED
@@ -33,7 +33,7 @@ class Premailer
|
|
33
33
|
include HtmlToPlainText
|
34
34
|
include CssParser
|
35
35
|
|
36
|
-
VERSION = '1.6.
|
36
|
+
VERSION = '1.6.2'
|
37
37
|
|
38
38
|
CLIENT_SUPPORT_FILE = File.dirname(__FILE__) + '/../../misc/client_support.yaml'
|
39
39
|
|
@@ -287,7 +287,8 @@ protected
|
|
287
287
|
else
|
288
288
|
thing = open(input)
|
289
289
|
end
|
290
|
-
|
290
|
+
|
291
|
+
# TODO: deal with Hpricot seg faults on empty input
|
291
292
|
thing ? Hpricot(thing) : nil
|
292
293
|
end
|
293
294
|
|
@@ -369,7 +370,7 @@ protected
|
|
369
370
|
def append_query_string(doc, qs)
|
370
371
|
return doc if qs.nil?
|
371
372
|
|
372
|
-
qs.to_s.strip!
|
373
|
+
qs.to_s.gsub!(/^[\?]*/, '').strip!
|
373
374
|
return doc if qs.empty?
|
374
375
|
|
375
376
|
begin
|
@@ -382,8 +383,8 @@ protected
|
|
382
383
|
|
383
384
|
doc.search('a').each do|el|
|
384
385
|
href = el.attributes['href'].to_s.strip
|
385
|
-
next if href.nil? or href.empty?
|
386
|
-
next if href[0] == '#' # don't bother with anchors
|
386
|
+
next if href.nil? or href.empty?
|
387
|
+
next if href[0,1] == '#' # don't bother with anchors
|
387
388
|
|
388
389
|
begin
|
389
390
|
href = URI.parse(href)
|
@@ -397,11 +398,11 @@ protected
|
|
397
398
|
puts "Skipping append_query_string for: #{href.to_s} because scheme is no good" if @options[:verbose]
|
398
399
|
next
|
399
400
|
end
|
400
|
-
|
401
|
-
if href.query
|
401
|
+
|
402
|
+
if href.query and not href.query.empty?
|
402
403
|
href.query = href.query + '&' + qs
|
403
404
|
else
|
404
|
-
href.query =
|
405
|
+
href.query = qs
|
405
406
|
end
|
406
407
|
|
407
408
|
el['href'] = href.to_s
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 1.6.
|
8
|
+
- 2
|
9
|
+
version: 1.6.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Alex Dunae
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-22 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|