Module: ColorExtractor::Base
- Defined in:
- lib/juice_extractor/core/color_extractor.rb
Class Method Summary collapse
- .build_explicit_colors(val, attributes, max = nil) ⇒ Object
- .color_explicit_cmd(site_url, attributes) ⇒ Object
- .screenshot(site_url, to_path = '/tmp') ⇒ Object
- .screenshot_cmd(site_url, path) ⇒ Object
Class Method Details
.build_explicit_colors(val, attributes, max = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/juice_extractor/core/color_extractor.rb', line 24 def self.build_explicit_colors(val, attributes, max = nil) colors = JSON.parse(val) attributes.each do |prop| 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 } 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 } if max && max > 0 colors['containers'][prop] = colors['containers'][prop][0..max-1] colors['typography'][prop] = colors['typography'][prop][0..max-1] end end colors end |
.color_explicit_cmd(site_url, attributes) ⇒ Object
40 41 42 43 44 |
# File 'lib/juice_extractor/core/color_extractor.rb', line 40 def self.color_explicit_cmd(site_url, attributes) phantom_script = File.(File.dirname(__FILE__) + "/../js/styles.phantom.js") puts "Running command: phantomjs #{phantom_script} #{site_url} #{ File.dirname(__FILE__) }/../ '#{attributes.to_json}' " `phantomjs #{phantom_script} #{site_url} #{ File.dirname(__FILE__) }/../ '#{attributes.to_json}'` end |
.screenshot(site_url, to_path = '/tmp') ⇒ Object
20 21 22 |
# File 'lib/juice_extractor/core/color_extractor.rb', line 20 def self.screenshot(site_url, to_path = '/tmp') Base.screenshot_cmd(site_url, to_path) end |
.screenshot_cmd(site_url, path) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/juice_extractor/core/color_extractor.rb', line 46 def self.screenshot_cmd(site_url, path) image_name = "#{path}/#{rand(36**10).to_s(36)}.png" phantom_script = File.(File.dirname(__FILE__) + "/../js/screenshot.phantom.js") puts "Running command: phantomjs --load-images=no #{phantom_script} #{site_url} #{image_name} " res = `phantomjs --load-images=no #{phantom_script} #{site_url} #{image_name}` /.*.png/.match(res).to_s end |