juice_extractor 0.0.0.2 → 0.0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,11 +4,12 @@ require 'json'
4
4
 
5
5
  module JuiceExtractor
6
6
  # TODO: Extend other modules here
7
- #"[\"background-color\",\"border-color\",\"color\"]"
7
+ #"[\"background-color\",\"border-color\",\"color\"]"
8
8
  end
9
9
 
10
10
  module ColorExtractor
11
11
  def self.implicit_colors(site_url, quantize = nil)
12
+ return [] if site_url.nil?
12
13
  image_path = Base.screenshot(site_url)
13
14
  img = Magick::ImageList.new(image_path)
14
15
  img = img.quantize(quantize) if quantize
@@ -16,6 +17,7 @@ module ColorExtractor
16
17
  end
17
18
 
18
19
  def self.explicit_colors(site_url, attributes = ['background-color', "border-color", 'color'], quantize = nil)
20
+ return {} if site_url.nil?
19
21
  phantom_script = File.expand_path(File.dirname(__FILE__) + "/juice_extractor/js/styles.phantom.js")
20
22
  val = `phantomjs #{phantom_script} #{site_url} #{ File.dirname(__FILE__) } '#{attributes.to_json}'`
21
23
  colors= Base.build_explicit_colors(val, attributes, quantize)
@@ -36,14 +38,14 @@ module ColorExtractor
36
38
  attributes.each do |prop|
37
39
  colors['containers'][prop] = colors['containers'][prop].compact.group_by.map{|e| [e, e.length]}.uniq.sort{|a,b| b[1] <=> a[1]}.map{|e| e[0].upcase }
38
40
  colors['typography'][prop] = colors['typography'][prop].compact.group_by.map{|e| [e, e.length]}.uniq.sort{|a,b| b[1] <=> a[1]}.map{|e| e[0].upcase }
39
-
41
+
40
42
  if max && max > 0
41
43
  colors['containers'][prop] = colors['containers'][prop][0..max-1]
42
44
  colors['typography'][prop] = colors['typography'][prop][0..max-1]
43
45
  end
44
46
  end
45
-
47
+
46
48
  colors
47
49
  end
48
50
  end
49
- end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module JuiceExtractor
2
- VERSION = "0.0.0.2"
2
+ VERSION = "0.0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: juice_extractor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 75
4
+ hash: 73
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
9
  - 0
10
- - 2
11
- version: 0.0.0.2
10
+ - 3
11
+ version: 0.0.0.3
12
12
  platform: ruby
13
13
  authors:
14
14
  - Adrian Castillo