cap_cap 0.0.1
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +2 -0
- data/bin/capcap +3 -0
- data/cap_cap.gemspec +26 -0
- data/lib/cap_cap.rb +91 -0
- data/lib/cap_cap/version.rb +3 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab3f11dc3c4eadc349d9dcdba751bbafeb196e94
|
4
|
+
data.tar.gz: f54b5d8d9792717398f35e9490676bb2a3b09796
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6069a958736ce6aa400b8278605297fd483f1dadb74e4854a742cc4a42397a87d5d6940877a0767c5c646cc79b9e7c17295bd1946c2d1e0e89979fe1bd8cbc1b
|
7
|
+
data.tar.gz: 2527e1e22860c64f6d0c3a9f3f14d66dfca41681b4266c63583176dec7b04b40b285322513074a0399fbf2a3efa7653a6ed78a9b926d5b8d69cb085cf6192638
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Koji NAKAMURA
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# CapCap
|
2
|
+
|
3
|
+
(Cap)ture web pages by using (Cap)ybara and Poltergeist.
|
4
|
+
|
5
|
+
## Installing PhantomJS
|
6
|
+
|
7
|
+
You need PhantomJS. Please see [installation guide](https://github.com/teampoltergeist/poltergeist/blob/master/README.md#installing-phantomjs) on README of Poltergeist.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```
|
12
|
+
$ gem install cap_cap
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```
|
18
|
+
$ capcap
|
19
|
+
Usage: capcap [options] <url> [<url>...]
|
20
|
+
-o, --output=VAL Output capturing image to specific path. If ommited, output to tempfile.
|
21
|
+
-s, --selector=VAL Capture only element specified by css selector. If ommited, capture entire page.
|
22
|
+
-H, --header=VAL Add extra HTTP-header to use when getting a web page.
|
23
|
+
--size=VAL Specify rendering page size. If ommited, it may be default size. e.g., `--size 320x480`
|
24
|
+
--open If specified, invoke `open` command to preview captured image.
|
25
|
+
```
|
26
|
+
|
27
|
+
## Dependency gems
|
28
|
+
|
29
|
+
- [Capybara](https://github.com/jnicklas/capybara)
|
30
|
+
- [Poltergeist](https://github.com/teampoltergeist/poltergeistJ)
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( https://github.com/kozy4324/cap_cap/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/capcap
ADDED
data/cap_cap.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cap_cap/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cap_cap"
|
8
|
+
spec.version = CapCap::VERSION
|
9
|
+
spec.authors = ["Koji NAKAMURA"]
|
10
|
+
spec.email = ["kozy4324@gmail.com"]
|
11
|
+
spec.summary = %q{(Cap)ture web pages by using (Cap)ybara and Poltergeist.}
|
12
|
+
spec.description = %q{(Cap)ture web pages by using (Cap)ybara and Poltergeist.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "capybara", "~> 2.4"
|
22
|
+
spec.add_dependency "poltergeist", "~> 1.6"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
data/lib/cap_cap.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require "tempfile"
|
2
|
+
require "optparse"
|
3
|
+
|
4
|
+
require "capybara"
|
5
|
+
require "capybara/poltergeist"
|
6
|
+
|
7
|
+
require "cap_cap/version"
|
8
|
+
|
9
|
+
Capybara.register_driver :poltergeist do |app|
|
10
|
+
opt = {
|
11
|
+
phantomjs_logger: File.open(File::NULL, "w"),
|
12
|
+
js_errors: false,
|
13
|
+
phantomjs_options: [
|
14
|
+
'--ignore-ssl-errors=true', # Enable access to the local env which has invalid ssl certificate
|
15
|
+
'--web-security=false', # Suppress warnings caused by adlantis js
|
16
|
+
]
|
17
|
+
}
|
18
|
+
opt[:logger] = File.open(ENV["POLTERGEIST_LOG"], "w") unless ENV["POLTERGEIST_LOG"].nil?
|
19
|
+
Capybara::Poltergeist::Driver.new(app, opt)
|
20
|
+
end
|
21
|
+
Capybara.default_driver = :poltergeist
|
22
|
+
|
23
|
+
module CapCap
|
24
|
+
def CapCap.run
|
25
|
+
opts = {headers: []}
|
26
|
+
opt = OptionParser.new
|
27
|
+
opt.banner = "Usage: capcap [options] <url> [<url>...]"
|
28
|
+
opt.on("-o", "--output=VAL", "Output capturing image to specific path. If ommited, output to tempfile.") {|v| opts[:output] = v }
|
29
|
+
opt.on("-s", "--selector=VAL", "Capture only element specified by css selector. If ommited, capture entire page.") {|v| opts[:selector] = v }
|
30
|
+
opt.on("-H", "--header=VAL", "Add extra HTTP-header to use when getting a web page.") {|v| opts[:headers] << v }
|
31
|
+
opt.on("--size=VAL", "Specify rendering page size. If ommited, it may be default size. e.g., `--size 320x480`") {|v| opts[:size] = v.split(?x).map(&:to_i) }
|
32
|
+
opt.on("--open", "If specified, invoke `open` command to preview captured image.") {|v| opts[:invoke_open] = v }
|
33
|
+
opt.parse! ARGV
|
34
|
+
|
35
|
+
main = Main.new
|
36
|
+
main.resize *opts[:size] unless opts[:size].nil?
|
37
|
+
if opts[:headers].size > 0
|
38
|
+
main.add_headers Hash[opts[:headers].map {|v| v.split(?:).map{|kv| kv.strip } }]
|
39
|
+
end
|
40
|
+
|
41
|
+
if ARGV.empty?
|
42
|
+
puts opt.help
|
43
|
+
exit
|
44
|
+
elsif ARGV.size == 1
|
45
|
+
output = main.capture ARGV.first, opts[:output], selector: opts[:selector]
|
46
|
+
main.invoke_open output if opts[:invoke_open]
|
47
|
+
else
|
48
|
+
outputs = ARGV.map {|url| main.capture url, selector: opts[:selector] }
|
49
|
+
output = main.capture_combined outputs, opts[:output]
|
50
|
+
main.invoke_open output if opts[:invoke_open]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Main
|
55
|
+
include Capybara::DSL
|
56
|
+
|
57
|
+
def capture url, output = nil, selector: nil
|
58
|
+
visit url
|
59
|
+
output = Tempfile.open(["capcap", ".png"]).path if output.nil?
|
60
|
+
opt = if selector.nil? then {full: true} else {selector: selector} end
|
61
|
+
save_screenshot output, opt
|
62
|
+
output
|
63
|
+
end
|
64
|
+
|
65
|
+
def invoke_open path
|
66
|
+
`open #{path}`
|
67
|
+
sleep 2
|
68
|
+
end
|
69
|
+
|
70
|
+
def capture_combined outputs, output = nil
|
71
|
+
visit "about:blank"
|
72
|
+
output = Tempfile.open(["capcap", ".png"]).path if output.nil?
|
73
|
+
|
74
|
+
imgs = outputs.map {|src| %Q|<img src="file://#{src}" />| }
|
75
|
+
html = %Q|<table id="canvas" border=0><tr><td valign=top>#{imgs.join("</td><td valign=top>")}</td></tr></table>|
|
76
|
+
script = %Q|document.body.innerHTML = '#{html}';|
|
77
|
+
evaluate_script script
|
78
|
+
|
79
|
+
save_screenshot output, selector: "#canvas"
|
80
|
+
output
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_headers headers
|
84
|
+
page.driver.add_headers headers
|
85
|
+
end
|
86
|
+
|
87
|
+
def resize w, h
|
88
|
+
page.driver.resize w, h
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cap_cap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Koji NAKAMURA
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capybara
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: poltergeist
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: "(Cap)ture web pages by using (Cap)ybara and Poltergeist."
|
70
|
+
email:
|
71
|
+
- kozy4324@gmail.com
|
72
|
+
executables:
|
73
|
+
- capcap
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/capcap
|
83
|
+
- cap_cap.gemspec
|
84
|
+
- lib/cap_cap.rb
|
85
|
+
- lib/cap_cap/version.rb
|
86
|
+
homepage: ''
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.4.5
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: "(Cap)ture web pages by using (Cap)ybara and Poltergeist."
|
110
|
+
test_files: []
|