scrap-css 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/scrap_css.rb +67 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 490448cf3a3a3fa6aacc3ea311fce308ad0dc378
4
+ data.tar.gz: 30deea3c9ebe38f11d58a41f16e666644fa7a6bb
5
+ SHA512:
6
+ metadata.gz: 626eceb7404d65cf374c1109a5bac423a9c13102c75d4ebdb3a80cad3333e8ccd0e7e9409dd9dd172f3b6f1e28246875db36594a56418145f820dd37d829704c
7
+ data.tar.gz: c59fea0dca07d885d6ba7b49a17afa2ef2ca39ea7e2bd926d6b6e60e4a89447ad135e5a4606547e144ff13ac29c0ff97e594b34749e07b8b6fe47feb9a5d237b
data/lib/scrap_css.rb ADDED
@@ -0,0 +1,67 @@
1
+ module ScrapCss
2
+ def self.html_file(path)
3
+ ScrapCss::Html.new(path)
4
+ end
5
+
6
+ def self.css_file(path)
7
+ ScrapCss::Css.new(path)
8
+ end
9
+
10
+ def self.run(path_html, path_css)
11
+ html_file = ScrapCss.html_file(path_html)
12
+ css_file = ScrapCss.css_file(path_css)
13
+ css_clases = html_file.css_clases
14
+ css_file.select_css(css_clases)
15
+ css_file.save_select_css
16
+ end
17
+ end
18
+
19
+ class ScrapCss::Html
20
+ def initialize(path="")
21
+ @file_lines ||= IO.readlines(path)
22
+ end
23
+
24
+ def css_clases
25
+ @css_clases ||= @file_lines.select{ |line|
26
+ line =~ /class=/
27
+ }.map{ |line|
28
+ line.scan(/class="([^"]*)"/)
29
+ }.flatten.uniq
30
+ end
31
+ end
32
+
33
+ class ScrapCss::Css
34
+ def initialize(path="")
35
+ @file_lines ||= IO.readlines(path)
36
+ @css_clases_used = []
37
+ end
38
+
39
+ def select_css(css_clases_useds)
40
+ @file_lines.each_with_index do |file_line, index|
41
+ css_clases_useds.each do |css_clase|
42
+ if ScrapCss::Css.str_contain_css(file_line, css_clase)
43
+ @css_clases_used << get_css_class(index, index_close_tag(index))
44
+ end
45
+ end
46
+ end
47
+ @css_clases_used
48
+ end
49
+
50
+ def save_select_css
51
+ File.open("output.css", 'w+') do |file|
52
+ @css_clases_used.each{|css_clase_used| file.write(css_clase_used) }
53
+ end
54
+ end
55
+
56
+ def self.str_contain_css(str, css_class)
57
+ str.include?(".#{css_class} ") || str.include?(".#{css_class}.")
58
+ end
59
+
60
+ def get_css_class(first_line, last_line)
61
+ @file_lines[first_line..last_line].join("")
62
+ end
63
+
64
+ def index_close_tag(index)
65
+ @file_lines[index].include?("}") ? index : index_close_tag(index+1)
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scrap-css
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Miguel Savignano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: get component html and css
14
+ email: migue.masx@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/scrap_css.rb
20
+ homepage: http://rubygems.org/gems/scrap-css
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.5.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: ScrapCss
44
+ test_files: []