eyeliner 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  class Eyeliner
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/eyeliner.rb CHANGED
@@ -65,17 +65,21 @@ class Eyeliner
65
65
 
66
66
  def extract_stylesheets
67
67
  @doc.css("style, link[rel=stylesheet][type='text/css']").each do |element|
68
- next if element["class"] && element["class"].split.member?("noinline")
68
+ next if has_class("noinline", element)
69
69
  case element.name
70
70
  when "style"
71
71
  @css << element.content
72
72
  when "link"
73
73
  @css << read_stylesheet(element["href"])
74
74
  end
75
- element.remove
75
+ element.remove unless has_class("retain", element)
76
76
  end
77
77
  end
78
78
 
79
+ def has_class(class_name, element)
80
+ element["class"] && element["class"].split.member?(class_name)
81
+ end
82
+
79
83
  def read_stylesheet(name)
80
84
  name_without_query = name.sub(%r{\?.*}, '')
81
85
  full_path = File.join(@eyeliner.stylesheet_base, name_without_query)
@@ -162,7 +162,7 @@ describe Eyeliner do
162
162
 
163
163
  end
164
164
 
165
- context "when the document contains a <style> block, classed noinline" do
165
+ context "when the document contains a <style> block, classed 'noinline'" do
166
166
 
167
167
  before do
168
168
  @input = <<-HTML
@@ -201,6 +201,44 @@ describe Eyeliner do
201
201
 
202
202
  end
203
203
 
204
+ context "when the document contains a <style> block, classed 'retain'" do
205
+
206
+ before do
207
+ @input = <<-HTML
208
+ <html>
209
+ <head>
210
+ <style class="retain">
211
+ strong { text-decoration: underline; }
212
+ </style>
213
+ </head>
214
+ <body>
215
+ <p>
216
+ Feeling <strong>STRONG</strong>.
217
+ </p>
218
+ </body>
219
+ </html>
220
+ HTML
221
+ end
222
+
223
+ describe "#apply_to" do
224
+
225
+ before do
226
+ @output = eyeliner.apply_to(@input)
227
+ @output_doc = Nokogiri::HTML.fragment(@output)
228
+ end
229
+
230
+ it "inlines the styles" do
231
+ strong_element = @output_doc.css("strong").first
232
+ strong_element["style"].should == "text-decoration: underline;"
233
+ end
234
+
235
+ it "does not remove the <style> element" do
236
+ @output_doc.css("style").should_not be_empty
237
+ end
238
+
239
+ end
240
+
241
+ end
204
242
 
205
243
  context "when the document contains a linked stylesheet" do
206
244
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eyeliner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-09-08 00:00:00.000000000Z
13
+ date: 2012-01-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
17
- requirement: &70147027952980 !ruby/object:Gem::Requirement
17
+ requirement: &70241861041100 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.4.4
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70147027952980
25
+ version_requirements: *70241861041100
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: css_parser
28
- requirement: &70147027951940 !ruby/object:Gem::Requirement
28
+ requirement: &70241861040600 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 1.1.9
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70147027951940
36
+ version_requirements: *70241861040600
37
37
  description:
38
38
  email:
39
39
  - mike@cogentconsulting.com.au
@@ -64,7 +64,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  segments:
66
66
  - 0
67
- hash: -140593005344463670
67
+ hash: -4128840240962595108
68
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  none: false
70
70
  requirements:
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  segments:
75
75
  - 0
76
- hash: -140593005344463670
76
+ hash: -4128840240962595108
77
77
  requirements: []
78
78
  rubyforge_project:
79
79
  rubygems_version: 1.8.10