phantomjs.rb 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.
- data/.autotest +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +16 -0
- data/Rakefile +1 -0
- data/lib/phantomjs.rb +53 -0
- data/lib/phantomjs/version.rb +3 -0
- data/phantomjs.rb.gemspec +24 -0
- data/spec/phantomjs_spec.rb +13 -0
- data/spec/runner.js +2 -0
- data/vendor/phantomjs-1.4.1_OSX/ChangeLog +145 -0
- data/vendor/phantomjs-1.4.1_OSX/LICENSE.BSD +22 -0
- data/vendor/phantomjs-1.4.1_OSX/README.md +33 -0
- data/vendor/phantomjs-1.4.1_OSX/bin/Info.plist +12 -0
- data/vendor/phantomjs-1.4.1_OSX/bin/phantomjs +0 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/arguments.coffee +6 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/arguments.js +8 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/colorwheel.coffee +46 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/colorwheel.js +51 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/countdown.coffee +8 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/countdown.js +9 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/detectsniff.coffee +40 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/detectsniff.js +57 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/direction.coffee +29 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/direction.js +34 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/echoToFile.coffee +19 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/echoToFile.js +22 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/features.js +30 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/fibo.coffee +8 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/fibo.js +9 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/follow.coffee +54 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/follow.js +59 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/hello.coffee +2 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/hello.js +2 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/imagebin.coffee +19 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/imagebin.js +22 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/injectme.coffee +23 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/injectme.js +25 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/ipgeocode.coffee +13 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/ipgeocode.js +14 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/loadspeed.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/loadspeed.js +22 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/modernizr.js +1116 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/movies.coffee +13 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/movies.js +14 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/netlog.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/netlog.js +23 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/netsniff.coffee +109 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/netsniff.js +131 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/outputEncoding.coffee +12 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/outputEncoding.js +16 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/phantomwebintro.coffee +13 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/phantomwebintro.js +19 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/pizza.coffee +18 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/pizza.js +20 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/post.coffee +12 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/post.js +14 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/rasterize.coffee +22 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/rasterize.js +27 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/render_multi_url.coffee +48 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/render_multi_url.js +60 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/run-jasmine.coffee +59 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/run-jasmine.js +77 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/run-qunit.coffee +62 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/run-qunit.js +74 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/scandir.coffee +15 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/scandir.js +21 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/seasonfood.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/seasonfood.js +19 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/simpleserver.coffee +35 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/simpleserver.js +40 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/sleepsort.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/sleepsort.js +24 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/technews.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/technews.js +16 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/tweets.coffee +30 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/tweets.js +36 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/unrandomize.coffee +18 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/unrandomize.js +24 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/useragent.coffee +11 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/useragent.js +14 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/version.coffee +5 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/version.js +5 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/waitfor.coffee +48 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/waitfor.js +57 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/weather.coffee +48 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/weather.js +57 -0
- data/vendor/phantomjs-1.4.1_OSX/lib/jquery.js +8374 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/ChangeLog +177 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/LICENSE.BSD +22 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/README.md +33 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/bin/Info.plist +12 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/bin/phantomjs +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/arguments.coffee +7 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/arguments.js +9 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.coffee +46 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.js +51 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/countdown.coffee +8 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/countdown.js +9 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/detectsniff.coffee +41 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/detectsniff.js +58 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.coffee +30 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.js +35 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/echoToFile.coffee +20 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/echoToFile.js +24 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/features.js +30 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/fibo.coffee +8 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/fibo.js +9 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/follow.coffee +29 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/follow.js +34 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/hello.coffee +2 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/hello.js +2 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/imagebin.coffee +20 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/imagebin.js +23 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/injectme.coffee +23 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/injectme.js +25 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/ipgeocode.coffee +13 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/ipgeocode.js +14 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/loadspeed.coffee +18 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/loadspeed.js +23 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/modernizr.js +1116 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/movies.coffee +13 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/movies.js +14 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netlog.coffee +18 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netlog.js +25 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netsniff.coffee +110 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netsniff.js +132 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/outputEncoding.coffee +12 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/outputEncoding.js +16 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/phantomwebintro.coffee +13 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/phantomwebintro.js +19 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/pizza.coffee +18 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/pizza.js +20 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/post.coffee +12 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/post.js +14 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/postserver.js +34 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/printenv.js +10 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/printmargins.js +35 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/rasterize.coffee +23 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/rasterize.js +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/render_multi_url.coffee +50 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/render_multi_url.js +62 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-jasmine.coffee +61 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-jasmine.js +79 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-qunit.coffee +64 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-qunit.js +76 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/scandir.coffee +16 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/scandir.js +22 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/seasonfood.coffee +17 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/seasonfood.js +19 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/server.js +43 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/serverkeepalive.js +34 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/simpleserver.coffee +38 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/simpleserver.js +42 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/sleepsort.coffee +20 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/sleepsort.js +25 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/technews.coffee +17 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/technews.js +16 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.coffee +31 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.js +37 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/unrandomize.coffee +18 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/unrandomize.js +24 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/useragent.coffee +11 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/useragent.js +14 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/version.coffee +5 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/version.js +5 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/waitfor.coffee +48 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/waitfor.js +57 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/weather.coffee +49 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/weather.js +58 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.la +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.prl +7 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4.8 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4.8.0 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.la +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.prl +7 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4.8 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4.8.0 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.la +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.prl +7 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4.8 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4.8.0 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.la +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.prl +6 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4.9 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4.9.0 +0 -0
- metadata +252 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
page = require('webpage').create()
|
|
2
|
+
|
|
3
|
+
if phantom.args.length < 2 or phantom.args.length > 3
|
|
4
|
+
console.log 'Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]'
|
|
5
|
+
console.log ' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"'
|
|
6
|
+
phantom.exit()
|
|
7
|
+
else
|
|
8
|
+
address = phantom.args[0]
|
|
9
|
+
output = phantom.args[1]
|
|
10
|
+
page.viewportSize = { width: 600, height: 600 }
|
|
11
|
+
if phantom.args.length is 3 and phantom.args[1].substr(-4) is ".pdf"
|
|
12
|
+
size = phantom.args[2].split '*'
|
|
13
|
+
if size.length is 2
|
|
14
|
+
page.paperSize = { width: size[0], height: size[1], border: '0px' }
|
|
15
|
+
else
|
|
16
|
+
page.paperSize = { format: phantom.args[2], orientation: 'portrait', border: '1cm' }
|
|
17
|
+
page.open address, (status) ->
|
|
18
|
+
if status isnt 'success'
|
|
19
|
+
console.log 'Unable to load the address!'
|
|
20
|
+
phantom.exit()
|
|
21
|
+
else
|
|
22
|
+
window.setTimeout (-> page.render output; phantom.exit()), 200
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var page = require('webpage').create(),
|
|
2
|
+
address, output, size;
|
|
3
|
+
|
|
4
|
+
if (phantom.args.length < 2 || phantom.args.length > 3) {
|
|
5
|
+
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]');
|
|
6
|
+
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
|
|
7
|
+
phantom.exit();
|
|
8
|
+
} else {
|
|
9
|
+
address = phantom.args[0];
|
|
10
|
+
output = phantom.args[1];
|
|
11
|
+
page.viewportSize = { width: 600, height: 600 };
|
|
12
|
+
if (phantom.args.length === 3 && phantom.args[1].substr(-4) === ".pdf") {
|
|
13
|
+
size = phantom.args[2].split('*');
|
|
14
|
+
page.paperSize = size.length === 2 ? { width: size[0], height: size[1], border: '0px' }
|
|
15
|
+
: { format: phantom.args[2], orientation: 'portrait', border: '1cm' };
|
|
16
|
+
}
|
|
17
|
+
page.open(address, function (status) {
|
|
18
|
+
if (status !== 'success') {
|
|
19
|
+
console.log('Unable to load the address!');
|
|
20
|
+
} else {
|
|
21
|
+
window.setTimeout(function () {
|
|
22
|
+
page.render(output);
|
|
23
|
+
phantom.exit();
|
|
24
|
+
}, 200);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Render Multiple URLs to file
|
|
2
|
+
# FIXME: For now it is fine with pure domain names: don't think it would work with paths and stuff like that
|
|
3
|
+
|
|
4
|
+
# Extend the Array Prototype with a 'foreach'
|
|
5
|
+
Array.prototype.forEach = (action) ->
|
|
6
|
+
for i, j in this
|
|
7
|
+
action j, i, _len
|
|
8
|
+
|
|
9
|
+
# Render a given url to a given file
|
|
10
|
+
# @param url URL to render
|
|
11
|
+
# @param file File to render to
|
|
12
|
+
# @param callback Callback function
|
|
13
|
+
renderUrlToFile = (url, file, callback) ->
|
|
14
|
+
page = require('webpage').create()
|
|
15
|
+
page.viewportSize = { width: 800, height : 600 }
|
|
16
|
+
page.settings.userAgent = 'Phantom.js bot'
|
|
17
|
+
|
|
18
|
+
page.open url, (status) ->
|
|
19
|
+
if status isnt 'success'
|
|
20
|
+
console.log "Unable to render '#{url}'"
|
|
21
|
+
else
|
|
22
|
+
page.render file
|
|
23
|
+
|
|
24
|
+
delete page
|
|
25
|
+
callback url, file
|
|
26
|
+
|
|
27
|
+
# Read the passed args
|
|
28
|
+
if phantom.args.length > 0
|
|
29
|
+
arrayOfUrls = phantom.args
|
|
30
|
+
else
|
|
31
|
+
# Default (no args passed)
|
|
32
|
+
console.log 'Usage: phantomjs render_multi_url.coffee [domain.name1, domain.name2, ...]'
|
|
33
|
+
arrayOfUrls = [
|
|
34
|
+
'www.google.com',
|
|
35
|
+
'www.bbc.co.uk',
|
|
36
|
+
'www.phantomjs.org'
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
# For each URL
|
|
40
|
+
arrayOfUrls.forEach (pos, url, total) ->
|
|
41
|
+
file_name = "./#{url}.png"
|
|
42
|
+
|
|
43
|
+
# Render to a file
|
|
44
|
+
renderUrlToFile "http://#{url}", file_name, (url, file) ->
|
|
45
|
+
console.log "Rendered '#{url}' at '#{file}'"
|
|
46
|
+
if pos is total - 1
|
|
47
|
+
# Close Phantom if it's the last URL
|
|
48
|
+
phantom.exit()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Render Multiple URLs to file
|
|
2
|
+
// FIXME: For now it is fine with pure domain names: don't think it would work with paths and stuff like that
|
|
3
|
+
|
|
4
|
+
// Extend the Array Prototype with a 'foreach'
|
|
5
|
+
Array.prototype.forEach = function (action) {
|
|
6
|
+
var i, len;
|
|
7
|
+
for ( i = 0, len = this.length; i < len; ++i ) {
|
|
8
|
+
action(i, this[i], len);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Render a given url to a given file
|
|
14
|
+
* @param url URL to render
|
|
15
|
+
* @param file File to render to
|
|
16
|
+
* @param callback Callback function
|
|
17
|
+
*/
|
|
18
|
+
function renderUrlToFile(url, file, callback) {
|
|
19
|
+
var page = require('webpage').create();
|
|
20
|
+
page.viewportSize = { width: 800, height : 600 };
|
|
21
|
+
page.settings.userAgent = "Phantom.js bot";
|
|
22
|
+
|
|
23
|
+
page.open(url, function(status){
|
|
24
|
+
if ( status !== "success") {
|
|
25
|
+
console.log("Unable to render '"+url+"'");
|
|
26
|
+
} else {
|
|
27
|
+
page.render(file);
|
|
28
|
+
}
|
|
29
|
+
delete page;
|
|
30
|
+
callback(url, file);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Read the passed args
|
|
35
|
+
var arrayOfUrls;
|
|
36
|
+
if ( phantom.args.length > 0 ) {
|
|
37
|
+
arrayOfUrls = phantom.args;
|
|
38
|
+
} else {
|
|
39
|
+
// Default (no args passed)
|
|
40
|
+
console.log("Usage: phantomjs render_multi_url.js [domain.name1, domain.name2, ...]");
|
|
41
|
+
arrayOfUrls = [
|
|
42
|
+
'www.google.com',
|
|
43
|
+
'www.bbc.co.uk',
|
|
44
|
+
'www.phantomjs.org'
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// For each URL
|
|
49
|
+
arrayOfUrls.forEach(function(pos, url, total){
|
|
50
|
+
var file_name = "./" + url + ".png";
|
|
51
|
+
|
|
52
|
+
// Render to a file
|
|
53
|
+
renderUrlToFile("http://"+url, file_name, function(url, file){
|
|
54
|
+
console.log("Rendered '"+url+"' at '"+file+"'");
|
|
55
|
+
if ( pos === total-1 ) {
|
|
56
|
+
// Close Phantom if it's the last URL
|
|
57
|
+
phantom.exit();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
##
|
|
2
|
+
# Wait until the test condition is true or a timeout occurs. Useful for waiting
|
|
3
|
+
# on a server response or for a ui change (fadeIn, etc.) to occur.
|
|
4
|
+
#
|
|
5
|
+
# @param testFx javascript condition that evaluates to a boolean,
|
|
6
|
+
# it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
|
|
7
|
+
# as a callback function.
|
|
8
|
+
# @param onReady what to do when testFx condition is fulfilled,
|
|
9
|
+
# it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
|
|
10
|
+
# as a callback function.
|
|
11
|
+
# @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
|
|
12
|
+
##
|
|
13
|
+
waitFor = (testFx, onReady, timeOutMillis=3000) ->
|
|
14
|
+
start = new Date().getTime()
|
|
15
|
+
condition = false
|
|
16
|
+
f = ->
|
|
17
|
+
if (new Date().getTime() - start < timeOutMillis) and not condition
|
|
18
|
+
# If not time-out yet and condition not yet fulfilled
|
|
19
|
+
condition = (if typeof testFx is 'string' then eval testFx else testFx()) #< defensive code
|
|
20
|
+
else
|
|
21
|
+
if not condition
|
|
22
|
+
# If condition still not fulfilled (timeout but condition is 'false')
|
|
23
|
+
console.log "'waitFor()' timeout"
|
|
24
|
+
phantom.exit(1)
|
|
25
|
+
else
|
|
26
|
+
# Condition fulfilled (timeout and/or condition is 'true')
|
|
27
|
+
console.log "'waitFor()' finished in #{new Date().getTime() - start}ms."
|
|
28
|
+
if typeof onReady is 'string' then eval onReady else onReady() #< Do what it's supposed to do once the condition is fulfilled
|
|
29
|
+
clearInterval interval #< Stop this interval
|
|
30
|
+
interval = setInterval f, 100 #< repeat check every 100ms
|
|
31
|
+
|
|
32
|
+
if phantom.args.length isnt 1
|
|
33
|
+
console.log 'Usage: run-jasmine.coffee URL'
|
|
34
|
+
phantom.exit()
|
|
35
|
+
|
|
36
|
+
page = require('webpage').create()
|
|
37
|
+
|
|
38
|
+
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
|
39
|
+
page.onConsoleMessage = (msg) ->
|
|
40
|
+
console.log msg
|
|
41
|
+
|
|
42
|
+
page.open phantom.args[0], (status) ->
|
|
43
|
+
if status isnt 'success'
|
|
44
|
+
console.log 'Unable to access network'
|
|
45
|
+
phantom.exit()
|
|
46
|
+
else
|
|
47
|
+
waitFor ->
|
|
48
|
+
page.evaluate ->
|
|
49
|
+
if document.body.querySelector '.finished-at'
|
|
50
|
+
return true
|
|
51
|
+
return false
|
|
52
|
+
, ->
|
|
53
|
+
page.evaluate ->
|
|
54
|
+
console.log document.body.querySelector('.description').innerText
|
|
55
|
+
list = document.body.querySelectorAll('.failed > .description, .failed > .messages > .resultMessage')
|
|
56
|
+
for el in list
|
|
57
|
+
console.log el.innerText
|
|
58
|
+
|
|
59
|
+
phantom.exit()
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wait until the test condition is true or a timeout occurs. Useful for waiting
|
|
3
|
+
* on a server response or for a ui change (fadeIn, etc.) to occur.
|
|
4
|
+
*
|
|
5
|
+
* @param testFx javascript condition that evaluates to a boolean,
|
|
6
|
+
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
|
|
7
|
+
* as a callback function.
|
|
8
|
+
* @param onReady what to do when testFx condition is fulfilled,
|
|
9
|
+
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
|
|
10
|
+
* as a callback function.
|
|
11
|
+
* @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
|
|
12
|
+
*/
|
|
13
|
+
function waitFor(testFx, onReady, timeOutMillis) {
|
|
14
|
+
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3001, //< Default Max Timeout is 3s
|
|
15
|
+
start = new Date().getTime(),
|
|
16
|
+
condition = false,
|
|
17
|
+
interval = setInterval(function() {
|
|
18
|
+
if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
|
|
19
|
+
// If not time-out yet and condition not yet fulfilled
|
|
20
|
+
condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
|
|
21
|
+
} else {
|
|
22
|
+
if(!condition) {
|
|
23
|
+
// If condition still not fulfilled (timeout but condition is 'false')
|
|
24
|
+
console.log("'waitFor()' timeout");
|
|
25
|
+
phantom.exit(1);
|
|
26
|
+
} else {
|
|
27
|
+
// Condition fulfilled (timeout and/or condition is 'true')
|
|
28
|
+
console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
|
|
29
|
+
typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
|
|
30
|
+
clearInterval(interval); //< Stop this interval
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}, 100); //< repeat check every 100ms
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if (phantom.args.length === 0 || phantom.args.length > 2) {
|
|
38
|
+
console.log('Usage: run-jasmine.js URL');
|
|
39
|
+
phantom.exit();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var page = require('webpage').create();
|
|
43
|
+
|
|
44
|
+
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
|
45
|
+
page.onConsoleMessage = function(msg) {
|
|
46
|
+
console.log(msg);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
page.open(phantom.args[0], function(status){
|
|
50
|
+
if (status !== "success") {
|
|
51
|
+
console.log("Unable to access network");
|
|
52
|
+
phantom.exit();
|
|
53
|
+
} else {
|
|
54
|
+
waitFor(function(){
|
|
55
|
+
return page.evaluate(function(){
|
|
56
|
+
if (document.body.querySelector('.finished-at')) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
});
|
|
61
|
+
}, function(){
|
|
62
|
+
page.evaluate(function(){
|
|
63
|
+
console.log(document.body.querySelector('.description').innerText);
|
|
64
|
+
list = document.body.querySelectorAll('div.jasmine_reporter > div.suite.failed');
|
|
65
|
+
for (i = 0; i < list.length; ++i) {
|
|
66
|
+
el = list[i];
|
|
67
|
+
desc = el.querySelectorAll('.description');
|
|
68
|
+
console.log('');
|
|
69
|
+
for (j = 0; j < desc.length; ++j) {
|
|
70
|
+
console.log(desc[j].innerText);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
phantom.exit();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
##
|
|
2
|
+
# Wait until the test condition is true or a timeout occurs. Useful for waiting
|
|
3
|
+
# on a server response or for a ui change (fadeIn, etc.) to occur.
|
|
4
|
+
#
|
|
5
|
+
# @param testFx javascript condition that evaluates to a boolean,
|
|
6
|
+
# it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
|
|
7
|
+
# as a callback function.
|
|
8
|
+
# @param onReady what to do when testFx condition is fulfilled,
|
|
9
|
+
# it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
|
|
10
|
+
# as a callback function.
|
|
11
|
+
# @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
|
|
12
|
+
##
|
|
13
|
+
waitFor = (testFx, onReady, timeOutMillis=3000) ->
|
|
14
|
+
start = new Date().getTime()
|
|
15
|
+
condition = false
|
|
16
|
+
f = ->
|
|
17
|
+
if (new Date().getTime() - start < timeOutMillis) and not condition
|
|
18
|
+
# If not time-out yet and condition not yet fulfilled
|
|
19
|
+
condition = (if typeof testFx is 'string' then eval testFx else testFx()) #< defensive code
|
|
20
|
+
else
|
|
21
|
+
if not condition
|
|
22
|
+
# If condition still not fulfilled (timeout but condition is 'false')
|
|
23
|
+
console.log "'waitFor()' timeout"
|
|
24
|
+
phantom.exit(1)
|
|
25
|
+
else
|
|
26
|
+
# Condition fulfilled (timeout and/or condition is 'true')
|
|
27
|
+
console.log "'waitFor()' finished in #{new Date().getTime() - start}ms."
|
|
28
|
+
if typeof onReady is 'string' then eval onReady else onReady() #< Do what it's supposed to do once the condition is fulfilled
|
|
29
|
+
clearInterval interval #< Stop this interval
|
|
30
|
+
interval = setInterval f, 100 #< repeat check every 100ms
|
|
31
|
+
|
|
32
|
+
if phantom.args.length isnt 1
|
|
33
|
+
console.log 'Usage: run-qunit.coffee URL'
|
|
34
|
+
phantom.exit(1)
|
|
35
|
+
|
|
36
|
+
page = require('webpage').create()
|
|
37
|
+
|
|
38
|
+
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
|
39
|
+
page.onConsoleMessage = (msg) ->
|
|
40
|
+
console.log msg
|
|
41
|
+
|
|
42
|
+
page.open phantom.args[0], (status) ->
|
|
43
|
+
if status isnt 'success'
|
|
44
|
+
console.log 'Unable to access network'
|
|
45
|
+
phantom.exit(1)
|
|
46
|
+
else
|
|
47
|
+
waitFor ->
|
|
48
|
+
page.evaluate ->
|
|
49
|
+
el = document.getElementById 'qunit-testresult'
|
|
50
|
+
if el and el.innerText.match 'completed'
|
|
51
|
+
return true
|
|
52
|
+
return false
|
|
53
|
+
, ->
|
|
54
|
+
failedNum = page.evaluate ->
|
|
55
|
+
el = document.getElementById 'qunit-testresult'
|
|
56
|
+
console.log el.innerText
|
|
57
|
+
try
|
|
58
|
+
return el.getElementsByClassName('failed')[0].innerHTML
|
|
59
|
+
catch e
|
|
60
|
+
return 10000
|
|
61
|
+
|
|
62
|
+
phantom.exit if parseInt(failedNum, 10) > 0 then 1 else 0
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wait until the test condition is true or a timeout occurs. Useful for waiting
|
|
3
|
+
* on a server response or for a ui change (fadeIn, etc.) to occur.
|
|
4
|
+
*
|
|
5
|
+
* @param testFx javascript condition that evaluates to a boolean,
|
|
6
|
+
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
|
|
7
|
+
* as a callback function.
|
|
8
|
+
* @param onReady what to do when testFx condition is fulfilled,
|
|
9
|
+
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
|
|
10
|
+
* as a callback function.
|
|
11
|
+
* @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
|
|
12
|
+
*/
|
|
13
|
+
function waitFor(testFx, onReady, timeOutMillis) {
|
|
14
|
+
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3001, //< Default Max Timout is 3s
|
|
15
|
+
start = new Date().getTime(),
|
|
16
|
+
condition = false,
|
|
17
|
+
interval = setInterval(function() {
|
|
18
|
+
if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
|
|
19
|
+
// If not time-out yet and condition not yet fulfilled
|
|
20
|
+
condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
|
|
21
|
+
} else {
|
|
22
|
+
if(!condition) {
|
|
23
|
+
// If condition still not fulfilled (timeout but condition is 'false')
|
|
24
|
+
console.log("'waitFor()' timeout");
|
|
25
|
+
phantom.exit(1);
|
|
26
|
+
} else {
|
|
27
|
+
// Condition fulfilled (timeout and/or condition is 'true')
|
|
28
|
+
console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
|
|
29
|
+
typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
|
|
30
|
+
clearInterval(interval); //< Stop this interval
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}, 100); //< repeat check every 250ms
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if (phantom.args.length === 0 || phantom.args.length > 2) {
|
|
38
|
+
console.log('Usage: run-qunit.js URL');
|
|
39
|
+
phantom.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var page = require('webpage').create();
|
|
43
|
+
|
|
44
|
+
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
|
45
|
+
page.onConsoleMessage = function(msg) {
|
|
46
|
+
console.log(msg);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
page.open(phantom.args[0], function(status){
|
|
50
|
+
if (status !== "success") {
|
|
51
|
+
console.log("Unable to access network");
|
|
52
|
+
phantom.exit(1);
|
|
53
|
+
} else {
|
|
54
|
+
waitFor(function(){
|
|
55
|
+
return page.evaluate(function(){
|
|
56
|
+
var el = document.getElementById('qunit-testresult');
|
|
57
|
+
if (el && el.innerText.match('completed')) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
});
|
|
62
|
+
}, function(){
|
|
63
|
+
var failedNum = page.evaluate(function(){
|
|
64
|
+
var el = document.getElementById('qunit-testresult');
|
|
65
|
+
console.log(el.innerText);
|
|
66
|
+
try {
|
|
67
|
+
return el.getElementsByClassName('failed')[0].innerHTML;
|
|
68
|
+
} catch (e) { }
|
|
69
|
+
return 10000;
|
|
70
|
+
});
|
|
71
|
+
phantom.exit((parseInt(failedNum, 10) > 0) ? 1 : 0);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# List all the files in a Tree of Directories
|
|
2
|
+
|
|
3
|
+
if phantom.args.length != 1
|
|
4
|
+
console.log "Usage: phantomjs scandir.js DIRECTORY_TO_SCAN"
|
|
5
|
+
phantom.exit()
|
|
6
|
+
scanDirectory = (path) ->
|
|
7
|
+
fs = require 'fs'
|
|
8
|
+
if fs.exists(path) and fs.isFile(path)
|
|
9
|
+
console.log path
|
|
10
|
+
else if fs.isDirectory(path)
|
|
11
|
+
fs.list(path).forEach (e) ->
|
|
12
|
+
scanDirectory path + "/" + e if e != "." and e != ".."
|
|
13
|
+
|
|
14
|
+
scanDirectory phantom.args[0]
|
|
15
|
+
phantom.exit()
|