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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab36466db22d447c5ac4948b1e5d07fbdf9b2e95
4
- data.tar.gz: be5f20e88868e3f5e3c8f89e0075045f47cecdd1
3
+ metadata.gz: e415f6bec3f21e0d05b5764c1e1d71de09f6f0e9
4
+ data.tar.gz: 9c34dbcab6eab6a395794635415e4ba5c6a50de4
5
5
  SHA512:
6
- metadata.gz: e75cd54aef1980b60693573d6178d3d5d18f5f0d30f13de2f225ed685fbe4a2be58c649df09399c0e5526e4b02c2ef88c9732dec9fe98c98cd44205a7af206a4
7
- data.tar.gz: 985808f61861e992316888448de70a7a6c09f81e42a4b0a8d8deb5e4f9e812ce130656ff524a9fb5c7f0be84330b30d164a7e78170cf93f6ddc586dd6062e3df
6
+ metadata.gz: dbcecd63981c97ddd6bfebe5a37da810a67a5c48e940b8d6a1259d2cfac88a5732d98267278445ed327dda46a6c86bee7bbc8f78ce85ac58ee10466382ef1318
7
+ data.tar.gz: 9cbf107ba71e454665adb7da63082eaa3c54cf1019016ab37274244886d3d6589618f238336dcfdc48b49720f6ed51bc1ed4d29bd36a6701fcfed74a27264ac6
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # HtmlInlineCss
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/html_inline_css`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
26
-
27
- ## Development
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
- 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.
29
+ html_with_inline_css => "<div style='border:1px solid #e5e5e5;'> Foo Bar </div>"
30
+ ```
30
31
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/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
+ 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
@@ -1,3 +1,3 @@
1
1
  module HtmlInlineCss
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -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(/<style>(.*?)\n\t\t<\/style>|<style>(.*?)<\/style>|<html>|<\/html>|<head>|<\/head>|<body>|<\/body>|<script>|<\/script>/,"")
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_inline_css
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolai Berg Andersen