gastly 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 +4 -4
- data/.rubocop.yml +27 -0
- data/.travis.yml +4 -1
- data/CHANGELOG.md +7 -1
- data/README.md +6 -2
- data/Rakefile +1 -1
- data/gastly.gemspec +3 -2
- data/lib/gastly.rb +1 -2
- data/lib/gastly/exceptions.rb +2 -2
- data/lib/gastly/image.rb +1 -3
- data/lib/gastly/screenshot.rb +2 -4
- data/lib/gastly/script.js +69 -65
- data/lib/gastly/version.rb +2 -2
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a44ef15ac998bc80a529ceb87f868e53c8ce61bf
|
4
|
+
data.tar.gz: 75a64b654c9031160a85aff58f5ef47b2f1add23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d110af0420f000a7851a1c21855ec111d4924ce34df3b5677fb8db1c57835fc541a96596e5f2c5fc1366955ba16b69a4df1c66db9ec5a40d25430cadc18ad78
|
7
|
+
data.tar.gz: 83e1dd27eb9f8122bc86764c03a2c837f512742300d86e905b188fe3f934e2e60139e091b0d0ae43d4122f2b76c0c1966448efdf46c2eb435d33522dae397da0
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
AllCops:
|
2
|
+
# Cop names are not displayed in offense messages by default. Change behavior
|
3
|
+
# by overriding DisplayCopNames, or by giving the -D/--display-cop-names
|
4
|
+
# option.
|
5
|
+
DisplayCopNames: true
|
6
|
+
# Style guide URLs are not displayed in offense messages by default. Change
|
7
|
+
# behavior by overriding DisplayStyleGuide, or by giving the
|
8
|
+
# -S/--display-style-guide option.
|
9
|
+
DisplayStyleGuide: true
|
10
|
+
Exclude:
|
11
|
+
- 'bin/**/*'
|
12
|
+
- 'spec/**/*'
|
13
|
+
- 'vendor/**/*'
|
14
|
+
|
15
|
+
# Missing top-level class documentation comment
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
# Line is too long
|
20
|
+
# https://github.com/bbatsov/ruby-style-guide#80-character-limits
|
21
|
+
Metrics/LineLength:
|
22
|
+
Max: 180 # 80
|
23
|
+
|
24
|
+
# Assignment Branch Condition size for perform is too high
|
25
|
+
# http://c2.com/cgi/wiki?AbcMetric
|
26
|
+
Metrics/AbcSize:
|
27
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Gastly
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/gastly.svg)](http://badge.fury.io/rb/gastly)
|
4
|
+
[![Dependency Status](https://gemnasium.com/mgrachev/gastly.svg)](https://gemnasium.com/mgrachev/gastly)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/mgrachev/gastly/badges/gpa.svg)](https://codeclimate.com/github/mgrachev/gastly)
|
6
|
+
|
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). Gastly, I choose you!
|
4
8
|
|
5
9
|
![Gastly](https://github.com/mgrachev/gastly/raw/master/gastly.png)
|
6
10
|
|
@@ -35,7 +39,7 @@ screenshot.browser_width = 1280 # Default: 1440px
|
|
35
39
|
screenshot.browser_height = 780 # Default: 900px
|
36
40
|
screenshot.timeout = 1000 # Default: 0 seconds
|
37
41
|
screenshot.cookies = { user_id: 1, auth_token: 'abcd' } # If you need
|
38
|
-
screenshot.proxy_host = '10.10.10.1' # If you want to use a proxy
|
42
|
+
screenshot.proxy_host = '10.10.10.1' # If you want to use a http proxy
|
39
43
|
screenshot.proxy_port = '8080'
|
40
44
|
image = screenshot.capture
|
41
45
|
```
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
data/gastly.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['Mikhail Grachev']
|
10
10
|
spec.email = ['work@mgrachev.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
12
|
+
spec.summary = 'Create screenshots or previews of web pages using Gastly. Gastly, I choose you!'
|
13
|
+
spec.description = 'Create screenshots or previews of web pages using Gastly. Under the hood Phantom.js and MiniMagick.'
|
14
14
|
spec.homepage = 'https://github.com/mgrachev/gastly'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.9'
|
22
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rubocop'
|
23
24
|
|
24
25
|
spec.add_dependency 'phantomjs2', '~> 2.0'
|
25
26
|
spec.add_dependency 'mini_magick', '~> 4.2'
|
data/lib/gastly.rb
CHANGED
@@ -4,7 +4,6 @@ require_relative 'gastly/exceptions'
|
|
4
4
|
require_relative 'gastly/version'
|
5
5
|
|
6
6
|
module Gastly
|
7
|
-
|
8
7
|
def screenshot(url, **kwargs)
|
9
8
|
Screenshot.new(url, **kwargs)
|
10
9
|
end
|
@@ -14,4 +13,4 @@ module Gastly
|
|
14
13
|
end
|
15
14
|
|
16
15
|
module_function :screenshot, :capture
|
17
|
-
end
|
16
|
+
end
|
data/lib/gastly/exceptions.rb
CHANGED
data/lib/gastly/image.rb
CHANGED
data/lib/gastly/screenshot.rb
CHANGED
@@ -4,7 +4,6 @@ require 'active_support/core_ext/object/blank'
|
|
4
4
|
|
5
5
|
module Gastly
|
6
6
|
class Screenshot
|
7
|
-
|
8
7
|
SCRIPT_PATH = File.expand_path('../script.js', __FILE__)
|
9
8
|
DEFAULT_TIMEOUT = 0
|
10
9
|
DEFAULT_BROWSER_WIDTH = 1440
|
@@ -81,8 +80,7 @@ module Gastly
|
|
81
80
|
when /^RuntimeError:(.+)/m then Gastly::PhantomJSError
|
82
81
|
end
|
83
82
|
|
84
|
-
|
83
|
+
fail error, Regexp.last_match(1)
|
85
84
|
end
|
86
|
-
|
87
85
|
end
|
88
|
-
end
|
86
|
+
end
|
data/lib/gastly/script.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
function extractDomain(url){
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
2
|
+
var domain;
|
3
|
+
// Remove protocol
|
4
|
+
if (url.indexOf("://") > -1) {
|
5
|
+
domain = url.split('/')[2];
|
6
|
+
} else {
|
7
|
+
domain = url.split('/')[0];
|
8
|
+
}
|
9
|
+
// Remove port number
|
10
|
+
domain = domain.split(':')[0];
|
11
|
+
|
12
|
+
return domain;
|
13
13
|
}
|
14
14
|
|
15
15
|
var i, pair,
|
@@ -18,72 +18,76 @@ var i, pair,
|
|
18
18
|
page = require('webpage').create();
|
19
19
|
|
20
20
|
system.args.forEach(function(arg) {
|
21
|
-
|
22
|
-
|
21
|
+
pair = arg.split(/=(.*)/);
|
22
|
+
args[pair[0]] = pair[1];
|
23
23
|
});
|
24
24
|
|
25
25
|
if (args.cookies !== undefined) {
|
26
|
-
|
26
|
+
var cookiesPair = args.cookies.split(',');
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
cookiesPair.forEach(function(cookie) {
|
29
|
+
pair = cookie.split(/=(.*)/);
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
});
|
31
|
+
page.addCookie({
|
32
|
+
'name': pair[0],
|
33
|
+
'value': pair[1],
|
34
|
+
'path': '/',
|
35
|
+
'domain': extractDomain(args.url)
|
37
36
|
});
|
37
|
+
});
|
38
38
|
}
|
39
39
|
|
40
40
|
phantom.onError = function(message, trace){
|
41
|
-
|
41
|
+
var messageStack = ['RuntimeError:' + message];
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
if (trace && trace.length) {
|
44
|
+
messageStack.push('Trace:');
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
trace.forEach(function(t) {
|
47
|
+
messageStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
|
48
|
+
});
|
49
|
+
}
|
50
50
|
|
51
|
-
|
52
|
-
|
51
|
+
console.log(messageStack.join('\n'));
|
52
|
+
phantom.exit(1);
|
53
53
|
}
|
54
54
|
|
55
|
+
// Suppress client errors
|
56
|
+
page.onError = function(message, trace){
|
57
|
+
};
|
58
|
+
|
55
59
|
page.open(args.url, function(status){
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
});
|
60
|
+
if(status !== 'success') {
|
61
|
+
console.log('FetchError:' + args.url);
|
62
|
+
phantom.exit();
|
63
|
+
} else {
|
64
|
+
window.setTimeout(function(){
|
65
|
+
page.viewportSize = { width: args.width, height: args.height };
|
66
|
+
|
67
|
+
if (args.selector !== undefined){
|
68
|
+
// Returns ClientRect object or null if selector not found
|
69
|
+
var clipRect = page.evaluate(function(s){
|
70
|
+
var result, selector = document.querySelector(s);
|
71
|
+
|
72
|
+
if (selector !== null) {
|
73
|
+
result = selector.getBoundingClientRect();
|
74
|
+
}
|
75
|
+
|
76
|
+
return result;
|
77
|
+
}, args.selector);
|
78
|
+
|
79
|
+
if (clipRect !== null) {
|
80
|
+
page.clipRect = {
|
81
|
+
top: clipRect.top,
|
82
|
+
left: clipRect.left,
|
83
|
+
width: clipRect.width,
|
84
|
+
height: clipRect.height
|
85
|
+
};
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
page.render(args.output);
|
90
|
+
phantom.exit();
|
91
|
+
}, args.timeout);
|
92
|
+
}
|
93
|
+
});
|
data/lib/gastly/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Gastly
|
2
|
-
VERSION = '0.2.
|
3
|
-
end
|
2
|
+
VERSION = '0.2.3'
|
3
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikhail Grachev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: phantomjs2
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,6 +103,7 @@ extensions: []
|
|
89
103
|
extra_rdoc_files: []
|
90
104
|
files:
|
91
105
|
- ".gitignore"
|
106
|
+
- ".rubocop.yml"
|
92
107
|
- ".travis.yml"
|
93
108
|
- CHANGELOG.md
|
94
109
|
- Gemfile
|
@@ -123,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
138
|
version: '0'
|
124
139
|
requirements: []
|
125
140
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.4.
|
141
|
+
rubygems_version: 2.4.5
|
127
142
|
signing_key:
|
128
143
|
specification_version: 4
|
129
144
|
summary: Create screenshots or previews of web pages using Gastly. Gastly, I choose
|