phantomjs-binaries 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in phantomjs-binaries.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ phantomjs-binaries (1.5.0)
5
+ sys-uname (= 0.9.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ ffi (1.0.11)
11
+ sys-uname (0.9.0)
12
+ ffi (>= 1.0.0)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ phantomjs-binaries!
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/bootstrap.js ADDED
@@ -0,0 +1,342 @@
1
+ /*!
2
+ * Casper is a navigation utility for PhantomJS.
3
+ *
4
+ * Documentation: http://casperjs.org/
5
+ * Repository: http://github.com/n1k0/casperjs
6
+ *
7
+ * Copyright (c) 2011-2012 Nicolas Perriault
8
+ *
9
+ * Part of source code is Copyright Joyent, Inc. and other Node contributors.
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a
12
+ * copy of this software and associated documentation files (the "Software"),
13
+ * to deal in the Software without restriction, including without limitation
14
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
+ * and/or sell copies of the Software, and to permit persons to whom the
16
+ * Software is furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included
19
+ * in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
+ * DEALINGS IN THE SOFTWARE.
28
+ *
29
+ */
30
+
31
+ /*global console phantom require*/
32
+ /*jshint maxstatements:30 maxcomplexity:10*/
33
+
34
+ if (!phantom) {
35
+ console.error('CasperJS needs to be executed in a PhantomJS environment http://phantomjs.org/');
36
+ phantom.exit(1);
37
+ }
38
+
39
+ if (phantom.version.major === 1 && phantom.version.minor < 7) {
40
+ console.error('CasperJS needs at least PhantomJS v1.7 or later.');
41
+ phantom.exit(1);
42
+ } else {
43
+ bootstrap(window);
44
+ }
45
+
46
+ // Polyfills
47
+ if (typeof Function.prototype.bind !== "function") {
48
+ Function.prototype.bind = function(scope) {
49
+ "use strict";
50
+ var _function = this;
51
+ return function() {
52
+ return _function.apply(scope, arguments);
53
+ };
54
+ };
55
+ }
56
+
57
+ /**
58
+ * CasperJS ships with its own implementation of CommonJS' require() because
59
+ * PhantomJS' native one doesn't allow to specify supplementary, alternative
60
+ * lookup directories to fetch modules from.
61
+ *
62
+ */
63
+ function patchRequire(require, requireDirs) {
64
+ "use strict";
65
+ require('webserver'); // force generation of phantomjs' require.cache for the webserver module
66
+ var fs = require('fs');
67
+ var phantomBuiltins = ['fs', 'webpage', 'system', 'webserver'];
68
+ var phantomRequire = phantom.__orig__require = require;
69
+ var requireCache = {};
70
+ function possiblePaths(path, requireDir) {
71
+ var dir, paths = [];
72
+ if (path[0] === '.') {
73
+ paths.push.apply(paths, [
74
+ fs.absolute(path),
75
+ fs.absolute(fs.pathJoin(requireDir, path))
76
+ ]);
77
+ } else if (path[0] === '/') {
78
+ paths.push(path);
79
+ } else {
80
+ dir = fs.absolute(requireDir);
81
+ while (dir !== '' && dir.lastIndexOf(':') !== dir.length - 1) {
82
+ paths.push(fs.pathJoin(dir, 'modules', path));
83
+ // nodejs compatibility
84
+ paths.push(fs.pathJoin(dir, 'node_modules', path));
85
+ dir = fs.dirname(dir);
86
+ }
87
+ paths.push(fs.pathJoin(requireDir, 'lib', path));
88
+ paths.push(fs.pathJoin(requireDir, 'modules', path));
89
+ }
90
+ return paths;
91
+ }
92
+ var patchedRequire = function _require(path) {
93
+ var i, paths = [],
94
+ fileGuesses = [],
95
+ file,
96
+ module = {
97
+ exports: {}
98
+ };
99
+ if (phantomBuiltins.indexOf(path) !== -1) {
100
+ return phantomRequire(path);
101
+ }
102
+ requireDirs.forEach(function(requireDir) {
103
+ paths = paths.concat(possiblePaths(path, requireDir));
104
+ });
105
+ paths.forEach(function _forEach(testPath) {
106
+ fileGuesses.push.apply(fileGuesses, [
107
+ testPath,
108
+ testPath + '.js',
109
+ testPath + '.json',
110
+ testPath + '.coffee',
111
+ fs.pathJoin(testPath, 'index.js'),
112
+ fs.pathJoin(testPath, 'index.json'),
113
+ fs.pathJoin(testPath, 'index.coffee'),
114
+ fs.pathJoin(testPath, 'lib', fs.basename(testPath) + '.js'),
115
+ fs.pathJoin(testPath, 'lib', fs.basename(testPath) + '.json'),
116
+ fs.pathJoin(testPath, 'lib', fs.basename(testPath) + '.coffee')
117
+ ]);
118
+ });
119
+ file = null;
120
+ for (i = 0; i < fileGuesses.length && !file; ++i) {
121
+ if (fs.isFile(fileGuesses[i])) {
122
+ file = fileGuesses[i];
123
+ }
124
+ }
125
+ if (!file) {
126
+ throw new window.CasperError("CasperJS couldn't find module " + path);
127
+ }
128
+ if (file in requireCache) {
129
+ return requireCache[file].exports;
130
+ }
131
+ if (/\.json/i.test(file)) {
132
+ var parsed = JSON.parse(fs.read(file));
133
+ requireCache[file] = parsed;
134
+ return parsed;
135
+ }
136
+ var scriptCode = (function getScriptCode(file) {
137
+ var scriptCode = fs.read(file);
138
+ if (/\.coffee$/i.test(file)) {
139
+ /*global CoffeeScript*/
140
+ scriptCode = CoffeeScript.compile(scriptCode);
141
+ }
142
+ return scriptCode;
143
+ })(file);
144
+ var fn = new Function('__file__', 'require', 'module', 'exports', scriptCode);
145
+ try {
146
+ fn(file, _require, module, module.exports);
147
+ } catch (e) {
148
+ var error = new window.CasperError('__mod_error(' + path + ':' + e.line + '):: ' + e);
149
+ error.file = file;
150
+ error.line = e.line;
151
+ error.stack = e.stack;
152
+ error.stackArray = JSON.parse(JSON.stringify(e.stackArray));
153
+ if (error.stackArray.length > 0) {
154
+ error.stackArray[0].sourceURL = file;
155
+ }
156
+ throw error;
157
+ }
158
+ requireCache[file] = module;
159
+ return module.exports;
160
+ };
161
+ patchedRequire.patched = true;
162
+ return patchedRequire;
163
+ }
164
+
165
+ function bootstrap(global) {
166
+ "use strict";
167
+ var phantomArgs = require('system').args;
168
+
169
+ /**
170
+ * Hooks in default phantomjs error handler to print a hint when a possible
171
+ * casperjs command misuse is detected.
172
+ *
173
+ */
174
+ phantom.onError = function onPhantomError(msg, trace) {
175
+ phantom.defaultErrorHandler.apply(phantom, arguments);
176
+ if (msg.indexOf("ReferenceError: Can't find variable: casper") === 0) {
177
+ console.error('Hint: you may want to use the `casperjs test` command.');
178
+ }
179
+ };
180
+
181
+ /**
182
+ * Loads and initialize the CasperJS environment.
183
+ */
184
+ phantom.loadCasper = function loadCasper() {
185
+ // Patching fs
186
+ // TODO: watch for these methods being implemented in official fs module
187
+ var fs = (function _fs(fs) {
188
+ if (!fs.hasOwnProperty('basename')) {
189
+ fs.basename = function basename(path) {
190
+ return path.replace(/.*\//, '');
191
+ };
192
+ }
193
+ if (!fs.hasOwnProperty('dirname')) {
194
+ fs.dirname = function dirname(path) {
195
+ return path.replace(/\\/g, '/').replace(/\/[^\/]*$/, '');
196
+ };
197
+ }
198
+ if (!fs.hasOwnProperty('isWindows')) {
199
+ fs.isWindows = function isWindows() {
200
+ var testPath = arguments[0] || this.workingDirectory;
201
+ return (/^[a-z]{1,2}:/i).test(testPath) || testPath.indexOf("\\\\") === 0;
202
+ };
203
+ }
204
+ if (!fs.hasOwnProperty('pathJoin')) {
205
+ fs.pathJoin = function pathJoin() {
206
+ return Array.prototype.join.call(arguments, this.separator);
207
+ };
208
+ }
209
+ return fs;
210
+ })(require('fs'));
211
+
212
+ // casper root path
213
+ if (!phantom.casperPath) {
214
+ try {
215
+ phantom.casperPath = phantom.args.map(function _map(i) {
216
+ var match = i.match(/^--casper-path=(.*)/);
217
+ if (match) {
218
+ return fs.absolute(match[1]);
219
+ }
220
+ }).filter(function _filter(path) {
221
+ return fs.isDirectory(path);
222
+ }).pop();
223
+ } catch (e) {}
224
+ }
225
+
226
+ if (!phantom.casperPath) {
227
+ console.error("Couldn't find nor compute phantom.casperPath, exiting.");
228
+ phantom.exit(1);
229
+ }
230
+
231
+ // Embedded, up-to-date, validatable & controlable CoffeeScript
232
+ phantom.injectJs(fs.pathJoin(phantom.casperPath, 'modules', 'vendors', 'coffee-script.js'));
233
+
234
+ // custom global CasperError
235
+ global.CasperError = function CasperError(msg) {
236
+ Error.call(this);
237
+ this.message = msg;
238
+ this.name = 'CasperError';
239
+ };
240
+
241
+ // standard Error prototype inheritance
242
+ global.CasperError.prototype = Object.getPrototypeOf(new Error());
243
+
244
+ // CasperJS version, extracted from package.json - see http://semver.org/
245
+ phantom.casperVersion = (function getVersion(path) {
246
+ var parts, patchPart, pkg, pkgFile;
247
+ var fs = require('fs');
248
+ pkgFile = fs.absolute(fs.pathJoin(path, 'package.json'));
249
+ if (!fs.exists(pkgFile)) {
250
+ throw new global.CasperError('Cannot find package.json at ' + pkgFile);
251
+ }
252
+ try {
253
+ pkg = JSON.parse(require('fs').read(pkgFile));
254
+ } catch (e) {
255
+ throw new global.CasperError('Cannot read package file contents: ' + e);
256
+ }
257
+ parts = pkg.version.trim().split(".");
258
+ if (parts.length < 3) {
259
+ throw new global.CasperError("Invalid version number");
260
+ }
261
+ patchPart = parts[2].split('-');
262
+ return {
263
+ major: ~~parts[0] || 0,
264
+ minor: ~~parts[1] || 0,
265
+ patch: ~~patchPart[0] || 0,
266
+ ident: patchPart[1] || "",
267
+ toString: function toString() {
268
+ var version = [this.major, this.minor, this.patch].join('.');
269
+ if (this.ident) {
270
+ version = [version, this.ident].join('-');
271
+ }
272
+ return version;
273
+ }
274
+ };
275
+ })(phantom.casperPath);
276
+
277
+ // patch require
278
+ global.require = patchRequire(global.require, [phantom.casperPath, fs.workingDirectory]);
279
+
280
+ // casper cli args
281
+ phantom.casperArgs = global.require('cli').parse(phantom.args);
282
+
283
+ // loaded status
284
+ phantom.casperLoaded = true;
285
+ };
286
+
287
+ /**
288
+ * Initializes the CasperJS Command Line Interface.
289
+ */
290
+ phantom.initCasperCli = function initCasperCli() {
291
+ var fs = require("fs");
292
+ var baseTestsPath = fs.pathJoin(phantom.casperPath, 'tests');
293
+
294
+ if (!!phantom.casperArgs.options.version) {
295
+ console.log(phantom.casperVersion.toString());
296
+ return phantom.exit();
297
+ } else if (phantom.casperArgs.get(0) === "test") {
298
+ phantom.casperScript = fs.absolute(fs.pathJoin(baseTestsPath, 'run.js'));
299
+ phantom.casperTest = true;
300
+ phantom.casperArgs.drop("test");
301
+ } else if (phantom.casperArgs.get(0) === "selftest") {
302
+ phantom.casperScript = fs.absolute(fs.pathJoin(baseTestsPath, 'run.js'));
303
+ phantom.casperSelfTest = phantom.casperTest = true;
304
+ phantom.casperArgs.options.includes = fs.pathJoin(baseTestsPath, 'selftest.js');
305
+ if (phantom.casperArgs.args.length <= 1) {
306
+ phantom.casperArgs.args.push(fs.pathJoin(baseTestsPath, 'suites'));
307
+ }
308
+ phantom.casperArgs.drop("selftest");
309
+ } else if (phantom.casperArgs.args.length === 0 || !!phantom.casperArgs.options.help) {
310
+ var phantomVersion = [phantom.version.major, phantom.version.minor, phantom.version.patch].join('.');
311
+ var f = require("utils").format;
312
+ console.log(f('CasperJS version %s at %s, using PhantomJS version %s',
313
+ phantom.casperVersion.toString(),
314
+ phantom.casperPath, phantomVersion));
315
+ console.log(fs.read(fs.pathJoin(phantom.casperPath, 'bin', 'usage.txt')));
316
+ return phantom.exit(0);
317
+ }
318
+
319
+ if (!phantom.casperScript) {
320
+ phantom.casperScript = phantom.casperArgs.get(0);
321
+ }
322
+
323
+ if (!fs.isFile(phantom.casperScript)) {
324
+ console.error('Unable to open file: ' + phantom.casperScript);
325
+ return phantom.exit(1);
326
+ }
327
+
328
+ // filter out the called script name from casper args
329
+ phantom.casperArgs.drop(phantom.casperScript);
330
+
331
+ // passed casperjs script execution
332
+ phantom.injectJs(phantom.casperScript);
333
+ };
334
+
335
+ if (!phantom.casperLoaded) {
336
+ phantom.loadCasper();
337
+ }
338
+
339
+ if (true === phantom.casperArgs.get('cli')) {
340
+ phantom.initCasperCli();
341
+ }
342
+ }
data/bin/casperjs ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ # Ruby Wrapper for CasperJs
3
+ # by hannyu
4
+
5
+ def resolve(file_path)
6
+ while File.symlink?(file_path) do
7
+ file_path = File.readlink(file_path)
8
+ end
9
+ file_path
10
+ end
11
+
12
+ CASPER_PATH = File.dirname(File.dirname(File.expand_path(resolve(__FILE__))))
13
+
14
+ PHANTOMJS_NATIVE_ARGS = [
15
+ '--cookies-file',
16
+ '--config',
17
+ '--debug',
18
+ '--disk-cache',
19
+ '--ignore-ssl-errors',
20
+ '--load-images',
21
+ '--load-plugins',
22
+ '--local-storage-path',
23
+ '--local-storage-quota',
24
+ '--local-to-remote-url-access',
25
+ '--max-disk-cache-size',
26
+ '--output-encoding',
27
+ '--proxy',
28
+ '--proxy-auth',
29
+ '--proxy-type',
30
+ '--remote-debugger-port',
31
+ '--remote-debugger-autorun',
32
+ '--script-encoding',
33
+ '--web-security',
34
+ ]
35
+
36
+ CASPER_ARGS = []
37
+ PHANTOMJS_ARGS = []
38
+ ARGV.each do |arg|
39
+ is_found = false
40
+ PHANTOMJS_NATIVE_ARGS.each do |pna|
41
+ if arg.start_with? pna
42
+ PHANTOMJS_ARGS << arg
43
+ is_found = true
44
+ break
45
+ end
46
+ end
47
+ CASPER_ARGS << arg if not is_found
48
+ end
49
+
50
+ CASPER_COMMAND = []
51
+ CASPER_COMMAND << (ENV["PHANTOMJS_EXECUTABLE"] || "phantomjs")
52
+ CASPER_COMMAND.concat PHANTOMJS_ARGS
53
+ CASPER_COMMAND << File.join(CASPER_PATH, "bin", "bootstrap.js")
54
+ CASPER_COMMAND << "--casper-path=#{CASPER_PATH}"
55
+ CASPER_COMMAND << "--cli"
56
+ CASPER_COMMAND.concat CASPER_ARGS
57
+
58
+ exec CASPER_COMMAND.join(" ")
data/bin/phantomjs ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sys/uname'
4
+ include Sys
5
+
6
+ $:.push File.expand_path("../../lib", __FILE__)
7
+ require "phantomjs-binaries/version"
8
+
9
+ machine = Uname.machine
10
+ platform = Uname.sysname.downcase
11
+ version = Phantomjs::Binaries::VERSION
12
+ platform_binary = File.expand_path(File.join(File.dirname(__FILE__), "phantomjs-#{version}-#{platform}-#{machine}"))
13
+ exec platform_binary, *ARGV
Binary file
Binary file
data/bin/usage.txt ADDED
@@ -0,0 +1,11 @@
1
+
2
+ Usage: casperjs [options] script.[js|coffee] [script argument [script argument ...]]
3
+ casperjs [options] test [test path [test path ...]]
4
+ casperjs [options] selftest
5
+
6
+ Options:
7
+
8
+ --help Prints this help
9
+ --version Prints out CasperJS version
10
+
11
+ Read the docs http://casperjs.org/
@@ -0,0 +1,5 @@
1
+ module Phantomjs
2
+ module Binaries
3
+ VERSION = "1.8.0"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require "phantomjs-binaries/version"
2
+
3
+ module Phantomjs
4
+ module Binaries
5
+ # Your code goes here...
6
+ end
7
+ end