casperjs_ruby
1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env ruby
# Ruby Wrapper for CasperJs
# Version: 1.0.0
# by hannyu
CASPER_PATH = File.dirname(File.dirname(File.expand_path(__FILE__)))
PHANTOMJS_NATIVE_ARGS = [
'--cookies-file',
'--config',
'--disk-cache',
'--ignore-ssl-errors',
'--load-images',
'--load-plugins',
'--local-to-remote-url-access',
'--max-disk-cache-size',
'--output-encoding',
'--remote-debugger-port',
'--remote-debugger-autorun',
'--proxy',
'--proxy-auth',
'--proxy-type',
'--script-encoding',
'--web-security',
]
CASPER_ARGS = []
PHANTOMJS_ARGS = []
ARGV.each do |arg|
is_found = false
PHANTOMJS_NATIVE_ARGS.each do |pna|
if arg.start_with? pna
PHANTOMJS_ARGS << arg
is_found = true
break
end
end
CASPER_ARGS << arg if not is_found
end
CASPER_COMMAND = []
CASPER_COMMAND << (ENV["PHANTOMJS_EXECUTABLE"] || "phantomjs")
CASPER_COMMAND.concat PHANTOMJS_ARGS
CASPER_COMMAND << File.join(CASPER_PATH, "bin", "bootstrap.js")
CASPER_COMMAND << "--casper-path=#{CASPER_PATH}"
CASPER_COMMAND << "--cli"
CASPER_COMMAND.concat CASPER_ARGS
if system(CASPER_COMMAND.join(" ")).nil?
puts "Fatal: Did you install phantomjs?"
end
exit $?.exitstatus