monet 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd82504151954e9dec64d70da527bf9d6973b2aa
4
- data.tar.gz: 67a18681fd090836de4c7d4285afbd8e59c1b67e
3
+ metadata.gz: 2a11fc10105edf8cce2166fb0bf751e84115374f
4
+ data.tar.gz: e895a699a3246d30ce4d46231a54eaaa0e4f58a7
5
5
  SHA512:
6
- metadata.gz: 9ec8e7217fedd9b53d186da3ec9b06e2b6d0be26db4b7cabe5365a8d5779e5c03ae517e571cee12f8e951a6e4d63fb92fdadcf63e5d8374c1202b8a798082b5a
7
- data.tar.gz: 7baca87ebf4ec4e08e5575cdfcd0cebe26eaca652adbfdf9b6ad81a476ffe94857d2286283f1ddb0d9a8ad7a93da9d41b1d2a4bdcac76623294a5a17c4ad60fd
6
+ metadata.gz: 693e7e62a8ccbe89d7a17370961576848c48e7c172a8184db9c5447f533062251e6ba46ff8e9e29fc1b118cad1853e70b22dfe877eba8901395733119b83fee1
7
+ data.tar.gz: be761e3bf2fe43a9764a1b8b326bf779672113941ab1ee356b41c53436675ae7ce44c2b8b4dfa0da71c9a47553046ae4d6b5059f57bcf737b69cad7bf9c9911c
data/lib/monet/capture.rb CHANGED
@@ -1,8 +1,11 @@
1
+ require 'fileutils'
2
+
1
3
  require "capybara"
2
4
  require 'capybara/poltergeist'
3
5
  require "capybara/dsl"
4
6
 
5
7
  require 'monet/config'
8
+ require 'monet/path_router'
6
9
 
7
10
  module Monet
8
11
  class Capture
@@ -27,9 +30,29 @@ module Monet
27
30
  visit @router.build_url(path)
28
31
 
29
32
  @config.dimensions.each do |width|
33
+ file_path = @router.route_url_path(path, width)
34
+
30
35
  page.driver.resize(width, MAX_HEIGHT)
31
- page.driver.render(@router.route_url_path(path, width), full: true)
36
+ page.driver.render(file_path, full: true)
37
+
38
+ thumbnail(file_path) if @config.thumbnail?
32
39
  end
33
40
  end
41
+
42
+ def thumbnail(path)
43
+ img = ChunkyPNG::Image.from_file(path)
44
+ short_edge = [img.width, img.height].min
45
+ save_path = @router.to_thumbnail_path(path)
46
+ save_dir = File.dirname save_path
47
+
48
+ puts save_path
49
+
50
+ cropped = img.crop(0, 0, short_edge, short_edge)
51
+ resized = cropped.resize(200, 200)
52
+
53
+ FileUtils.mkdir_p save_dir unless Dir.exists? save_dir
54
+
55
+ resized.save save_path
56
+ end
34
57
  end
35
58
  end
data/lib/monet/config.rb CHANGED
@@ -14,7 +14,9 @@ module Monet
14
14
  map: nil,
15
15
  compare_type: "ColorBlend",
16
16
  capture_dir: "./captures",
17
- baseline_dir: "./baselines"
17
+ baseline_dir: "./baselines",
18
+ thumbnail_dir: "./thumbnails",
19
+ thumbnail: false
18
20
  }
19
21
 
20
22
  attr_accessor *DEFAULT_OPTIONS.keys
@@ -49,6 +51,10 @@ module Monet
49
51
  @base_url
50
52
  end
51
53
 
54
+ def thumbnail?
55
+ !!thumbnail
56
+ end
57
+
52
58
  def capture_dir=(path)
53
59
  @capture_dir = expand_path(path)
54
60
  end
@@ -57,6 +63,10 @@ module Monet
57
63
  @baseline_dir = expand_path(path)
58
64
  end
59
65
 
66
+ def thumbnail_dir=(path)
67
+ @thumbnail_dir = expand_path(path)
68
+ end
69
+
60
70
  def map=(paths)
61
71
  map.paths = paths unless paths.nil?
62
72
  end
@@ -8,6 +8,7 @@ module Monet
8
8
  @base_url = parse_uri(config.base_url)
9
9
  @capture_path = config.capture_dir
10
10
  @baseline_path = config.baseline_dir
11
+ @thumbnail_path = config.thumbnail_dir
11
12
  end
12
13
 
13
14
  def build_url(path)
@@ -38,6 +39,11 @@ module Monet
38
39
  path.gsub(@capture_path, @baseline_path)
39
40
  end
40
41
 
42
+ def to_thumbnail_path(path)
43
+ image_path = path.split(File::SEPARATOR)[-2..-1].join(File::SEPARATOR)
44
+ File.join @thumbnail_path, image_path
45
+ end
46
+
41
47
  # takes a path, returns the URL used to generate the image
42
48
  def route_path(path)
43
49
  url = path.split("/").last
data/lib/monet/tasks.rb CHANGED
@@ -1,23 +1,49 @@
1
1
  require 'monet'
2
2
 
3
+ def load_config(args)
4
+ args.with_defaults(path: './config.yaml')
5
+ Monet::Config.load args[:path]
6
+ end
7
+
8
+ def images_from_dir(dir)
9
+ Dir.glob File.join(dir, "**", "*.png")
10
+ end
11
+
3
12
  namespace :monet do
4
13
  desc "clean out the baseline directory"
5
14
  task :clean, :path do |t, args|
6
- args.with_defaults(path: './config.yaml')
7
-
8
- config = Monet::Config.load args[:path]
9
- Monet.clean config
15
+ Monet.clean load_config(args)
10
16
  end
11
17
 
12
18
  desc "Runs the site and grabs baselines"
13
19
  task :baseline => [:clean, :run] do
14
20
  end
15
21
 
22
+
23
+ namespace :thumbnail do
24
+ desc "Thumbnail all baseline images"
25
+ task :baseline do
26
+ config = load_config(args)
27
+ capture = Monet::Capture.new config
28
+
29
+ images_from_dir(config.baseline_dir).each do |image|
30
+ capture.thumbnail image
31
+ end
32
+ end
33
+
34
+ desc "Thumnail all captured images"
35
+ task :captures do
36
+ capture = Monet::Capture.new config
37
+
38
+ images_from_dir(config.capture_dir).each do |image|
39
+ capture.thumbnail image
40
+ end
41
+ end
42
+ end
43
+
16
44
  desc "Run the baseline comparison"
17
45
  task :run, :path do |t, args|
18
- args.with_defaults(path: './config.yaml')
19
-
20
- config = Monet::Config.load args[:path]
46
+ config = load_config(args)
21
47
  Monet.capture config
22
48
  Monet.compare config
23
49
  end
data/lib/monet/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Monet
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -3,7 +3,7 @@ require 'monet/baseline_control'
3
3
 
4
4
  describe Monet::BaselineControl do
5
5
  Given(:control) do
6
- config = flexmock("Config", compare_type: "ColorBlend", capture_dir: "./spec/fixtures", baseline_dir: "./baseline", base_url: "http://google.com")
6
+ config = flexmock("Config", compare_type: "ColorBlend", capture_dir: "./spec/fixtures", baseline_dir: "./baseline", thumbnail_dir: "./thumb", base_url: "http://google.com")
7
7
  flexmock Monet::BaselineControl.new(config)
8
8
  end
9
9
 
data/spec/capture_spec.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'spec_helper'
2
+
3
+ require 'chunky_png'
2
4
  require 'monet/capture'
3
5
 
4
6
  describe Monet::Capture do
@@ -6,7 +8,7 @@ describe Monet::Capture do
6
8
  Given(:url) { "http://google.com" }
7
9
  Given(:capture_agent) { Monet::Capture.new(capture_dir: path, base_url: url) }
8
10
 
9
- after do
11
+ after(:all) do
10
12
  Dir.glob("#{path}/**/*.png").each do |file|
11
13
  File.delete(file)
12
14
  end
@@ -42,10 +44,30 @@ describe Monet::Capture do
42
44
  Then { File.exist?("#{path}/google.com/google.com|-1400.png").should be_true }
43
45
  end
44
46
 
45
- context "prepends default protocol if missing" do
47
+ context "captures defualt size as 1024" do
46
48
  Given(:capture_agent) { Monet::Capture.new(capture_dir: path, base_url: "http://www.facebook.com") }
47
49
  When { capture_agent.capture('/') }
48
50
  Then { File.exist?("#{path}/www.facebook.com/www.facebook.com|-1024.png").should be_true }
49
51
  end
50
52
 
53
+ context "captured" do
54
+ Given(:thumb_path) { "#{path}/thumbnails/www.spider.io/www.spider.io|-1024.png" }
55
+ Given(:capture_agent) { Monet::Capture.new(capture_dir: path,
56
+ thumbnail_dir: File.join(path, "thumbnails"),
57
+ base_url: "http://www.spider.io",
58
+ thumbnail: true)
59
+ }
60
+ When { capture_agent.capture('/') }
61
+
62
+ context "can thumbnail an image" do
63
+ Then { File.exist?("#{path}/www.spider.io/www.spider.io|-1024.png").should be_true }
64
+ And { File.exist?(thumb_path).should be_true }
65
+ end
66
+
67
+ context "thumb is 200x200" do
68
+ When(:thumb) { ChunkyPNG::Image.from_file(thumb_path) }
69
+ Then { thumb.width.should == 200 }
70
+ And { thumb.height.should == 200 }
71
+ end
72
+ end
51
73
  end
@@ -5,7 +5,8 @@ require 'monet/config'
5
5
  describe Monet::PathRouter do
6
6
  Given(:capture) { File.expand_path "./capture" }
7
7
  Given(:baseline) { File.expand_path "./baseline" }
8
- Given(:config) { Monet::Config.new(base_url: "http://google.com", capture_dir: "./capture", baseline_dir: "./baseline") }
8
+ Given(:thumbnail) { File.expand_path "./thumbnail" }
9
+ Given(:config) { Monet::Config.new(base_url: "http://google.com", capture_dir: "./capture", baseline_dir: "./baseline", thumbnail_dir: "./thumbnail") }
9
10
  Given(:router) { Monet::PathRouter.new(config) }
10
11
 
11
12
  context "knows base dir" do
@@ -47,4 +48,12 @@ describe Monet::PathRouter do
47
48
  When(:path) { router.capture_to_baseline("#{capture}/google.com/google.com|space|manager-900.png") }
48
49
  Then { path.should == "#{baseline}/google.com/google.com|space|manager-900.png" }
49
50
  end
51
+
52
+ context "can create thumbnail path" do
53
+ When(:path) { router.to_thumbnail_path("#{capture}/google.com/google.com|space|manager-900.png") }
54
+ Then { path.should == "#{thumbnail}/google.com/google.com|space|manager-900.png" }
55
+
56
+ When(:path) { router.to_thumbnail_path("#{baseline}/google.com/google.com|space|manager-900.png") }
57
+ Then { path.should == "#{thumbnail}/google.com/google.com|space|manager-900.png" }
58
+ end
50
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke van der Hoeven
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-18 00:00:00.000000000 Z
11
+ date: 2013-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake