gastly 0.2.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -3
- data/CHANGELOG.md +25 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/README.md +12 -6
- data/Rakefile +5 -0
- data/gastly.gemspec +8 -6
- data/lib/gastly.rb +5 -0
- data/lib/gastly/exceptions.rb +1 -2
- data/lib/gastly/image.rb +22 -9
- data/lib/gastly/phantomjs_patch.rb +85 -0
- data/lib/gastly/screenshot.rb +40 -34
- data/lib/gastly/utils.rb +2 -0
- data/lib/gastly/utils/hash.rb +29 -0
- data/lib/gastly/utils/string.rb +36 -0
- data/lib/gastly/version.rb +1 -1
- metadata +33 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7825b37663690656b92aeb9ff48ac57461fe1ca1
|
4
|
+
data.tar.gz: a00e6b600dbc19b77d9502d5b4f30ad70e8a3ade
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9f8daf6095af2e710a48817ccbc1c5cfb3a86bd9fddcba753c86a620b73473610beac22dcc686fc058da161a2b5a49ac64dfbf0dac02c77e29227ef8368c1bc
|
7
|
+
data.tar.gz: 2948a1bcd65853becc73a7073f2eeba0f35e2c1006eb6767ce3136a83201c4e22a18ce71b404b77674113db8b8be14a4cab46ee05aeb09de09f71ade3ce94cd8
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: Yl4eB6CrBH8Jq6D02bBV5MxCtrNfDGP4L
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.4
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
## 1.0.1 (02/11/2016)
|
2
|
+
|
3
|
+
### Enhancements
|
4
|
+
|
5
|
+
* Added ability to send CLI options to PhantomJS ([#6](https://github.com/mgrachev/gastly/pull/6))
|
6
|
+
* Required ruby version is 2.1.0 or higher
|
7
|
+
|
8
|
+
## 1.0.0 (16/07/2016)
|
9
|
+
|
10
|
+
### Enhancements
|
11
|
+
|
12
|
+
* Remove support ActiveSupport
|
13
|
+
|
14
|
+
## 0.3.0 (29/01/2016)
|
15
|
+
|
16
|
+
### Enhancements
|
17
|
+
|
18
|
+
* Update PhantomJS version to 2.1.1
|
19
|
+
|
20
|
+
## 0.2.4 (24/01/2016)
|
21
|
+
|
22
|
+
### Enhancements
|
23
|
+
|
24
|
+
* Code optimization
|
25
|
+
|
1
26
|
## 0.2.3 (23/11/2015)
|
2
27
|
|
3
28
|
### Enhancements
|
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Grachev Mikhail
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-
# Gastly
|
1
|
+
# 👻 Gastly
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/gastly.svg)](http://badge.fury.io/rb/gastly)
|
4
4
|
[![Dependency Status](https://gemnasium.com/mgrachev/gastly.svg)](https://gemnasium.com/mgrachev/gastly)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/mgrachev/gastly/badges/gpa.svg)](https://codeclimate.com/github/mgrachev/gastly)
|
6
|
+
[![Build Status](https://travis-ci.org/mgrachev/gastly.svg?branch=master)](https://travis-ci.org/mgrachev/gastly)
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/github/mgrachev/gastly/badge.svg?branch=master)](https://coveralls.io/github/mgrachev/gastly?branch=master)
|
6
8
|
|
7
|
-
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).
|
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).
|
10
|
+
|
11
|
+
Gastly, I choose you!
|
8
12
|
|
9
13
|
![Gastly](https://github.com/mgrachev/gastly/raw/master/gastly.png)
|
10
14
|
|
@@ -30,7 +34,7 @@ Or install it yourself as:
|
|
30
34
|
Gastly.capture('http://google.com', 'output.png')
|
31
35
|
```
|
32
36
|
|
33
|
-
It
|
37
|
+
It's also possible to further customize the creation of screenshots and further processing of the resulting image:
|
34
38
|
|
35
39
|
```ruby
|
36
40
|
screenshot = Gastly.screenshot('http://google.com')
|
@@ -41,6 +45,7 @@ screenshot.timeout = 1000 # Default: 0 seconds
|
|
41
45
|
screenshot.cookies = { user_id: 1, auth_token: 'abcd' } # If you need
|
42
46
|
screenshot.proxy_host = '10.10.10.1' # If you want to use a http proxy
|
43
47
|
screenshot.proxy_port = '8080'
|
48
|
+
screenshot.phantomjs_options = '--ignore-ssl-errors=true'
|
44
49
|
image = screenshot.capture
|
45
50
|
```
|
46
51
|
|
@@ -51,11 +56,12 @@ screenshot = Gastly.screenshot('http://google.com', selector: '#hplogo', timeout
|
|
51
56
|
image = screenshot.capture
|
52
57
|
```
|
53
58
|
|
54
|
-
You can resize or change the format of the screenshot:
|
59
|
+
You can resize, crop or change the format of the screenshot:
|
55
60
|
|
56
61
|
```ruby
|
57
62
|
image = screenshot.capture
|
58
|
-
image.
|
63
|
+
image.crop(width: 250, height: 250, x: 10, y: 0) # Crop with an offset
|
64
|
+
image.resize(width: 110, height: 110) # Creates a preview of the web page
|
59
65
|
image.format('png')
|
60
66
|
image.save('output.png')
|
61
67
|
```
|
@@ -68,7 +74,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
68
74
|
|
69
75
|
## Contributing
|
70
76
|
|
71
|
-
1. Fork it ( https://github.com/
|
77
|
+
1. Fork it ( https://github.com/mgrachev/gastly/fork )
|
72
78
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
73
79
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
74
80
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
data/gastly.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
4
|
+
require 'gastly/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'gastly'
|
@@ -18,11 +18,13 @@ 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.
|
22
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
-
spec.add_development_dependency 'rubocop'
|
21
|
+
spec.required_ruby_version = '>= 2.1.0'
|
24
22
|
|
25
|
-
spec.
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
25
|
+
spec.add_development_dependency 'rubocop', '0.68'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.4.0'
|
27
|
+
|
28
|
+
spec.add_dependency 'phantomjs', '~> 2.1.1'
|
26
29
|
spec.add_dependency 'mini_magick', '~> 4.2'
|
27
|
-
spec.add_dependency 'activesupport', '>= 3.1'
|
28
30
|
end
|
data/lib/gastly.rb
CHANGED
data/lib/gastly/exceptions.rb
CHANGED
data/lib/gastly/image.rb
CHANGED
@@ -1,25 +1,38 @@
|
|
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
|
+
end
|
16
|
+
|
17
|
+
# @param width [Fixnum] Crop width
|
18
|
+
# @param height [Fixnum] Crop height
|
19
|
+
# @param x [Fixnum] Crop x offset
|
20
|
+
# @param y [Fixnum] Crop y offset
|
21
|
+
def crop(width:, height:, x:, y:)
|
22
|
+
dimensions = "#{width}x#{height}+#{x}+#{y}"
|
23
|
+
image.crop(dimensions)
|
15
24
|
end
|
16
25
|
|
26
|
+
# @param ext [String] Image extension
|
27
|
+
# @return [MiniMagick::Image] Instance
|
17
28
|
def format(ext)
|
18
|
-
|
29
|
+
image.format(ext)
|
19
30
|
end
|
20
31
|
|
32
|
+
# @param output [String] Full path to image
|
33
|
+
# @return [String] Full path to image
|
21
34
|
def save(output)
|
22
|
-
|
35
|
+
image.write(output)
|
23
36
|
output
|
24
37
|
end
|
25
38
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Phantomjs
|
2
|
+
class << self
|
3
|
+
attr_accessor :proxy_host, :proxy_port
|
4
|
+
end
|
5
|
+
|
6
|
+
class Platform
|
7
|
+
RETRY_COUNT = 5
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def install!
|
11
|
+
STDERR.puts "Phantomjs does not appear to be installed in #{phantomjs_path}, installing!"
|
12
|
+
FileUtils.mkdir_p Phantomjs.base_dir
|
13
|
+
|
14
|
+
# Purge temporary directory if it is still hanging around from previous installs,
|
15
|
+
# then re-create it.
|
16
|
+
temp_dir = File.join(temp_path, 'phantomjs_install')
|
17
|
+
FileUtils.rm_rf temp_dir
|
18
|
+
FileUtils.mkdir_p temp_dir
|
19
|
+
|
20
|
+
Dir.chdir temp_dir do
|
21
|
+
unless download_via_curl || download_via_wget
|
22
|
+
fail "\n\nFailed to load phantomjs! :(\nYou need to have cURL or wget installed on your system.\nIf you have, the source of phantomjs might be unavailable: #{package_url}\n\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
case package_url.split('.').last
|
26
|
+
when 'bz2'
|
27
|
+
system "bunzip2 #{File.basename(package_url)}"
|
28
|
+
system "tar xf #{File.basename(package_url).sub(/\.bz2$/, '')}"
|
29
|
+
when 'zip'
|
30
|
+
system "unzip #{File.basename(package_url)}"
|
31
|
+
else
|
32
|
+
fail "Unknown compression format for #{File.basename(package_url)}"
|
33
|
+
end
|
34
|
+
|
35
|
+
# Find the phantomjs build we just extracted
|
36
|
+
extracted_dir = Dir['phantomjs*'].find { |path| File.directory?(path) }
|
37
|
+
|
38
|
+
if extracted_dir.nil?
|
39
|
+
# Move the executable file
|
40
|
+
FileUtils.mkdir_p File.join(Phantomjs.base_dir, platform, 'bin')
|
41
|
+
if FileUtils.mv 'phantomjs', File.join(Phantomjs.base_dir, platform, 'bin')
|
42
|
+
STDOUT.puts "\nSuccessfully installed phantomjs. Yay!"
|
43
|
+
end
|
44
|
+
else
|
45
|
+
# Move the extracted phantomjs build to $HOME/.phantomjs/version/platform
|
46
|
+
if FileUtils.mv extracted_dir, File.join(Phantomjs.base_dir, platform)
|
47
|
+
STDOUT.puts "\nSuccessfully installed phantomjs. Yay!"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Clean up remaining files in tmp
|
52
|
+
if FileUtils.rm_rf temp_dir
|
53
|
+
STDOUT.puts 'Removed temporarily downloaded files.'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
fail 'Failed to install phantomjs. Sorry :(' unless File.exist?(phantomjs_path)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def download_via_curl
|
63
|
+
system "curl -L --retry #{RETRY_COUNT} -O #{package_url} #{curl_proxy_options}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def download_via_wget
|
67
|
+
system "wget -t #{RETRY_COUNT} #{package_url} #{wget_proxy_options}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def curl_proxy_options
|
71
|
+
return '' if proxy_options_exist?
|
72
|
+
"-x #{Phantomjs.proxy_host}:#{Phantomjs.proxy_port}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def wget_proxy_options
|
76
|
+
return '' if proxy_options_exist?
|
77
|
+
"-e use_proxy=yes -e http_proxy=#{Phantomjs.proxy_host}:#{Phantomjs.proxy_port}"
|
78
|
+
end
|
79
|
+
|
80
|
+
def proxy_options_exist?
|
81
|
+
Phantomjs.proxy_host.nil? && Phantomjs.proxy_port.nil?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/gastly/screenshot.rb
CHANGED
@@ -1,57 +1,57 @@
|
|
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
|
-
attr_accessor :url, :selector, :cookies, :proxy_host, :proxy_port
|
16
|
-
attr_reader :tempfile
|
11
|
+
attr_accessor :url, :selector, :cookies, :proxy_host, :proxy_port, :phantomjs_options
|
17
12
|
|
13
|
+
# @param url [String] The full url to the site
|
18
14
|
def initialize(url, **kwargs)
|
19
|
-
|
15
|
+
hash = Gastly::Utils::Hash.new(kwargs)
|
16
|
+
hash.assert_valid_keys(:timeout, :browser_width, :browser_height, :selector, :cookies, :proxy_host, :proxy_port, :phantomjs_options)
|
20
17
|
|
21
18
|
@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
|
19
|
+
@cookies = kwargs.delete(:cookies)
|
31
20
|
|
32
|
-
|
33
|
-
@browser_width || DEFAULT_BROWSER_WIDTH
|
34
|
-
end
|
21
|
+
@image = MiniMagick::Image.create(DEFAULT_FILE_FORMAT, false) # Disable validation
|
35
22
|
|
36
|
-
|
37
|
-
@browser_height || DEFAULT_BROWSER_HEIGHT
|
23
|
+
kwargs.each { |key, value| instance_variable_set(:"@#{key}", value) }
|
38
24
|
end
|
39
25
|
|
26
|
+
# Capture image via PhantomJS and save to output file
|
27
|
+
#
|
28
|
+
# @return [Gastly::Image] Instance of Gastly::Image
|
40
29
|
def capture
|
30
|
+
# This necessary to install PhantomJS via proxy
|
41
31
|
Phantomjs.proxy_host = proxy_host if proxy_host
|
42
32
|
Phantomjs.proxy_port = proxy_port if proxy_port
|
43
33
|
|
44
|
-
output = Phantomjs.run(
|
34
|
+
output = Phantomjs.run(options, SCRIPT_PATH.to_s, *prepared_params)
|
35
|
+
handle_output(output)
|
45
36
|
|
46
|
-
|
37
|
+
Gastly::Image.new(image)
|
38
|
+
end
|
47
39
|
|
48
|
-
|
40
|
+
%w(timeout browser_width browser_height).each do |name|
|
41
|
+
define_method name do # def timeout
|
42
|
+
instance_variable_get("@#{name}") || # @timeout ||
|
43
|
+
self.class.const_get("default_#{name}".upcase) # self.class.const_get('DEFAULT_TIMEOUT')
|
44
|
+
end # end
|
49
45
|
end
|
50
46
|
|
51
47
|
private
|
52
48
|
|
49
|
+
def options
|
50
|
+
[proxy_options, phantomjs_options].join(' ').strip
|
51
|
+
end
|
52
|
+
|
53
53
|
def proxy_options
|
54
|
-
return '' if proxy_host.
|
54
|
+
return '' if proxy_host.nil? && proxy_port.nil?
|
55
55
|
"--proxy=#{proxy_host}:#{proxy_port}"
|
56
56
|
end
|
57
57
|
|
@@ -61,23 +61,29 @@ module Gastly
|
|
61
61
|
timeout: timeout,
|
62
62
|
width: browser_width,
|
63
63
|
height: browser_height,
|
64
|
-
output:
|
64
|
+
output: image.path
|
65
65
|
}
|
66
66
|
|
67
|
-
params[:selector] = selector if selector
|
68
|
-
params[:cookies] =
|
67
|
+
params[:selector] = selector if selector
|
68
|
+
params[:cookies] = parameterize(cookies).join(',') if cookies
|
69
69
|
|
70
|
-
|
70
|
+
parameterize(params)
|
71
71
|
end
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
# @param hash [Hash]
|
74
|
+
# @return [Array] Array of parameterized strings
|
75
|
+
def parameterize(hash)
|
76
|
+
hash.map { |key, value| "#{key}=#{value}" }
|
75
77
|
end
|
76
78
|
|
77
|
-
def
|
78
|
-
|
79
|
+
def handle_output(out)
|
80
|
+
output = Gastly::Utils::String.new(out)
|
81
|
+
return unless output.present?
|
82
|
+
|
83
|
+
error = case output.string
|
79
84
|
when /^FetchError:(.+)/ then Gastly::FetchError
|
80
85
|
when /^RuntimeError:(.+)/m then Gastly::PhantomJSError
|
86
|
+
else UnknownError
|
81
87
|
end
|
82
88
|
|
83
89
|
fail error, Regexp.last_match(1)
|
data/lib/gastly/utils.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Gastly
|
2
|
+
module Utils
|
3
|
+
class Hash
|
4
|
+
attr_reader :hash
|
5
|
+
|
6
|
+
def initialize(hash = {})
|
7
|
+
@hash = hash.to_h
|
8
|
+
end
|
9
|
+
|
10
|
+
# Validates all keys in a hash match <tt>*valid_keys</tt>, raising
|
11
|
+
# +ArgumentError+ on a mismatch.
|
12
|
+
#
|
13
|
+
# Note that keys are treated differently than HashWithIndifferentAccess,
|
14
|
+
# meaning that string and symbol keys will not match.
|
15
|
+
#
|
16
|
+
# { name: 'Rob', years: '28' }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key: :years. Valid keys are: :name, :age"
|
17
|
+
# { name: 'Rob', age: '28' }.assert_valid_keys('name', 'age') # => raises "ArgumentError: Unknown key: :name. Valid keys are: 'name', 'age'"
|
18
|
+
# { name: 'Rob', age: '28' }.assert_valid_keys(:name, :age) # => passes, raises nothing
|
19
|
+
def assert_valid_keys(*valid_keys)
|
20
|
+
valid_keys.flatten!
|
21
|
+
hash.each_key do |k|
|
22
|
+
unless valid_keys.include?(k)
|
23
|
+
fail ArgumentError.new("Unknown key: #{k.inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(', ')}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Gastly
|
2
|
+
module Utils
|
3
|
+
class String
|
4
|
+
BLANK_RE = /\A[[:space:]]*\z/
|
5
|
+
|
6
|
+
attr_reader :string
|
7
|
+
|
8
|
+
def initialize(string = '')
|
9
|
+
@string = string.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
# A string is blank if it's empty or contains whitespaces only:
|
13
|
+
#
|
14
|
+
# ''.blank? # => true
|
15
|
+
# ' '.blank? # => true
|
16
|
+
# "\t\n\r".blank? # => true
|
17
|
+
# ' blah '.blank? # => false
|
18
|
+
#
|
19
|
+
# Unicode whitespace is supported:
|
20
|
+
#
|
21
|
+
# "\u00a0".blank? # => true
|
22
|
+
#
|
23
|
+
# @return [true, false]
|
24
|
+
def blank?
|
25
|
+
BLANK_RE === string
|
26
|
+
end
|
27
|
+
|
28
|
+
# An object is present if it's not blank.
|
29
|
+
#
|
30
|
+
# @return [true, false]
|
31
|
+
def present?
|
32
|
+
!blank?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/gastly/version.rb
CHANGED
metadata
CHANGED
@@ -1,99 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gastly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
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: 2020-08-27 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
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '12.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '12.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rubocop
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '0.68'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '0.68'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
type: :
|
61
|
+
version: 3.4.0
|
62
|
+
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 3.4.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: phantomjs
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 2.1.1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 2.1.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: mini_magick
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '4.2'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '4.2'
|
97
97
|
description: Create screenshots or previews of web pages using Gastly. Under the hood
|
98
98
|
Phantom.js and MiniMagick.
|
99
99
|
email:
|
@@ -102,11 +102,14 @@ executables: []
|
|
102
102
|
extensions: []
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
|
+
- ".coveralls.yml"
|
105
106
|
- ".gitignore"
|
106
107
|
- ".rubocop.yml"
|
108
|
+
- ".ruby-version"
|
107
109
|
- ".travis.yml"
|
108
110
|
- CHANGELOG.md
|
109
111
|
- Gemfile
|
112
|
+
- LICENSE
|
110
113
|
- README.md
|
111
114
|
- Rakefile
|
112
115
|
- bin/console
|
@@ -116,8 +119,12 @@ files:
|
|
116
119
|
- lib/gastly.rb
|
117
120
|
- lib/gastly/exceptions.rb
|
118
121
|
- lib/gastly/image.rb
|
122
|
+
- lib/gastly/phantomjs_patch.rb
|
119
123
|
- lib/gastly/screenshot.rb
|
120
124
|
- lib/gastly/script.js
|
125
|
+
- lib/gastly/utils.rb
|
126
|
+
- lib/gastly/utils/hash.rb
|
127
|
+
- lib/gastly/utils/string.rb
|
121
128
|
- lib/gastly/version.rb
|
122
129
|
homepage: https://github.com/mgrachev/gastly
|
123
130
|
licenses: []
|
@@ -130,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
137
|
requirements:
|
131
138
|
- - ">="
|
132
139
|
- !ruby/object:Gem::Version
|
133
|
-
version:
|
140
|
+
version: 2.1.0
|
134
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
142
|
requirements:
|
136
143
|
- - ">="
|
@@ -138,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
145
|
version: '0'
|
139
146
|
requirements: []
|
140
147
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.6.3
|
142
149
|
signing_key:
|
143
150
|
specification_version: 4
|
144
151
|
summary: Create screenshots or previews of web pages using Gastly. Gastly, I choose
|