html-to-css 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 421d1eaa5841abe3e4bcb2a9a774f9c56c42deb4
4
- data.tar.gz: 407d169119f7c6038f8a2dacf1393dcc8f55093c
3
+ metadata.gz: 7bb567fab6e41c0222d3c482d3830711ab82ed62
4
+ data.tar.gz: 99b4ea9ceb1975d692de150a010607863fa87d9d
5
5
  SHA512:
6
- metadata.gz: 37eed1658e73c76a004ede96799288a1f3162d2792bf779fd1da2535e347458f0f4dfedc71b8b2daea8c74fc37403c7e582f0318fe1815884c484b2d33261438
7
- data.tar.gz: 2d8fd2b7571a7179fb3124f9f26116259ef41f9c0efd1fb0341a83ccec66a69b2ee67d19040b76bd367293cedb779101fd0682bd2068ef3e1e7948aa3790a9d9
6
+ metadata.gz: a5d9df03b2f703e504398f0729b758363eb649d8899b3a44489eb2c528aac925b03495223094ad94579132b310de229f11d274c9fb4e6cceefb15c3e62622d63
7
+ data.tar.gz: 5d0879fe7a4f3fe5d7ca40563e411fc83987c8bcbb1cfb1dc37576b9820840f8d169aba07a24a3f4ccbba045dd6bf596f2d0f95c31e2cab0e5fe14b463b13abe
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/html-to-css.rb CHANGED
@@ -4,6 +4,12 @@
4
4
 
5
5
  require 'rexle'
6
6
 
7
+ class String
8
+
9
+ def to_h()
10
+ Hash[self.gsub(/\n/,'').split(/;\s*/).map{|x| x.split(/:/,2).map(&:strip)}]
11
+ end
12
+ end
7
13
 
8
14
  class HtmlToCss
9
15
 
@@ -89,10 +95,10 @@ class HtmlToCss
89
95
  def scan_to_css(e, indent='', parent_selector='')
90
96
 
91
97
  return if @nocss.include? e.name
92
- attr = e.attributes
98
+ h = e.attributes
93
99
 
94
- if attr.has_key?(:id) then
95
- selector = '#' + attr[:id]
100
+ if h.has_key?(:id) then
101
+ selector = '#' + h[:id]
96
102
  else
97
103
  selector = (parent_selector + ' ' + e.name).strip
98
104
  end
@@ -104,13 +110,15 @@ class HtmlToCss
104
110
  @selectors << selector
105
111
 
106
112
  if @elements.has_key?(e.name.to_sym) then
107
- attributes = @elements[e.name.to_sym].strip.sub(':color','#a4f')
108
- .gsub(/\n/,'').split(/;\s*/).join(";\n" + indent + ' ')
113
+ attributes = @elements[e.name.to_sym].strip.sub(':color','#a4f').to_h
109
114
  else
110
- attributes = ''
115
+ attributes = {}
111
116
  end
117
+
118
+ attr = attributes.merge!(h[:style].to_h)
119
+ .map{|x| x.join(': ')}.join(";\n" + indent + ' ')
112
120
 
113
- @css << indent + selector + " {\n#{indent} #{attributes}\n#{indent}}"
121
+ @css << indent + selector + " {\n#{indent} #{attr}\n#{indent}}"
114
122
 
115
123
  end
116
124
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-to-css
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file