gastly 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -3
- data/CHANGELOG.md +6 -0
- data/Gemfile +2 -0
- data/README.md +2 -0
- data/Rakefile +5 -0
- data/gastly.gemspec +2 -1
- data/lib/gastly.rb +5 -0
- data/lib/gastly/exceptions.rb +1 -0
- data/lib/gastly/image.rb +13 -9
- data/lib/gastly/screenshot.rb +28 -28
- data/lib/gastly/version.rb +1 -1
- metadata +23 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72868583159f8e35a055086dbba4130ad364589e
|
4
|
+
data.tar.gz: 7f86570ddc94846083a66fddc3e20234ae7ecef6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fe604a0a919d5d76a6be7358074e1348da096919c4db9217361d23fca30efc4d39a55d5e491772a692a87f521060a003be5c9a5820570bb9191a10b4a8bfa14
|
7
|
+
data.tar.gz: da9a98e0fe76658bb2a779623205e0628124c5138e0dd564c2bfe09b014e4ecf227913c7b4918f99b10991ba908d495735eef9741eadbdb313979a9feb6c4951
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: Yl4eB6CrBH8Jq6D02bBV5MxCtrNfDGP4L
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.3
|
data/.travis.yml
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
dist: trusty
|
1
2
|
language: ruby
|
2
3
|
rvm:
|
3
|
-
- 1.9.3
|
4
|
-
- 2.0.0
|
5
4
|
- 2.1.7
|
6
|
-
- 2.2.3
|
5
|
+
- 2.2.3
|
6
|
+
- 2.3.0
|
7
|
+
before_install:
|
8
|
+
- mkdir travis-phantomjs
|
9
|
+
- wget https://s3.amazonaws.com/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2 -O $PWD/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2
|
10
|
+
- tar -xvf $PWD/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2 -C $PWD/travis-phantomjs
|
11
|
+
- export PATH=$PWD/travis-phantomjs:$PATH
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
[](http://badge.fury.io/rb/gastly)
|
4
4
|
[](https://gemnasium.com/mgrachev/gastly)
|
5
5
|
[](https://codeclimate.com/github/mgrachev/gastly)
|
6
|
+
[](https://travis-ci.org/mgrachev/gastly)
|
7
|
+
[](https://coveralls.io/github/mgrachev/gastly?branch=master)
|
6
8
|
|
7
9
|
Create screenshots or previews of web pages using Gastly. Under the hood [Phantom.js](https://github.com/ariya/phantomjs/) and [MiniMagick](https://github.com/minimagick/minimagick). Gastly, I choose you!
|
8
10
|
|
data/Rakefile
CHANGED
data/gastly.gemspec
CHANGED
@@ -18,9 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency 'bundler'
|
21
|
+
spec.add_development_dependency 'bundler'
|
22
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
23
|
spec.add_development_dependency 'rubocop'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.4.0'
|
24
25
|
|
25
26
|
spec.add_dependency 'phantomjs2', '~> 2.0'
|
26
27
|
spec.add_dependency 'mini_magick', '~> 4.2'
|
data/lib/gastly.rb
CHANGED
data/lib/gastly/exceptions.rb
CHANGED
data/lib/gastly/image.rb
CHANGED
@@ -1,25 +1,29 @@
|
|
1
|
-
require 'mini_magick'
|
2
|
-
|
3
1
|
module Gastly
|
4
2
|
class Image
|
5
|
-
attr_reader :
|
3
|
+
attr_reader :image
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
# @param image [MiniMagick::Image] Instance of MiniMagick::Image
|
6
|
+
def initialize(image)
|
7
|
+
@image = image
|
10
8
|
end
|
11
9
|
|
10
|
+
# @param width [Fixnum] Image width
|
11
|
+
# @param height [Fixnum] Image height
|
12
12
|
def resize(width:, height:)
|
13
13
|
dimensions = "#{width}x#{height}"
|
14
|
-
|
14
|
+
image.resize(dimensions)
|
15
15
|
end
|
16
16
|
|
17
|
+
# @param ext [String] Image extension
|
18
|
+
# @return [MiniMagick::Image] Instance
|
17
19
|
def format(ext)
|
18
|
-
|
20
|
+
image.format(ext)
|
19
21
|
end
|
20
22
|
|
23
|
+
# @param output [String] Full path to image
|
24
|
+
# @return [String] Full path to image
|
21
25
|
def save(output)
|
22
|
-
|
26
|
+
image.write(output)
|
23
27
|
output
|
24
28
|
end
|
25
29
|
end
|
data/lib/gastly/screenshot.rb
CHANGED
@@ -1,51 +1,46 @@
|
|
1
|
-
require 'phantomjs'
|
2
|
-
require 'active_support/core_ext/hash/keys'
|
3
|
-
require 'active_support/core_ext/object/blank'
|
4
|
-
|
5
1
|
module Gastly
|
6
2
|
class Screenshot
|
7
3
|
SCRIPT_PATH = File.expand_path('../script.js', __FILE__)
|
8
4
|
DEFAULT_TIMEOUT = 0
|
9
5
|
DEFAULT_BROWSER_WIDTH = 1440
|
10
6
|
DEFAULT_BROWSER_HEIGHT = 900
|
11
|
-
DEFAULT_FILE_NAME = 'output'.freeze
|
12
7
|
DEFAULT_FILE_FORMAT = '.png'.freeze
|
13
8
|
|
9
|
+
attr_reader :image
|
14
10
|
attr_writer :timeout, :browser_width, :browser_height
|
15
11
|
attr_accessor :url, :selector, :cookies, :proxy_host, :proxy_port
|
16
|
-
attr_reader :tempfile
|
17
12
|
|
13
|
+
# @param url [String] The full url to the site
|
18
14
|
def initialize(url, **kwargs)
|
19
15
|
kwargs.assert_valid_keys(:timeout, :browser_width, :browser_height, :selector, :cookies, :proxy_host, :proxy_port)
|
20
16
|
|
21
17
|
@url = url
|
22
|
-
@
|
23
|
-
self.cookies = kwargs.delete(:cookies)
|
24
|
-
|
25
|
-
kwargs.each { |key, value| instance_variable_set(:"@#{key}", value) }
|
26
|
-
end
|
27
|
-
|
28
|
-
def timeout
|
29
|
-
@timeout || DEFAULT_TIMEOUT
|
30
|
-
end
|
18
|
+
@cookies = kwargs.delete(:cookies)
|
31
19
|
|
32
|
-
|
33
|
-
@browser_width || DEFAULT_BROWSER_WIDTH
|
34
|
-
end
|
20
|
+
@image = MiniMagick::Image.create(DEFAULT_FILE_FORMAT, false) # Disable validation
|
35
21
|
|
36
|
-
|
37
|
-
@browser_height || DEFAULT_BROWSER_HEIGHT
|
22
|
+
kwargs.each { |key, value| instance_variable_set(:"@#{key}", value) }
|
38
23
|
end
|
39
24
|
|
25
|
+
# Capture image via PhantomJS and save to output file
|
26
|
+
#
|
27
|
+
# @return [Gastly::Image] Instance of Gastly::Image
|
40
28
|
def capture
|
29
|
+
# This necessary to install PhantomJS via proxy
|
41
30
|
Phantomjs.proxy_host = proxy_host if proxy_host
|
42
31
|
Phantomjs.proxy_port = proxy_port if proxy_port
|
43
32
|
|
44
33
|
output = Phantomjs.run(proxy_options, SCRIPT_PATH.to_s, *prepared_params)
|
34
|
+
handle_output(output)
|
45
35
|
|
46
|
-
|
36
|
+
Gastly::Image.new(image)
|
37
|
+
end
|
47
38
|
|
48
|
-
|
39
|
+
%w(timeout browser_width browser_height).each do |name|
|
40
|
+
define_method name do # def timeout
|
41
|
+
instance_variable_get("@#{name}") || # @timeout ||
|
42
|
+
self.class.const_get("default_#{name}".upcase) # self.class.const_get('DEFAULT_TIMEOUT')
|
43
|
+
end # end
|
49
44
|
end
|
50
45
|
|
51
46
|
private
|
@@ -61,23 +56,28 @@ module Gastly
|
|
61
56
|
timeout: timeout,
|
62
57
|
width: browser_width,
|
63
58
|
height: browser_height,
|
64
|
-
output:
|
59
|
+
output: image.path
|
65
60
|
}
|
66
61
|
|
67
62
|
params[:selector] = selector if selector.present?
|
68
|
-
params[:cookies] =
|
63
|
+
params[:cookies] = parameterize(cookies).join(',') if cookies.present?
|
69
64
|
|
70
|
-
|
65
|
+
parameterize(params)
|
71
66
|
end
|
72
67
|
|
73
|
-
|
74
|
-
|
68
|
+
# @param hash [Hash]
|
69
|
+
# @return [Array] Array of parameterized strings
|
70
|
+
def parameterize(hash)
|
71
|
+
hash.map { |key, value| "#{key}=#{value}" }
|
75
72
|
end
|
76
73
|
|
77
|
-
def
|
74
|
+
def handle_output(output)
|
75
|
+
return unless output.present?
|
76
|
+
|
78
77
|
error = case output
|
79
78
|
when /^FetchError:(.+)/ then Gastly::FetchError
|
80
79
|
when /^RuntimeError:(.+)/m then Gastly::PhantomJSError
|
80
|
+
else UnknownError
|
81
81
|
end
|
82
82
|
|
83
83
|
fail error, Regexp.last_match(1)
|
data/lib/gastly/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gastly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikhail Grachev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.4.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.4.0
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: phantomjs2
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,8 +116,10 @@ executables: []
|
|
102
116
|
extensions: []
|
103
117
|
extra_rdoc_files: []
|
104
118
|
files:
|
119
|
+
- ".coveralls.yml"
|
105
120
|
- ".gitignore"
|
106
121
|
- ".rubocop.yml"
|
122
|
+
- ".ruby-version"
|
107
123
|
- ".travis.yml"
|
108
124
|
- CHANGELOG.md
|
109
125
|
- Gemfile
|
@@ -138,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
154
|
version: '0'
|
139
155
|
requirements: []
|
140
156
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.4.5
|
157
|
+
rubygems_version: 2.4.5.1
|
142
158
|
signing_key:
|
143
159
|
specification_version: 4
|
144
160
|
summary: Create screenshots or previews of web pages using Gastly. Gastly, I choose
|