url2png 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,9 +26,10 @@ This is done by setting the mode:
26
26
  Url2png::Config.mode = :placehold if Rails.env.development?
27
27
 
28
28
  Options are:
29
- - :production (default; will use the url2png api to generate images)
30
- - :placehold (will generate images at http://placehold.it)
31
- - :dummy (will give a grey base64 data image)
29
+
30
+ * :production (default; will use the url2png api to generate images)
31
+ * :placehold (will generate images at http://placehold.it)
32
+ * :dummy (will give a grey base64 data image)
32
33
 
33
34
  In Rails you probably want to do configuration in an initializer.
34
35
 
@@ -50,6 +51,55 @@ To only get the image url:
50
51
 
51
52
  site_image_url url, :size => '300x200'
52
53
 
54
+ Options are:
55
+
56
+ **:size**<br>
57
+ This is a proportion bounding box.<br>
58
+ Thumbnails will be resized to fit within this box.<br>
59
+ default: 'ORIGINAL'<br>
60
+ examples:
61
+
62
+ site_image_tag url, :size => '500x500'
63
+
64
+ site_image_tag url, :size => 'ORIGINAL'
65
+
66
+ **:thumbnail** (alias for :size)
67
+
68
+ **:browser_size**<br>
69
+ Set the initial browser screen size.<br>
70
+ default: '1024x768'<br>
71
+ min: '200x200'<br>
72
+ max: '4000x4000'<br>
73
+ example:
74
+
75
+ site_image_tag url, :size => '300x200', :browser_size => '1024x2500'
76
+
77
+ **:delay**<br>
78
+ Extra delay (in seconds) forced between page load and screenshot.<br>
79
+ default: 1<br>
80
+ min: 1<br>
81
+ max: 5<br>
82
+ example:
83
+
84
+ site_image_tag url, :size => '300x200', :delay => 2
85
+
86
+ **:fullscreen**<br>
87
+ When true, Will attempt to capture entire document canvas.<br>
88
+ Will never return screenshot smaller than "Initial Screen Size".<br>
89
+ default: false<br>
90
+ example:
91
+
92
+ site_image_tag url, :size => '300x200', :fullscreen => true
93
+
94
+
95
+ Original API docs: https://url2png.com/doc/
96
+
97
+
98
+
99
+ ### API Version
100
+ From version 0.1.0 and up this gem is using version 4 of the url2png API.<br>
101
+ Version 0.0.7 is the last one using version 3 of the API.
102
+
53
103
 
54
104
  ## Important
55
105
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.1.0
@@ -20,7 +20,7 @@ module Url2png
20
20
  end
21
21
 
22
22
  def self.api_version
23
- @url2png_version ||= 'v3'
23
+ @url2png_version ||= 'v4'
24
24
  end
25
25
 
26
26
  # public key setter and getter
@@ -2,12 +2,19 @@ module Url2png
2
2
  module Dimensions
3
3
 
4
4
  def self.parse options
5
- size = options[:size] || Url2png::Config.default_size
6
-
5
+ # convert tumbnail to size to ensure compatibility with older gem versions
6
+ options[:size] ||= options[:thumbnail]
7
+
8
+ # distill image size
9
+ size = (options[:size] || Url2png::Config.default_size).split('x')
10
+ width = options[:width] || size[0]
11
+ height = options[:height] || size[1]
12
+
13
+ # return dimensions hash
7
14
  {
8
- :size => size,
9
- :width => options[:width] || size.split('x')[0],
10
- :height => options[:height] || size.split('x')[1]
15
+ :size => "#{ width }x#{ height }",
16
+ :width => width,
17
+ :height => height
11
18
  }
12
19
  end
13
20
 
@@ -1,24 +1,36 @@
1
1
  module Url2png
2
2
  module Helpers
3
3
  module Common
4
-
4
+
5
+ # complete image tag
5
6
  def site_image_tag url, options = {}
7
+ # parse size
6
8
  dim = Url2png::Dimensions.parse(options)
7
-
9
+
10
+ # ensure image alt
11
+ alt = options.key?(:alt) ? options.delete(:alt) : url
12
+
13
+ # filter options
14
+ url2png_options = {}
15
+ [:size, :thumbnail, :browser_size, :delay, :fullscreen].each do |key|
16
+ url2png_options[key] = options.delete(key) if options.key?(key)
17
+ end
18
+
8
19
  # build image tag
9
20
  img = '<img'
10
- img << " src='#{ site_image_url(url, options) }'"
11
- img << " alt='#{ options[:alt] || url }'"
21
+ img << " src='#{ site_image_url(url, url2png_options) }'"
22
+ img << " alt='#{ alt }'"
12
23
  img << " width='#{ dim[:width] }'"
13
24
  img << " height='#{ dim[:height] }'"
14
25
  options.each_pair do |k, v|
15
26
  img << " #{ k }='#{ v }'" unless v.nil? || v == ''
16
27
  end
17
28
  img << ' />'
18
- img.html_safe
19
29
  end
20
30
 
31
+ # only the url for the image
21
32
  def site_image_url url, options = {}
33
+ # parse size
22
34
  dim = Url2png::Dimensions.parse(options)
23
35
 
24
36
  case Url2png::Config.mode
@@ -60,12 +72,27 @@ module Url2png
60
72
  # generate token
61
73
  token = Digest::MD5.hexdigest("#{ Url2png::Config.shared_secret }+#{ safe_url }")
62
74
 
75
+ # build options portion of URL
76
+ url_options = []
77
+ url_options << "t#{ dim[:size] }" if dim[:size]
78
+ url_options << "s#{ options[:browser_size] }" if options[:browser_size]
79
+ url_options << "d#{ options[:delay] }" if options[:delay]
80
+ url_options << "FULL" if options[:fullscreen]
81
+ url_options_string = url_options.join('-')
82
+
63
83
  # build image url
64
- File.join(Url2png::Config.api_url(options[:protocol]), Url2png::Config.api_version, Url2png::Config.public_key, token, dim[:size], safe_url)
84
+ File.join(
85
+ Url2png::Config.api_url(options[:protocol]),
86
+ Url2png::Config.api_version,
87
+ Url2png::Config.public_key,
88
+ token,
89
+ url_options_string,
90
+ safe_url
91
+ )
65
92
  end
66
93
 
67
94
  end
68
-
95
+
69
96
  end
70
97
  end
71
98
  end
@@ -1,12 +1,38 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../../lib/url2png/helpers/common.rb')
1
+ require 'spec_helper'
2
+ require 'url2png/helpers/common'
3
3
 
4
4
  describe Url2png do
5
5
  include Url2png::Helpers::Common
6
+ before(:all) do
7
+ Url2png::Config.public_key = "P4DBEC0200EE98"
8
+ Url2png::Config.shared_secret = "S169B0E051EAC6794B3EC9F385866187R"
9
+ end
6
10
 
7
11
  describe "site_image_tag" do
8
12
  it "should return the url of the http://pasparout.com image" do
9
13
  site_image_tag('http://pasparout.com').should_not be_nil
10
14
  end
11
15
  end
16
+
17
+ describe "site_image_url" do
18
+ it "should encode the thumbnail size when provided" do
19
+ site_image_url('http://www.nytimes.com/', :thumbnail => '200x300').should =~ %r{t200x300}
20
+ end
21
+
22
+ it "should encode the initial browser size when provided" do
23
+ site_image_url('http://www.nytimes.com/', :browser_size => '200x300').should =~ %r{s200x300}
24
+ end
25
+
26
+ it "should encode the delay when provided" do
27
+ site_image_url('http://www.nytimes.com/', :delay => 3).should =~ %r{d3}
28
+ end
29
+
30
+ it "should encode the fullscreen capture flag when provided" do
31
+ site_image_url('http://www.nytimes.com/', :fullscreen => true).should =~ %r{FULL}
32
+ end
33
+
34
+ it "should concatenate options by using hyphens" do
35
+ site_image_url('http://www.nytimes.com/', :delay => 3, :fullscreen => true).should =~ %r{d3-FULL}
36
+ end
37
+ end
12
38
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "url2png"
8
- s.version = "0.0.7"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["wout fierens", "fuzzyalej", "ceritium"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: url2png
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -15,7 +15,7 @@ date: 2011-12-01 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
18
- requirement: &2157323520 !ruby/object:Gem::Requirement
18
+ requirement: &2156933760 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 2.6.0
24
24
  type: :development
25
25
  prerelease: false
26
- version_requirements: *2157323520
26
+ version_requirements: *2156933760
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
- requirement: &2157321920 !ruby/object:Gem::Requirement
29
+ requirement: &2156933160 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 1.0.0
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *2157321920
37
+ version_requirements: *2156933160
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: jeweler
40
- requirement: &2157320760 !ruby/object:Gem::Requirement
40
+ requirement: &2156932560 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: 1.5.2
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *2157320760
48
+ version_requirements: *2156932560
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rcov
51
- requirement: &2157319780 !ruby/object:Gem::Requirement
51
+ requirement: &2156931920 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *2157319780
59
+ version_requirements: *2156931920
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: rspec
62
- requirement: &2157318140 !ruby/object:Gem::Requirement
62
+ requirement: &2156931280 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>'
@@ -67,7 +67,7 @@ dependencies:
67
67
  version: 2.6.0
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *2157318140
70
+ version_requirements: *2156931280
71
71
  description: Generate screenshots from websites almost instantly at any preferred
72
72
  size using ruby and the url2png.com API
73
73
  email: wout@impinc.co.uk
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  segments:
111
111
  - 0
112
- hash: -2618384894962089538
112
+ hash: -928741917321471624
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  none: false
115
115
  requirements: