css_inliner 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/css-inliner CHANGED
@@ -4,18 +4,19 @@ require 'css_inliner'
4
4
 
5
5
  opt = OptionParser.new
6
6
  Version = CSSInliner::VERSION
7
- options = {}
7
+ options = {format: 'html'}
8
8
 
9
9
  opt.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options] htmlfile"
10
10
  opt.on('-o', '--output=OUTPUTFILE', 'file name to output result HTML') {|v| options[:output] = v}
11
+ opt.on('-f', '--format=FORMAT', 'format to output("html", "xhtml" or "xml")', %w[html xhtml xml]) {|v| options[:format] = v}
11
12
  opt.on('-i [SUFFIX]', '--in-place', '--overwrite', 'inplace editing') do |v|
12
13
  options[:'in-place'] = true
13
14
  options[:suffix] = v
14
15
  end
15
- opt.on('-e ELEMENT', '--element', 'element name to extract as root') {|v| options[:element] = v}
16
+ opt.on('-e', '--element=ELEMENT', 'element name to extract as root') {|v| options[:element] = v}
16
17
 
17
18
  opt.parse! ARGV
18
- processed = CSSInliner.process File.read(ARGV[0]), File.dirname(ARGV[0]), options[:element]
19
+ processed = CSSInliner.process File.read(ARGV[0]), File.dirname(ARGV[0]), options[:element], options[:format]
19
20
  if options[:'in-place']
20
21
  FileUtils.cp(ARGV[0], ARGV[0] + options[:suffix]) if options[:suffix]
21
22
  File.open(ARGV[0], 'w') {|f| f.write processed}
data/lib/css_inliner.rb CHANGED
@@ -11,12 +11,22 @@ module CSSInliner
11
11
  # @param [String] basedir Base directory or URI to traverse relative URI for images
12
12
  # @param [String] element Element name to be returned.
13
13
  # Returns whole document when nil
14
+ # @param [String] format Format to output, html or xhtml
14
15
  # @return [String] HTML source
15
- def process(html, basedir = '.', element = nil)
16
+ def process(html, basedir = '.', element = nil, format = 'html')
16
17
  doc = html.instance_of?(Nokogiri::XML::Document) ? html : Nokogiri.XML(html)
17
18
  doc = Inliner.new(doc, basedir).inline
18
19
  doc = doc.css(element)[0] if element
19
- doc.to_s
20
+ case format
21
+ when 'xhtml'
22
+ doc.to_xhtml
23
+ when 'html'
24
+ doc.to_html
25
+ when 'xml'
26
+ doc.to_xml
27
+ else
28
+ doc.to_s
29
+ end
20
30
  end
21
31
  end
22
32
  end
@@ -13,7 +13,7 @@ module CSSPool
13
13
  if base_decls.empty?
14
14
  base << other_decl
15
15
  else
16
- base_decl = base_decls.pop
16
+ base_decl = base_decls.shift
17
17
  base_decls.each do |decl|
18
18
  base_decl.update decl
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module CSSInliner
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: css_inliner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-29 00:00:00.000000000Z
12
+ date: 2012-04-30 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &12417000 !ruby/object:Gem::Requirement
16
+ requirement: &11151600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12417000
24
+ version_requirements: *11151600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: csspool
27
- requirement: &12415820 !ruby/object:Gem::Requirement
27
+ requirement: &11150260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *12415820
35
+ version_requirements: *11150260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bsearch
38
- requirement: &12415220 !ruby/object:Gem::Requirement
38
+ requirement: &11149700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *12415220
46
+ version_requirements: *11149700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: test-unit
49
- requirement: &12414040 !ruby/object:Gem::Requirement
49
+ requirement: &11148500 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *12414040
57
+ version_requirements: *11148500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: cover_me
60
- requirement: &12430900 !ruby/object:Gem::Requirement
60
+ requirement: &11165460 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '1'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *12430900
68
+ version_requirements: *11165460
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
- requirement: &12430380 !ruby/object:Gem::Requirement
71
+ requirement: &11164980 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *12430380
79
+ version_requirements: *11164980
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: pry
82
- requirement: &12429780 !ruby/object:Gem::Requirement
82
+ requirement: &11164380 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *12429780
90
+ version_requirements: *11164380
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: pry-doc
93
- requirement: &12429300 !ruby/object:Gem::Requirement
93
+ requirement: &11163880 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *12429300
101
+ version_requirements: *11163880
102
102
  description: ! "\n inline CSS from external file(s) and/or style elment(s) in head
103
103
  element\n into style attibute of HTML elements\n "
104
104
  email:
@@ -267,7 +267,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
267
267
  version: '0'
268
268
  segments:
269
269
  - 0
270
- hash: -1019368120188778628
270
+ hash: 4449711269837875918
271
271
  required_rubygems_version: !ruby/object:Gem::Requirement
272
272
  none: false
273
273
  requirements:
@@ -276,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
276
276
  version: '0'
277
277
  segments:
278
278
  - 0
279
- hash: -1019368120188778628
279
+ hash: 4449711269837875918
280
280
  requirements: []
281
281
  rubyforge_project:
282
282
  rubygems_version: 1.8.8