html_inline_css 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 172196abced8b4d267a138b57c6b525f247c8e2e
4
+ data.tar.gz: 2de8d446169e86032fd132b6ebc80817be4e03a1
5
+ SHA512:
6
+ metadata.gz: 892abbdbc657131f14bbe68bd7f10f9331bf4a24266008b787d524cd2c1eeb97f234897edbd334bd236f2a3640e3d5611df3a3b18ee3af1aec37f856b2ab9e27
7
+ data.tar.gz: 1108a7f17662099e7be974fa14e8468f2940f02df4ba42eebcd74c7b1780be12f27ae4fa0944649538741a2e2468e48def3ee264200283d4f788521a1f5f47dc
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'nokogiri'
4
+ # Specify your gem's dependencies in html_inline_css.gemspec
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Nicolai Andersen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # HtmlInlineCss
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.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'html_inline_css'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install html_inline_css
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
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.
30
+
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
+
33
+ ## Contributing
34
+
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
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "html_inline_css"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'html_inline_css/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "html_inline_css"
8
+ spec.version = HtmlInlineCss::VERSION
9
+ spec.authors = ["Nicolai Berg Andersen"]
10
+ spec.email = ["niiicolai@gmail.com"]
11
+
12
+ spec.summary = %q{Inline CSS}
13
+ spec.description = %q{A ruby script there can inline CSS on a string.}
14
+ spec.homepage = "https://github.com/niiicolai/html_inline_css"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
@@ -0,0 +1,3 @@
1
+ module HtmlInlineCss
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,397 @@
1
+ require "html_inline_css/version"
2
+ require "nokogiri"
3
+
4
+ module HtmlInlineCss
5
+
6
+ def inline_css(html)
7
+ @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"]
8
+ @classes = Array.new
9
+ @ids = Array.new
10
+ @html_without_skeleton = html.gsub(/<style>(.*?)\n\t\t<\/style>|<style>(.*?)<\/style>|<html>|<\/html>|<head>|<\/head>|<body>|<\/body>|<script>|<\/script>/,"")
11
+ @doc = Nokogiri::HTML::DocumentFragment.parse(html)
12
+ @doc_to = Nokogiri::HTML::DocumentFragment.parse(@html_without_skeleton)
13
+ get_all_class_and_ids
14
+ add_style_tag_to_html(@doc_to)
15
+ inline_css_from_style_tag(@doc)
16
+ return @doc_to.to_html
17
+ end
18
+
19
+ def get_all_class_and_ids
20
+ @html_tags.each do |tag|
21
+ @doc_to.css("#{tag}").each do |y|
22
+ unless y.nil?
23
+ if @classes.empty?
24
+ @classes << y["class"].to_s;
25
+ else
26
+ @classes.each do |css_class|; unless css_class == y["class"] || y["class"].nil?; @classes << y["class"].to_s; break; end; end;
27
+ end
28
+ if @ids.empty?
29
+ @ids << y["id"].to_s;
30
+ else
31
+ @ids.each do |css_id|; unless css_id == y["id"] || y["id"].nil?; @ids << y["id"].to_s; break; end; end;
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ def add_style_tag_to_html(html)
39
+ @html_tags.each do |tag|
40
+ html.css("#{tag}").each do |x|
41
+ unless x.nil?
42
+ unless x.to_s.match(/<#{Regexp.escape(tag)}\s(.*?)style=('|")(.*?)('|")(.*?)>/)
43
+ x['style'] = ''
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ def add_style(tag, arr)
51
+ unless arr.nil?;
52
+ @doc_to.css("#{tag}").each do |y|
53
+ unless y.nil?
54
+ y.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; y['style'] = "#{arr}#{i}" end }
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ def add_style_by_id_or_class(id_or_class_name, arr, id_or_class)
61
+ unless arr.nil?;
62
+ if id_or_class == "class"
63
+ @html_tags.each do |tag|
64
+ @doc_to.xpath("#{tag}[@class = '#{id_or_class_name}']").each do |y|
65
+ unless y.nil?
66
+ y.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; y['style'] = "#{arr}#{i}" end }
67
+ end
68
+ end
69
+ end
70
+ else
71
+ @html_tags.each do |tag|
72
+ @doc_to.xpath("#{tag}[@class = '#{id_or_class_name}']").each do |y|
73
+ unless y.nil?
74
+ y.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; y['style'] = "#{arr}#{i}" end }
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ def inline_css_from_style_tag(html)
83
+
84
+ style_tags = html.search('style').map { |n| n.inner_text }
85
+
86
+ style_tags.each do |tag|
87
+
88
+ # DIV
89
+ tag.scan(/div(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("div", x) }
90
+
91
+ # PARAGRAPH
92
+ tag.scan(/p\s{(.*?)}|p{(.*?)}/).flatten.select{ |x| !x.nil?; add_style("p", x) }
93
+
94
+ # BOLD
95
+ tag.scan(/b\s{(.*?)}|b{(.*?)}/).flatten.select{ |x| !x.nil?; add_style("b", x) }
96
+
97
+ # ITALIC
98
+ tag.scan(/i{(.*?)}|i\s{(.*?)}/).flatten.select{ |x| !x.nil?; add_style("i", x) }
99
+
100
+ # SPAN
101
+ tag.scan(/span(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("span", x) }
102
+
103
+ # H1
104
+ tag.scan(/h1(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("h1", x) }
105
+
106
+ # H2
107
+ tag.scan(/h2(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("h2", x) }
108
+
109
+ # H3
110
+ tag.scan(/h3(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("h3", x) }
111
+
112
+ # H4
113
+ tag.scan(/h4(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("h4", x) }
114
+
115
+ # H5
116
+ tag.scan(/h5(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("h5", x) }
117
+
118
+ # H6
119
+ tag.scan(/h6(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("h6", x) }
120
+
121
+ # A
122
+ tag.scan(/a(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("a", x) }
123
+
124
+ # ABBR
125
+ tag.scan(/abbr(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("abbr", x) }
126
+
127
+ # ACRONYM
128
+ tag.scan(/acronym(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("acronym", x) }
129
+
130
+ # ADDRESS
131
+ tag.scan(/address(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("address", x) }
132
+
133
+ # APPLET
134
+ tag.scan(/applet(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("applet", x) }
135
+
136
+ # AREA
137
+ tag.scan(/area(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("area", x) }
138
+
139
+ # ARTICLE
140
+ tag.scan(/article(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("article", x) }
141
+
142
+ # ASIDE
143
+ tag.scan(/aside(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("aside", x) }
144
+
145
+ # BDI
146
+ tag.scan(/bdi(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("bdi", x) }
147
+
148
+ # BIG
149
+ tag.scan(/big(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("big", x) }
150
+
151
+ # BLOCKQUOTE
152
+ tag.scan(/blockquote(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("blockquote", x) }
153
+
154
+ # CAPTION
155
+ tag.scan(/caption(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("caption", x) }
156
+
157
+ # CENTER
158
+ tag.scan(/center(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("center", x) }
159
+
160
+ # CITE
161
+ tag.scan(/cite(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("cite", x) }
162
+
163
+ # CODE
164
+ tag.scan(/code(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("code", x) }
165
+
166
+ # COL
167
+ tag.scan(/col(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("col", x) }
168
+
169
+ # COLGROUP
170
+ tag.scan(/colgroup(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("colgroup", x) }
171
+
172
+ # DATALIST
173
+ tag.scan(/datalist(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("datalist", x) }
174
+
175
+ # DD
176
+ tag.scan(/dd(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("dd", x) }
177
+
178
+ # DEL
179
+ tag.scan(/del(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("del", x) }
180
+
181
+ # details
182
+ tag.scan(/details(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("details", x) }
183
+
184
+ # DFN
185
+ tag.scan(/dfn(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("dfn", x) }
186
+
187
+ # DIALOG
188
+ tag.scan(/dialog(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("dialog", x) }
189
+
190
+ # DIR
191
+ tag.scan(/dir(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("dir", x) }
192
+
193
+ # DL
194
+ tag.scan(/dl(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("dl", x) }
195
+
196
+ # DT
197
+ tag.scan(/dt(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("dt", x) }
198
+
199
+ # EM
200
+ tag.scan(/em(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("em", x) }
201
+
202
+ # FOOTER
203
+ tag.scan(/footer(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("footer", x) }
204
+
205
+ # FORM
206
+ tag.scan(/form(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("form", x) }
207
+
208
+ # FRAME
209
+ tag.scan(/frame(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("frame", x) }
210
+
211
+ # FRAMESET
212
+ tag.scan(/frameset(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("frameset", x) }
213
+
214
+ # HR
215
+ tag.scan(/hr(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("hr", x) }
216
+
217
+ # IFRAME
218
+ tag.scan(/iframe(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("iframe", x) }
219
+
220
+ # IMG
221
+ tag.scan(/img(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("img", x) }
222
+
223
+ # INPUT
224
+ tag.scan(/input(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("input", x) }
225
+
226
+ # INS
227
+ tag.scan(/ins(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("ins", x) }
228
+
229
+ # KBD
230
+ tag.scan(/kbd(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("kbd", x) }
231
+
232
+ # KEYGEN
233
+ tag.scan(/keygen(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("keygen", x) }
234
+
235
+ # LABEL
236
+ tag.scan(/label(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("label", x) }
237
+
238
+ # LEGEND
239
+ tag.scan(/legend(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("legend", x) }
240
+
241
+ # LI
242
+ tag.scan(/li(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("li", x) }
243
+
244
+ # LINK
245
+ tag.scan(/link(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("link", x) }
246
+
247
+ # MAIN
248
+ tag.scan(/main(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("main", x) }
249
+
250
+ # MAP
251
+ tag.scan(/map(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("map", x) }
252
+
253
+ # MARK
254
+ tag.scan(/mark(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("mark", x) }
255
+
256
+ # MENU
257
+ tag.scan(/menu(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("menu", x) }
258
+
259
+ # MENUITEM
260
+ tag.scan(/menuitem(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("menuitem", x) }
261
+
262
+ # METER
263
+ tag.scan(/meter(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("meter", x) }
264
+
265
+ # NAV
266
+ tag.scan(/nav(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("nav", x) }
267
+
268
+ # OBJECT
269
+ tag.scan(/object(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("object", x) }
270
+
271
+ # OL
272
+ tag.scan(/ol(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("ol", x) }
273
+
274
+ # OPTGROUP
275
+ tag.scan(/optgroup(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("optgroup", x) }
276
+
277
+ # OPTION
278
+ tag.scan(/option(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("option", x) }
279
+
280
+ # OUTPUT
281
+ tag.scan(/output(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("output", x) }
282
+
283
+ # PARAM
284
+ tag.scan(/param(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("param", x) }
285
+
286
+ # PRE
287
+ tag.scan(/pre(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("pre", x) }
288
+
289
+ # PROGRESS
290
+ tag.scan(/progress(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("progress", x) }
291
+
292
+ # Q
293
+ tag.scan(/q{(.*?)}|q\s{(.*?)}/).flatten.select{ |x| !x.nil?; add_style("q", x) }
294
+
295
+ # RP
296
+ tag.scan(/rp(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("rp", x) }
297
+
298
+ # RT
299
+ tag.scan(/rt(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("rt", x) }
300
+
301
+ # RUBY
302
+ tag.scan(/ruby(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("ruby", x) }
303
+
304
+ # S
305
+ tag.scan(/s{(.*?)}|s\s{(.*?)}/).flatten.select{ |x| !x.nil?; add_style("ruby", x) }
306
+
307
+ # SAMP
308
+ tag.scan(/samp(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("samp", x) }
309
+
310
+ # SECTION
311
+ tag.scan(/section(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("section", x) }
312
+
313
+ # SELECT
314
+ tag.scan(/select(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("select", x) }
315
+
316
+ # SMALL
317
+ tag.scan(/small(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("small", x) }
318
+
319
+ # SOURCE
320
+ tag.scan(/source(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("source", x) }
321
+
322
+ # STRIKE
323
+ tag.scan(/strike(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("strike", x) }
324
+
325
+ # STRONG
326
+ tag.scan(/strong(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("strong", x) }
327
+
328
+ # SUB
329
+ tag.scan(/sub(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("sub", x) }
330
+
331
+ # SUMMARY
332
+ tag.scan(/summary(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("summary", x) }
333
+
334
+ # SUP
335
+ tag.scan(/sup(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("sup", x) }
336
+
337
+ # TABLE
338
+ tag.scan(/table(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("table", x) }
339
+
340
+ # TBODY
341
+ tag.scan(/tbody(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("tbody", x) }
342
+
343
+ # TD
344
+ tag.scan(/td(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("td", x) }
345
+
346
+ # TEXTAREA
347
+ tag.scan(/textarea(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("textarea", x) }
348
+
349
+ # TFOOT
350
+ tag.scan(/tfoot(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("tfoot", x) }
351
+
352
+ # TH
353
+ tag.scan(/th(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("th", x) }
354
+
355
+ # THEAD
356
+ tag.scan(/thead(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("thead", x) }
357
+
358
+ # TIME
359
+ tag.scan(/time(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("time", x) }
360
+
361
+ # TR
362
+ tag.scan(/tr(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("tr", x) }
363
+
364
+ # TRACK
365
+ tag.scan(/track(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("track", x) }
366
+
367
+ # TT
368
+ tag.scan(/tt(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("tt", x) }
369
+
370
+ # U
371
+ tag.scan(/u{(.*?)}|u\s{(.*?)}/).flatten.select{ |x| !x.nil?; add_style("u", x) }
372
+
373
+ # UL
374
+ tag.scan(/ul(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("ul", x) }
375
+
376
+ # VAR
377
+ tag.scan(/var(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("var", x) }
378
+
379
+ # WBR
380
+ tag.scan(/wbr(.*?){(.*?)}/).flatten.select{ |x| !x.nil?; add_style("wbr", x) }
381
+
382
+ # CLASS
383
+ @classes.each do |css_class|
384
+ regex = /\.#{Regexp.escape(css_class)}\s{(.*?)}|\.#{Regexp.escape(css_class)}{(.*?)}/
385
+ tag.scan(regex).flatten.select{ |x| !x.nil?; add_style_by_id_or_class(css_class, x, 'class'); }
386
+ end
387
+
388
+ # ID
389
+ @ids.each do |css_id|
390
+ regex = /\##{Regexp.escape(css_id)}\s{(.*?)}|\##{Regexp.escape(css_id)}{(.*?)}/
391
+ tag.scan(regex).flatten.select{ |x| !x.nil?; add_style_by_id_or_class(css_id, x, 'id') }
392
+ end
393
+
394
+ end
395
+ end
396
+
397
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html_inline_css
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicolai Berg Andersen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: A ruby script there can inline CSS on a string.
42
+ email:
43
+ - niiicolai@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - html_inline_css.gemspec
57
+ - lib/html_inline_css.rb
58
+ - lib/html_inline_css/version.rb
59
+ homepage: https://github.com/niiicolai/html_inline_css
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.6
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Inline CSS
83
+ test_files: []