html_inline_css 0.1.3 → 0.1.5
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 +4 -4
- data/README.md +9 -8
- data/lib/html_inline_css/version.rb +1 -1
- data/lib/html_inline_css.rb +11 -9
- 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: e415f6bec3f21e0d05b5764c1e1d71de09f6f0e9
|
4
|
+
data.tar.gz: 9c34dbcab6eab6a395794635415e4ba5c6a50de4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbcecd63981c97ddd6bfebe5a37da810a67a5c48e940b8d6a1259d2cfac88a5732d98267278445ed327dda46a6c86bee7bbc8f78ce85ac58ee10466382ef1318
|
7
|
+
data.tar.gz: 9cbf107ba71e454665adb7da63082eaa3c54cf1019016ab37274244886d3d6589618f238336dcfdc48b49720f6ed51bc1ed4d29bd36a6701fcfed74a27264ac6
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# HtmlInlineCss
|
2
2
|
|
3
|
-
|
3
|
+
This gem was created to inline css in html mails for Pustomer.com but can be used anywhere you want to inline css.
|
4
4
|
|
5
|
-
|
5
|
+
Be aware that the gem not yet is ready for production. Feel free to fork and build upon it yourself.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,17 +22,18 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
```ruby
|
26
|
+
html = "<html><head><style>div {border: 1px solid #e5e5e5;}</style></head><body><div> Foo bar </div></body></html>"
|
27
|
+
html_with_inline_css = InlineCssString::CSS.inline_css(html)
|
28
28
|
|
29
|
-
|
29
|
+
html_with_inline_css => "<div style='border:1px solid #e5e5e5;'> Foo Bar </div>"
|
30
|
+
```
|
30
31
|
|
31
|
-
|
32
|
+
Be aware that the "InlineCssString::CSS.inline_css(string)" will remove all <html>,<head>,<style> and <body> tags.
|
32
33
|
|
33
34
|
## Contributing
|
34
35
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/niiicolai/html_inline_css. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
37
|
|
37
38
|
|
38
39
|
## License
|
data/lib/html_inline_css.rb
CHANGED
@@ -4,7 +4,7 @@ require "nokogiri"
|
|
4
4
|
module InlineCssString
|
5
5
|
class CSS
|
6
6
|
|
7
|
-
def get_all_class_and_ids
|
7
|
+
def self.get_all_class_and_ids
|
8
8
|
@html_tags.each do |tag|
|
9
9
|
@doc_to.css("#{tag}").each do |y|
|
10
10
|
unless y.nil?
|
@@ -23,7 +23,7 @@ module InlineCssString
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def add_style_tag_to_html(html)
|
26
|
+
def self.add_style_tag_to_html(html)
|
27
27
|
@html_tags.each do |tag|
|
28
28
|
html.css("#{tag}").each do |x|
|
29
29
|
unless x.nil?
|
@@ -35,7 +35,7 @@ module InlineCssString
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def add_style(tag, arr)
|
38
|
+
def self.add_style(tag, arr)
|
39
39
|
unless arr.nil?;
|
40
40
|
@doc_to.css("#{tag}").each do |y|
|
41
41
|
unless y.nil?
|
@@ -45,7 +45,7 @@ module InlineCssString
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def add_style_by_id_or_class(id_or_class_name, arr, id_or_class)
|
48
|
+
def self.add_style_by_id_or_class(id_or_class_name, arr, id_or_class)
|
49
49
|
unless arr.nil?;
|
50
50
|
if id_or_class == "class"
|
51
51
|
@html_tags.each do |tag|
|
@@ -67,7 +67,7 @@ module InlineCssString
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
def inline_css_from_style_tag(html)
|
70
|
+
def self.inline_css_from_style_tag(html)
|
71
71
|
|
72
72
|
style_tags = html.search('style').map { |n| n.inner_text }
|
73
73
|
|
@@ -386,12 +386,14 @@ module InlineCssString
|
|
386
386
|
@html_tags = ["div","span","b","a","i","abbr","acronym","address","applet","area","article","aside","bdi","big","blockquote","caption","center","cite","code","col","colgroup","datalist","dd","del","details","dfn","dialog","dir","dl","dt","em","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","hr","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","menu","menuitem","meter","nav","object","ol","optgroup","option","output","p","param","pre","progress","q","rp","rt","ruby","s","samp","section","select","small","source","strike","strong","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","wbr"]
|
387
387
|
@classes = Array.new
|
388
388
|
@ids = Array.new
|
389
|
-
@html_without_skeleton = html.gsub(/<
|
389
|
+
@html_without_skeleton = html.gsub(/<html>|<\/html>|<head>|<\/head>|<body>|<\/body>|<script>|<\/script>/,"")
|
390
|
+
@html_without_skeleton = html.gsub(/<script(.*?)>(.*?)<\/script>|<script(.*?)>(.*?)<\/script>/m,"")
|
391
|
+
@html_without_skeleton = html.gsub(/<style(.*?)>(.*?)<\/style>|<style(.*?)>(.*?)<\/style>/m,"")
|
390
392
|
@doc = Nokogiri::HTML::DocumentFragment.parse(html)
|
391
393
|
@doc_to = Nokogiri::HTML::DocumentFragment.parse(@html_without_skeleton)
|
392
|
-
get_all_class_and_ids
|
393
|
-
add_style_tag_to_html(@doc_to)
|
394
|
-
inline_css_from_style_tag(@doc)
|
394
|
+
self.get_all_class_and_ids
|
395
|
+
self.add_style_tag_to_html(@doc_to)
|
396
|
+
self.inline_css_from_style_tag(@doc)
|
395
397
|
return @doc_to.to_html
|
396
398
|
end
|
397
399
|
|