premailer 1.7.8 → 1.7.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,15 +20,20 @@ I'm looking for input on a version 2.0 update to Premailer. PLease visit the [P
20
20
 
21
21
  ## Installation
22
22
 
23
- Download the Premailer gem from RubyGems.
23
+ Install the Premailer gem from RubyGems.
24
24
 
25
25
  ```bash
26
26
  gem install premailer
27
27
  ```
28
28
 
29
+ or add it to your `Gemfile` and run `bundle`.
30
+
29
31
  ## Example
30
32
 
31
33
  ```ruby
34
+ require 'rubygems' # optional for Ruby 1.9 or above.
35
+ require 'premailer'
36
+
32
37
  premailer = Premailer.new('http://example.com/myfile.html', :warn_level => Premailer::Warnings::SAFE)
33
38
 
34
39
  # Write the HTML output
@@ -61,6 +66,7 @@ Premailer looks for a few CSS attributes that make working with tables a bit eas
61
66
  | -premailer-height | Available on `table`, `tr`, `th` and `td` elements |
62
67
  | -premailer-cellpadding | Available on `table` elements |
63
68
  | -premailer-cellspacing | Available on `table` elements |
69
+ | data-premailer="ignore" | Available on `style` elements. Premailer will ignore these elements entirely. |
64
70
 
65
71
  Each of these CSS declarations will be copied to appropriate element's attribute.
66
72
 
@@ -30,6 +30,12 @@ class Premailer
30
30
  @unmergable_rules.add_rule_set!(CssParser::RuleSet.new(selector, declaration)) unless @options[:preserve_styles]
31
31
  else
32
32
  begin
33
+ if selector =~ Premailer::RE_RESET_SELECTORS
34
+ # this is in place to preserve the MailChimp CSS reset: http://github.com/mailchimp/Email-Blueprints/
35
+ # however, this doesn't mean for testing pur
36
+ @unmergable_rules.add_rule_set!(CssParser::RuleSet.new(selector, declaration)) unless !@options[:preserve_reset]
37
+ end
38
+
33
39
  # Change single ID CSS selectors into xpath so that we can match more
34
40
  # than one element. Added to work around dodgy generated code.
35
41
  selector.gsub!(/\A\#([\w_\-]+)\Z/, '*[@id=\1]')
@@ -131,7 +137,7 @@ class Premailer
131
137
  end
132
138
 
133
139
  unless styles.empty?
134
- style_tag = "<style type=\"text/css\">\n#{styles}></style>"
140
+ style_tag = "<style type=\"text/css\">\n#{styles}</style>"
135
141
  if head = doc.search('head')
136
142
  doc.at_css('head').add_child(::Nokogiri::XML.fragment(style_tag))
137
143
  elsif body = doc.search('body')
@@ -77,10 +77,10 @@ $stderr.puts "Processing in #{mode} mode with options #{options.inspect}" if opt
77
77
  premailer = nil
78
78
  input = nil
79
79
 
80
- if $stdin.tty? or STDIN.fcntl(Fcntl::F_GETFL, 0) == 0
80
+ if $stdin.tty?
81
81
  input = ARGV.shift
82
82
  else
83
- input = $stdin
83
+ input = $stdin.read
84
84
  options[:with_html_string] = true
85
85
  end
86
86
 
@@ -10,10 +10,6 @@ module HtmlToPlainText
10
10
  def convert_to_text(html, line_length = 65, from_charset = 'UTF-8')
11
11
  txt = html
12
12
 
13
- # decode HTML entities
14
- he = HTMLEntities.new
15
- txt = he.decode(txt)
16
-
17
13
  # replace images with their alt attributes
18
14
  # for img tags with "" for attribute quotes
19
15
  # with or without closing tag
@@ -46,7 +42,6 @@ module HtmlToPlainText
46
42
  end
47
43
  end
48
44
 
49
-
50
45
  # handle headings (H1-H6)
51
46
  txt.gsub!(/(<\/h[1-6]>)/i, "\n\\1") # move closing tags to new lines
52
47
  txt.gsub!(/[\s]*<h([1-6]+)[^>]*>[\s]*(.*)[\s]*<\/h[1-6]+>/i) do |s|
@@ -88,6 +83,10 @@ module HtmlToPlainText
88
83
  # strip remaining tags
89
84
  txt.gsub!(/<\/?[^>]*>/, '')
90
85
 
86
+ # decode HTML entities
87
+ he = HTMLEntities.new
88
+ txt = he.decode(txt)
89
+
91
90
  txt = word_wrap(txt, line_length)
92
91
 
93
92
  # remove linefeeds (\r\n and \r -> \n)
@@ -1,4 +1,4 @@
1
1
  class Premailer
2
2
  # Premailer version.
3
- VERSION = '1.7.8'.freeze
3
+ VERSION = '1.7.9'.freeze
4
4
  end
data/rakefile.rb CHANGED
@@ -1,5 +1,3 @@
1
- $:.unshift File.expand_path('../lib', __FILE__)
2
-
3
1
  require 'rake'
4
2
  require 'rake/testtask'
5
3
  require "bundler/gem_tasks"
data/test/test_links.rb CHANGED
@@ -121,6 +121,18 @@ class TestLinks < Premailer::TestCase
121
121
  assert_equal 'http://example.com/path', Premailer.resolve_link(' path', base_uri)
122
122
  end
123
123
 
124
+ def test_resolving_urls_from_html_string
125
+ # The inner URI is on its own line to ensure that the impl doesn't match
126
+ # URIs based on start of line.
127
+ base_uri = "<html><head></head><body>\nhttp://example.com/\n</body>"
128
+ ['test.html', '/test.html', './test.html',
129
+ 'test/../test.html', 'test/../test/../test.html'].each do |q|
130
+ assert_nothing_raised do
131
+ Premailer.resolve_link(q, base_uri)
132
+ end
133
+ end
134
+ end
135
+
124
136
  def test_resolving_urls_in_doc
125
137
  # force Nokogiri since this consistenly segfaults with Hpricot
126
138
  base_file = File.dirname(__FILE__) + '/files/base.html'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: premailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.8
4
+ version: 1.7.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-23 00:00:00.000000000 Z
12
+ date: 2013-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: css_parser