style_inliner 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +19 -2
- data/lib/style_inliner/document.rb +4 -2
- data/lib/style_inliner/node_style_folding.rb +4 -2
- data/lib/style_inliner/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf6243cd2ac843cb80cbaac1f3e6473e8ca4ed4e
|
4
|
+
data.tar.gz: 6290a31218e4de678afdd967dadb1f9ce276c2c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d3cf33a841c8c575764192957a001dbacc2c78a11168523f24dbfa069ac69645575a9900500cfb1bb64bc07568c07ffab1ab5ba77d7cf0cf0153c99c518b906
|
7
|
+
data.tar.gz: 3a0a85c2414583ad78efa39a10cab66ac9b6ded0aa302cc912125e87a2111f9efb34d7c3fed0d448b316500401098a086eff9d9d9480f1394c9e3828ab03863f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -31,15 +31,24 @@ html = <<-EOS
|
|
31
31
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
32
32
|
<style>
|
33
33
|
body {
|
34
|
-
background: red;
|
34
|
+
background-color: red;
|
35
|
+
}
|
36
|
+
|
37
|
+
td {
|
38
|
+
background-color: blue
|
35
39
|
}
|
36
40
|
</style>
|
37
41
|
</head>
|
38
42
|
<body>
|
43
|
+
<table>
|
44
|
+
<tr>
|
45
|
+
<td>example</td>
|
46
|
+
</tr>
|
47
|
+
</table>
|
39
48
|
</body>
|
40
49
|
</html>
|
41
50
|
EOS
|
42
|
-
puts StyleInliner::Document.new(html).inline
|
51
|
+
puts StyleInliner::Document.new(html, replace_properties_to_attributes: true).inline
|
43
52
|
```
|
44
53
|
|
45
54
|
```html
|
@@ -50,10 +59,18 @@ puts StyleInliner::Document.new(html).inline
|
|
50
59
|
|
51
60
|
</head>
|
52
61
|
<body style="background-color: red">
|
62
|
+
<table>
|
63
|
+
<tr>
|
64
|
+
<td bgcolor="blue">example</td>
|
65
|
+
</tr>
|
66
|
+
</table>
|
53
67
|
</body>
|
54
68
|
</html>
|
55
69
|
```
|
56
70
|
|
71
|
+
## Ruby version compatibility
|
72
|
+
StyleInliner is tested on Ruby 2.2.0.
|
73
|
+
|
57
74
|
## Development
|
58
75
|
|
59
76
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -19,8 +19,10 @@ module StyleInliner
|
|
19
19
|
)
|
20
20
|
|
21
21
|
# @param html [String]
|
22
|
-
|
22
|
+
# @param replace_properties_to_attributes [false, true]
|
23
|
+
def initialize(html, replace_properties_to_attributes: true)
|
23
24
|
@html = html
|
25
|
+
@replace_properties_to_attributes = replace_properties_to_attributes
|
24
26
|
end
|
25
27
|
|
26
28
|
# @return [Nokogiri::XML::Node]
|
@@ -79,7 +81,7 @@ module StyleInliner
|
|
79
81
|
|
80
82
|
def fold_style_attributes
|
81
83
|
root.search("*[@style]").each do |node|
|
82
|
-
NodeStyleFolding.new(node).call
|
84
|
+
NodeStyleFolding.new(node, replace_properties_to_attributes: @replace_properties_to_attributes).call
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
@@ -58,12 +58,14 @@ module StyleInliner
|
|
58
58
|
)
|
59
59
|
|
60
60
|
# @param node [Nokogiri::XML::Node]
|
61
|
-
|
61
|
+
# @param replace_properties_to_attributes [false, true]
|
62
|
+
def initialize(node, replace_properties_to_attributes: true)
|
62
63
|
@node = node
|
64
|
+
@replace_properties_to_attributes = replace_properties_to_attributes
|
63
65
|
end
|
64
66
|
|
65
67
|
def call
|
66
|
-
update_css_compatible_attributes
|
68
|
+
update_css_compatible_attributes if @replace_properties_to_attributes
|
67
69
|
update_style_attribute
|
68
70
|
end
|
69
71
|
|