scrap-css 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/scrapcss +4 -0
  3. data/lib/scrap_css.rb +25 -11
  4. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abe2d347ff1d32ac9e038aa80161c9bcb26a8756
4
- data.tar.gz: d8dcfdb2db58f17ebb3b30a1b0f502030a05a7c1
3
+ metadata.gz: 5c75af8a388a24f86011c6b00287745ab9782e36
4
+ data.tar.gz: cd82cc894aedfb9cfb2229b68db61dbb4f1aaae5
5
5
  SHA512:
6
- metadata.gz: 0d9d809eb8c62c213b2764e7e94df02e2fdf706b9a03864a0eb4babc92e137f20a4a1725b673ea4ff53c3c48ebfb230e638b0226d918c4a460788b7d61af8d08
7
- data.tar.gz: cd35ac2549667d8f0281d82665cf769679bcca7b02e42f7d3905f6270609c3df59c5cb186fee3f1eac5702fe341fa7ada95c5a7e0cdb54106a366957dd531465
6
+ metadata.gz: 7e56ea39344dd21a3a5fbb5ef22bb21202e4cfb661ed6ba5fd17e159fe91a603c0822de16ab2306863c7a3a5f2d80483febaa38f42397e8929d46954f5dc859d
7
+ data.tar.gz: 30baed05e7175ccb44fae2135f6429576e7b0d7db28ab097445965a83c61796504551584734fc79fa77b55c992f41b35d339adb43755176a7234a13d471e950e
data/bin/scrapcss ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'scrap_css'
3
+ result = ScrapCss.run(ARGV[0], ARGV[1])
4
+ puts "#{result[:css_class_used_size]} css clases used in your html"
data/lib/scrap_css.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module ScrapCss
2
+
2
3
  def self.html_file(path)
3
4
  ScrapCss::Html.new(path)
4
5
  end
@@ -13,6 +14,7 @@ module ScrapCss
13
14
  css_clases = html_file.css_clases
14
15
  css_file.select_css(css_clases)
15
16
  css_file.save_select_css
17
+ result = {css_class_used_size:html_file.css_clases.size}
16
18
  end
17
19
  end
18
20
 
@@ -36,12 +38,32 @@ class ScrapCss::Html
36
38
  end
37
39
 
38
40
  class ScrapCss::Css
39
- def initialize(path="")
40
- @file_lines ||= IO.readlines(path)
41
- @css_parts = @file_lines.join("").split("\n\n")
41
+ def initialize(path="", url="")
42
+ @url = url
43
+ @path = path
44
+ @css_parts = IO.read(path).split("\n\n") unless path =~ /.min./
45
+ @css_parts = self.unminify.split("\n\n") if path =~ /.min./
42
46
  @css_parts_used = []
43
47
  end
44
48
 
49
+ def unminify
50
+ _unminify = IO.read(@path)
51
+ .gsub(";",";\n ")
52
+ .gsub("}","\n}\n\n\n")
53
+ .gsub("{","{\n ")
54
+ .gsub(",",",\n")
55
+ .gsub("*/","*/\n")
56
+
57
+ # File.open("output.css", 'w+'){ |file| file.write(_unminify) }
58
+ _unminify
59
+ end
60
+
61
+ def get_urls
62
+ @css_parts.select{|a| a =~ /url\(/ }
63
+ .map{|css_part| css_part.scan(/url\(([^)]*)\)/) }
64
+ .flatten.uniq
65
+ end
66
+
45
67
  def select_css(css_clases_useds)
46
68
  css_clases_useds.each do |css_clase|
47
69
  @css_parts.each do |css_part|
@@ -60,12 +82,4 @@ class ScrapCss::Css
60
82
  def self.str_contain_css(str, css_class)
61
83
  str.include?(".#{css_class} ") || str.include?(".#{css_class}.") || str.include?(".#{css_class}:")
62
84
  end
63
-
64
- def get_css_class(first_line, last_line)
65
- @file_lines[first_line..last_line].join("")
66
- end
67
-
68
- def index_close_tag(index)
69
- @file_lines[index].include?("}") ? index : index_close_tag(index+1)
70
- end
71
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrap-css
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Savignano
@@ -13,10 +13,12 @@ dependencies: []
13
13
  description: Get only the css used in a html portion; use to understand a web components
14
14
  from other web site.
15
15
  email: migue.masx@gmail.com
16
- executables: []
16
+ executables:
17
+ - scrapcss
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
21
+ - bin/scrapcss
20
22
  - lib/scrap_css.rb
21
23
  homepage: http://rubygems.org/gems/scrap-css
22
24
  licenses: