phantomjs.rb 0.0.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGELOG +4 -0
- data/README.md +9 -9
- data/lib/phantomjs.rb +15 -47
- data/lib/phantomjs/errors.rb +7 -0
- data/lib/phantomjs/version.rb +2 -2
- data/phantomjs.rb.gemspec +0 -7
- data/spec/phantomjs_spec.rb +19 -0
- metadata +7 -49
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzhkY2U5YjQ1ZDM0YWE1NGY3NDIzMTczMjBmNTQzMTdlZTYyZmRkZg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YWZiY2JjYWFiNzRkMTZiMjQzYmU3YWM3ODQ3YzZlMzdkMzNjYzU3MA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODhjMDQ4ZDVlNWViMDViMWViODQ2ZDdhYmNhMjM3ZTZmODE5Nzg4MzVlNzc5
|
10
|
+
MmJhODU3OTQzOGE4NTk3NTY2NzFhZWU4YzQ3ZDkwNzNlMDJmYmZjMmM2OTk1
|
11
|
+
YjQ3Y2MzYTUyY2VlNjY4M2NiZTVlYmMyOTJmZGZjMjVmN2JlY2Y=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTlmMDFmZjlhYTcwMTAyODRjODczODBlYzhmOGIzOGI1NWQ1YjFhMTBiNjc1
|
14
|
+
ZWE5MmNiZTdiNzcwNGU5NTQzYTIyNDg0ZTI3MmEzMmEyZmJjYWQ5MjFjMDU0
|
15
|
+
N2E0NDNkYjVlZjk1ZTAxMTU1MmIzNGE4Y2FhOGFmZTczYzczNDM=
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/westoque/phantomjs.rb.png?branch=master)](http://travis-ci.org/westoque/phantomjs.rb)
|
4
4
|
|
5
|
-
A ruby wrapper for phantomjs.
|
6
|
-
|
7
|
-
|
5
|
+
A ruby wrapper for phantomjs.
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
You have to have `phantomjs` installed.
|
8
10
|
|
9
11
|
## Install
|
10
12
|
|
@@ -15,13 +17,11 @@ gem install phantomjs.rb
|
|
15
17
|
## Usage
|
16
18
|
|
17
19
|
```rb
|
18
|
-
script = File.expand_path('
|
20
|
+
script = File.expand_path('my_runner.js')
|
19
21
|
output = Phantomjs.run(script, 'myarg1', 'myarg2')
|
20
|
-
p output # Whatever it outputs from
|
22
|
+
p output # Whatever it outputs from STDOUT
|
21
23
|
```
|
22
24
|
|
23
|
-
|
25
|
+
## License
|
24
26
|
|
25
|
-
|
26
|
-
/absolute/path/to/phantomjs /absolute/my_runner.js myarg1 myarg2
|
27
|
-
```
|
27
|
+
MIT
|
data/lib/phantomjs.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require "phantomjs/version"
|
2
|
+
require 'phantomjs/errors'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
extend self
|
4
|
+
class Phantomjs
|
5
|
+
EXEC = 'phantomjs'
|
6
6
|
|
7
7
|
# Public: Runs the phantomjs binary
|
8
8
|
#
|
@@ -10,53 +10,21 @@ module Phantomjs
|
|
10
10
|
# *args - The arguments to pass to the script
|
11
11
|
#
|
12
12
|
# Returns the stdout output of phantomjs
|
13
|
-
def run(script, *args)
|
13
|
+
def self.run(script, *args)
|
14
|
+
raise NoSuchPathError unless File.exist?(File.expand_path(script))
|
15
|
+
|
14
16
|
string_args = args.join(" ")
|
15
|
-
@executable ||= get_executable
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
begin
|
19
|
+
if block_given?
|
20
|
+
IO.popen("#{EXEC} #{script} #{string_args}").each_line do |line|
|
21
|
+
yield line
|
22
|
+
end
|
23
|
+
else
|
24
|
+
`#{EXEC} #{script} #{string_args}`
|
20
25
|
end
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def get_executable
|
29
|
-
if Os.is_mac?
|
30
|
-
require 'phantomjs-mac'
|
31
|
-
elsif Os.is_linux?
|
32
|
-
require 'phantomjs-linux'
|
33
|
-
else
|
34
|
-
# Sorry windows guy
|
35
|
-
# Nothing here
|
26
|
+
rescue Errno::ENOENT
|
27
|
+
raise CommandNotFoundError.new('Phantomjs is not installed')
|
36
28
|
end
|
37
|
-
|
38
|
-
Phantomjs.executable_path
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
module Os
|
43
|
-
# Again, Fight the power
|
44
|
-
extend self
|
45
|
-
|
46
|
-
# universal-darwin9.0 shows up for RUBY_PLATFORM on os X leopard with the bundled ruby.
|
47
|
-
# Installing ruby in different manners may give a different result, so beware.
|
48
|
-
# Examine the ruby platform yourself. If you see other values please comment
|
49
|
-
# in the snippet on dzone and I will add them.
|
50
|
-
|
51
|
-
def is_mac?
|
52
|
-
RUBY_PLATFORM.downcase.include?("darwin")
|
53
|
-
end
|
54
|
-
|
55
|
-
def is_windows?
|
56
|
-
RUBY_PLATFORM.downcase.include?("mswin")
|
57
|
-
end
|
58
|
-
|
59
|
-
def is_linux?
|
60
|
-
RUBY_PLATFORM.downcase.include?("linux")
|
61
29
|
end
|
62
30
|
end
|
data/lib/phantomjs/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0
|
1
|
+
class Phantomjs
|
2
|
+
VERSION = "1.0.0"
|
3
3
|
end
|
data/phantomjs.rb.gemspec
CHANGED
@@ -19,13 +19,6 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
# specify any dependencies here; for example:
|
22
|
-
s.add_development_dependency "ZenTest"
|
23
22
|
s.add_development_dependency "rspec"
|
24
23
|
s.add_development_dependency "rake"
|
25
|
-
|
26
|
-
if RUBY_PLATFORM =~ /linux/
|
27
|
-
s.add_runtime_dependency 'phantomjs-linux'
|
28
|
-
elsif RUBY_PLATFORM =~ /darwin/
|
29
|
-
s.add_runtime_dependency 'phantomjs-mac'
|
30
|
-
end
|
31
24
|
end
|
data/spec/phantomjs_spec.rb
CHANGED
@@ -2,6 +2,25 @@ require 'phantomjs'
|
|
2
2
|
|
3
3
|
describe Phantomjs do
|
4
4
|
describe ".run" do
|
5
|
+
describe 'when phantomjs is non installed' do
|
6
|
+
before { Phantomjs::EXEC = 'not_existing_phantomjs' }
|
7
|
+
after { Phantomjs::EXEC = 'phantomjs' }
|
8
|
+
|
9
|
+
it "raises an error" do
|
10
|
+
script = File.expand_path('./spec/runner.js')
|
11
|
+
expect {
|
12
|
+
Phantomjs.run(script, 'foo1', 'foo2')
|
13
|
+
}.to raise_error(Phantomjs::CommandNotFoundError)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'raises an error when the script does not exist' do
|
18
|
+
script = File.expand_path('./doesnt_exist.js')
|
19
|
+
expect {
|
20
|
+
Phantomjs.run(script)
|
21
|
+
}.to raise_error(Phantomjs::NoSuchPathError)
|
22
|
+
end
|
23
|
+
|
5
24
|
it "runs phantomjs binary with the correct arguments" do
|
6
25
|
script = File.expand_path('./spec/runner.js')
|
7
26
|
result = Phantomjs.run(script, 'foo1', 'foo2')
|
metadata
CHANGED
@@ -1,36 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phantomjs.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- William Estoque
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: ZenTest
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
13
|
- !ruby/object:Gem::Dependency
|
31
14
|
name: rspec
|
32
15
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
16
|
requirements:
|
35
17
|
- - ! '>='
|
36
18
|
- !ruby/object:Gem::Version
|
@@ -38,7 +20,6 @@ dependencies:
|
|
38
20
|
type: :development
|
39
21
|
prerelease: false
|
40
22
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
23
|
requirements:
|
43
24
|
- - ! '>='
|
44
25
|
- !ruby/object:Gem::Version
|
@@ -46,7 +27,6 @@ dependencies:
|
|
46
27
|
- !ruby/object:Gem::Dependency
|
47
28
|
name: rake
|
48
29
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
30
|
requirements:
|
51
31
|
- - ! '>='
|
52
32
|
- !ruby/object:Gem::Version
|
@@ -54,23 +34,6 @@ dependencies:
|
|
54
34
|
type: :development
|
55
35
|
prerelease: false
|
56
36
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: phantomjs-mac
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :runtime
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
37
|
requirements:
|
75
38
|
- - ! '>='
|
76
39
|
- !ruby/object:Gem::Version
|
@@ -91,40 +54,35 @@ files:
|
|
91
54
|
- README.md
|
92
55
|
- Rakefile
|
93
56
|
- lib/phantomjs.rb
|
57
|
+
- lib/phantomjs/errors.rb
|
94
58
|
- lib/phantomjs/version.rb
|
95
59
|
- phantomjs.rb.gemspec
|
96
60
|
- spec/phantomjs_spec.rb
|
97
61
|
- spec/runner.js
|
98
62
|
homepage: http://westoque.com
|
99
63
|
licenses: []
|
64
|
+
metadata: {}
|
100
65
|
post_install_message:
|
101
66
|
rdoc_options: []
|
102
67
|
require_paths:
|
103
68
|
- lib
|
104
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
70
|
requirements:
|
107
71
|
- - ! '>='
|
108
72
|
- !ruby/object:Gem::Version
|
109
73
|
version: '0'
|
110
|
-
segments:
|
111
|
-
- 0
|
112
|
-
hash: 344941083117915964
|
113
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
75
|
requirements:
|
116
76
|
- - ! '>='
|
117
77
|
- !ruby/object:Gem::Version
|
118
78
|
version: '0'
|
119
|
-
segments:
|
120
|
-
- 0
|
121
|
-
hash: 344941083117915964
|
122
79
|
requirements: []
|
123
80
|
rubyforge_project: phantomjs.rb
|
124
|
-
rubygems_version:
|
81
|
+
rubygems_version: 2.0.3
|
125
82
|
signing_key:
|
126
|
-
specification_version:
|
83
|
+
specification_version: 4
|
127
84
|
summary: Ruby wrapper for phantomjs
|
128
85
|
test_files:
|
129
86
|
- spec/phantomjs_spec.rb
|
130
87
|
- spec/runner.js
|
88
|
+
has_rdoc:
|