premailer 1.10.4 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b5558b61431fcbad3d7fe4136960b75e8cecec6
4
- data.tar.gz: bd3c0941de04600fae48c0e2d7d2104a676fb0a6
3
+ metadata.gz: c1f0cb88ede5d92fb777b596973cb59c69bd02e0
4
+ data.tar.gz: cb84c900b1160ca8f8c91d3ad74bcd9023dc7c79
5
5
  SHA512:
6
- metadata.gz: 2a62d80a9238c76cfed3b1ad398c98221e6ece39a289d4b9435862f2c0191cba8ac7461590cdc8406e3eecb765d2c96faa51bc00158edd6abdee2baee76d041e
7
- data.tar.gz: 5533bcce2a737c63f4ee3ded37d3f765739925bf89739955e068f3e79889a1e5e02ffbe6dffd13ec7f733e00c3b9d5feaba6205bf95c542cfe4e11989c253a6c
6
+ metadata.gz: f50e404b63d17ae55256615118585baf7eabf443dd56d634ad06ae4a83cc258c6a9b2dd647184f23d03b51decbc0770910f3e886aa558c4cd57fd0950102e1c1
7
+ data.tar.gz: 0aab4b4d34f52a0e81a3176e3f9508d2637f1a0fb57b0a76efcfbf6f7a24cfbebb80037605cabb8fdea8de87e27f44f69b33c2ba298e816abf68c5220539947f
@@ -149,11 +149,17 @@ class Premailer
149
149
  def write_unmergable_css_rules(doc, unmergable_rules) # :nodoc:
150
150
  styles = unmergable_rules.to_s
151
151
  unless styles.empty?
152
- style_tag = doc.create_element "style", "#{styles}"
153
- head = doc.at_css('head')
154
- head ||= doc.root.first_element_child.add_previous_sibling(doc.create_element "head") if doc.root && doc.root.first_element_child
155
- head ||= doc.add_child(doc.create_element "head")
156
- head << style_tag
152
+ if @options[:html_fragment]
153
+ style_tag = ::Nokogiri::XML::Node.new("style", doc)
154
+ style_tag.content = styles
155
+ doc.add_child(style_tag)
156
+ else
157
+ style_tag = doc.create_element "style", "#{styles}"
158
+ head = doc.at_css('head')
159
+ head ||= doc.root.first_element_child.add_previous_sibling(doc.create_element "head") if doc.root && doc.root.first_element_child
160
+ head ||= doc.add_child(doc.create_element "head")
161
+ head << style_tag
162
+ end
157
163
  end
158
164
  doc
159
165
  end
@@ -216,12 +222,16 @@ class Premailer
216
222
  end
217
223
  # Default encoding is ASCII-8BIT (binary) per http://groups.google.com/group/nokogiri-talk/msg/0b81ef0dc180dc74
218
224
  # However, we really don't want to hardcode this. ASCII-8BIT should be the default, but not the only option.
219
- if thing.is_a?(String) and RUBY_VERSION =~ /1.9/
225
+ encoding = if thing.is_a?(String) and RUBY_VERSION =~ /1.9/
220
226
  thing = thing.force_encoding(@options[:input_encoding]).encode!
221
- doc = ::Nokogiri::HTML(thing, nil, @options[:input_encoding]) { |c| c.recover }
227
+ @options[:input_encoding]
228
+ else
229
+ @options[:input_encoding] || RUBY_PLATFORM == 'java' ? nil : 'BINARY'
230
+ end
231
+ doc = if @options[:html_fragment]
232
+ ::Nokogiri::HTML.fragment(thing, encoding)
222
233
  else
223
- default_encoding = RUBY_PLATFORM == 'java' ? nil : 'BINARY'
224
- doc = ::Nokogiri::HTML(thing, nil, @options[:input_encoding] || default_encoding) { |c| c.recover }
234
+ ::Nokogiri::HTML(thing, nil, encoding) { |c| c.recover }
225
235
  end
226
236
 
227
237
  # Fix for removing any CDATA tags from both style and script tags inserted per
@@ -150,12 +150,19 @@ class Premailer
150
150
  # @return [::Nokogiri::XML] a document.
151
151
  def write_unmergable_css_rules(doc, unmergable_rules) # :nodoc:
152
152
  styles = unmergable_rules.to_s
153
- return doc if styles.empty?
154
- style_tag = doc.create_element "style", styles
155
- head = doc.at_css('head')
156
- head ||= doc.root.first_element_child.add_previous_sibling(doc.create_element "head") if doc.root && doc.root.first_element_child
157
- head ||= doc.add_child(doc.create_element "head")
158
- head << style_tag
153
+ unless styles.empty?
154
+ if @options[:html_fragment]
155
+ style_tag = ::Nokogiri::XML::Node.new("style", doc)
156
+ style_tag.content = styles
157
+ doc.add_child(style_tag)
158
+ else
159
+ style_tag = doc.create_element "style", styles
160
+ head = doc.at_css('head')
161
+ head ||= doc.root.first_element_child.add_previous_sibling(doc.create_element "head") if doc.root && doc.root.first_element_child
162
+ head ||= doc.add_child(doc.create_element "head")
163
+ head << style_tag
164
+ end
165
+ end
159
166
  doc
160
167
  end
161
168
 
@@ -217,12 +224,16 @@ class Premailer
217
224
  end
218
225
  # Default encoding is ASCII-8BIT (binary) per http://groups.google.com/group/nokogiri-talk/msg/0b81ef0dc180dc74
219
226
  # However, we really don't want to hardcode this. ASCII-8BIT should be the default, but not the only option.
220
- if thing.is_a?(String) and RUBY_VERSION =~ /1.9/
227
+ encoding = if thing.is_a?(String) and RUBY_VERSION =~ /1.9/
221
228
  thing = thing.force_encoding(@options[:input_encoding]).encode!
222
- doc = ::Nokogiri::HTML(thing, nil, @options[:input_encoding]) { |c| c.recover }
229
+ @options[:input_encoding]
230
+ else
231
+ @options[:input_encoding] || RUBY_PLATFORM == 'java' ? nil : 'BINARY'
232
+ end
233
+ doc = if @options[:html_fragment]
234
+ ::Nokogiri::HTML.fragment(thing, encoding)
223
235
  else
224
- default_encoding = RUBY_PLATFORM == 'java' ? nil : 'BINARY'
225
- doc = ::Nokogiri::HTML(thing, nil, @options[:input_encoding] || default_encoding) { |c| c.recover }
236
+ ::Nokogiri::HTML(thing, nil, encoding) { |c| c.recover }
226
237
  end
227
238
 
228
239
  # Fix for removing any CDATA tags from both style and script tags inserted per
@@ -148,12 +148,19 @@ class Premailer
148
148
  # @return [::Nokogiri::XML] a document.
149
149
  def write_unmergable_css_rules(doc, unmergable_rules) # :nodoc:
150
150
  styles = unmergable_rules.to_s
151
- return doc if styles.empty?
152
- style_tag = doc.create_element "style", styles
153
- head = doc.at_css('head')
154
- head ||= doc.root.first_element_child.add_previous_sibling(doc.create_element "head") if doc.root && doc.root.first_element_child
155
- head ||= doc.add_child(doc.create_element "head")
156
- head << style_tag
151
+ unless styles.empty?
152
+ if @options[:html_fragment]
153
+ style_tag = ::Nokogiri::XML::Node.new("style", doc)
154
+ style_tag.content = styles
155
+ doc.add_child(style_tag)
156
+ else
157
+ style_tag = doc.create_element "style", styles
158
+ head = doc.at_css('head')
159
+ head ||= doc.root.first_element_child.add_previous_sibling(doc.create_element "head") if doc.root && doc.root.first_element_child
160
+ head ||= doc.add_child(doc.create_element "head")
161
+ head << style_tag
162
+ end
163
+ end
157
164
  doc
158
165
  end
159
166
 
@@ -217,10 +224,11 @@ class Premailer
217
224
  # However, we really don't want to hardcode this. ASCII-8BIT should be the default, but not the only option.
218
225
  if thing.is_a?(String) and RUBY_VERSION =~ /1.9/
219
226
  thing = thing.force_encoding(@options[:input_encoding]).encode!
220
- doc = ::Nokogiri::HTML5(thing)
227
+ end
228
+ doc = if @options[:html_fragment]
229
+ ::Nokogiri::HTML5(thing)
221
230
  else
222
- default_encoding = RUBY_PLATFORM == 'java' ? nil : 'BINARY'
223
- doc = ::Nokogiri::HTML5(thing)
231
+ ::Nokogiri::HTML5.fragment(thing)
224
232
  end
225
233
 
226
234
  # Fix for removing any CDATA tags from both style and script tags inserted per
@@ -177,6 +177,7 @@ class Premailer
177
177
  # @option options [Symbol] :adapter Which HTML parser to use, <tt>:nokogiri</tt>, <tt>:nokogiri_fast</tt> or <tt>:nokogumbo</tt>. Default is <tt>:nokogiri</tt>.
178
178
  # @option options [String] :output_encoding Output encoding option for Nokogiri adapter. Should be set to "US-ASCII" to output HTML entities instead of Unicode characters.
179
179
  # @option options [Boolean] :create_shorthands Combine several properties into a shorthand one, e.g. font: style weight size. Default is true.
180
+ # @option options [Boolean] :html_fragment Handle HTML fragment without any HTML content wrappers. Default is false.
180
181
  def initialize(html, options = {})
181
182
  @options = {:warn_level => Warnings::SAFE,
182
183
  :line_length => 65,
@@ -206,6 +207,7 @@ class Premailer
206
207
  :escape_url_attributes => true,
207
208
  :unescaped_ampersand => false,
208
209
  :create_shorthands => true,
210
+ :html_fragment => false,
209
211
  :adapter => Adapter.use,
210
212
  }.merge(options)
211
213
 
@@ -1,4 +1,4 @@
1
1
  class Premailer
2
2
  # Premailer version.
3
- VERSION = '1.10.4'.freeze
3
+ VERSION = '1.11.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: premailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.4
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dunae
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-16 00:00:00.000000000 Z
11
+ date: 2017-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: css_parser
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.10
19
+ version: 1.6.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.4.10
26
+ version: 1.6.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: htmlentities
29
29
  requirement: !ruby/object:Gem::Requirement