premailer 1.6.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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, converting links and warning about unsupported code."
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 [MODE]", [:html, :txt], "Output type: either html or txt") do |v|
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, "Manually set the base URL, useful for local files") do |v|
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 (do not include the ?)") do |v|
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 classes from the HTML document?") do |v|
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, "Length of lines when creating plaintext version (default: #{options[:line_length].to_s})") do |v|
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
- # check for input from STDIN
80
- if STDIN.fcntl(Fcntl::F_GETFL, 0) == 0
81
- io = STDIN.to_io
82
- premailer = Premailer.new(io, options)
79
+ if $stdin.tty?
80
+ input = ARGV.shift
83
81
  else
84
- uri = ARGV.shift
85
-
86
- if uri.to_s.strip.empty?
87
- puts opts
88
- exit 1
89
- end
82
+ input = $stdin
83
+ options[:with_html_string] = true
84
+ end
90
85
 
91
- premailer = Premailer.new(uri, options)
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
- p premailer.to_plain_text
94
+ print premailer.to_plain_text
96
95
  else
97
- p premailer.to_inline_css
96
+ print premailer.to_inline_css
98
97
  end
99
98
 
100
99
  exit
@@ -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')
@@ -33,7 +33,7 @@ class Premailer
33
33
  include HtmlToPlainText
34
34
  include CssParser
35
35
 
36
- VERSION = '1.6.1'
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 + '&amp;' + qs
403
404
  else
404
- href.query = '?' + qs
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
- - 1
9
- version: 1.6.1
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-16 00:00:00 -08:00
17
+ date: 2010-11-22 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency