webshot 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -21,13 +21,26 @@ Or install it yourself as:
21
21
 
22
22
  # Setup Capybara
23
23
  Webshot.capybara_setup!
24
-
25
24
  webshot = Webshot::Screenshot.new
25
+
26
+ # Capture Google's home page
26
27
  webshot.capture "http://www.google.com/", "google.png"
27
28
 
28
- # Customize output (MiniMagick settings)
29
+ # Customize thumbnail
29
30
  webshot.capture "http://www.google.com/", "google.png", width: 100, height: 90, quality: 85
30
31
 
32
+ # Customize thumbnail generation (MiniMagick)
33
+ # see: https://github.com/minimagick/minimagick
34
+ webshot.capture("http://www.google.com/", "google.png") do |magick|
35
+ magick.combine_options do |c|
36
+ c.thumbnail "100x"
37
+ c.background "white"
38
+ c.extent "100x90"
39
+ c.gravity "north"
40
+ c.quality 85
41
+ end
42
+ end
43
+
31
44
  ## Contributing
32
45
 
33
46
  1. Fork it
@@ -22,21 +22,30 @@ module Webshot
22
22
  gravity = opts.fetch(:gravity, "north")
23
23
  quality = opts.fetch(:quality, 85)
24
24
 
25
+ # Reset session before visiting url
26
+ Capybara.reset_sessions!
27
+
25
28
  # Open page
26
29
  visit url
27
30
 
31
+ # Check response code
28
32
  if page.driver.status_code == 200
29
- # Save screenshot
33
+ # Save screenshot to file
30
34
  page.driver.save_screenshot(path, :full => true)
31
35
 
32
36
  # Resize screenshot
33
37
  thumb = MiniMagick::Image.open(path)
34
- thumb.combine_options do |c|
35
- c.thumbnail "#{width}x"
36
- c.background "white"
37
- c.extent "#{width}x#{height}"
38
- c.gravity gravity
39
- c.quality quality
38
+ if block_given?
39
+ # Customize MiniMagick options
40
+ yield thumb
41
+ else
42
+ thumb.combine_options do |c|
43
+ c.thumbnail "#{width}x"
44
+ c.background "white"
45
+ c.extent "#{width}x#{height}"
46
+ c.gravity gravity
47
+ c.quality quality
48
+ end
40
49
  end
41
50
 
42
51
  # Save thumbnail
@@ -1,3 +1,3 @@
1
1
  module Webshot
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/test/webshot_test.rb CHANGED
@@ -11,7 +11,7 @@ class WebshotTest < Test::Unit::TestCase
11
11
 
12
12
  def test_http
13
13
  assert_nothing_raised do
14
- %w(www.google.com www.yahoo.com).each do |name|
14
+ %w(www.yahoo.com).each do |name|
15
15
  output = thumb(name)
16
16
  File.delete output if File.exists? output
17
17
  @webshot.capture "http://#{name}/", output
@@ -31,14 +31,31 @@ class WebshotTest < Test::Unit::TestCase
31
31
  end
32
32
  end
33
33
 
34
- def test_
35
- %w(888.888.888.888).each do |name|
34
+ def test_invalid_url
35
+ %w(nxdomain).each do |name|
36
36
  assert_raise Webshot::WebshotError do
37
37
  @webshot.capture "http://#{name}/", thumb(name)
38
38
  end
39
39
  end
40
40
  end
41
41
 
42
+ def test_mini_magick
43
+ assert_nothing_raised do
44
+ %w(www.yahoo.com).each do |name|
45
+ output = thumb(name)
46
+ File.delete output if File.exists? output
47
+
48
+ # Customize MiniMagick options
49
+ @webshot.capture("http://#{name}/", output) do |thumb|
50
+ thumb.combine_options do |c|
51
+ c.thumbnail "100x90"
52
+ end
53
+ end
54
+ assert File.exists? output
55
+ end
56
+ end
57
+ end
58
+
42
59
  protected
43
60
 
44
61
  def thumb(name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-30 00:00:00.000000000 Z
12
+ date: 2013-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler