Commit 2af64a19 2af64a195d4d60bdf0f2c580a8b81d6e6cd339d5 by Nicolas Perriault

Merge branch 'master' into issue-114

2 parents fa3ed042 fd9956c5
Subproject commit 100ffeb02edee0d765efd29ef897c25343e24b2d
Subproject commit 980f9a9c31054badf459e11e700fb959df24b3a7
......
......@@ -375,11 +375,9 @@ Casper.prototype.each = function each(array, fn) {
this.log("each() only works with arrays", "error");
return this;
}
(function _each(self) {
array.forEach(function _forEach(item, i) {
fn.call(self, self, item, i);
});
})(this);
array.forEach.call(this, function _forEach(item, i) {
fn.call(this, this, item, i);
});
return this;
};
......@@ -924,8 +922,8 @@ Casper.prototype.start = function start(location, then) {
}, this.options.timeout, this);
}
if (utils.isString(location) && location.length > 0) {
return this.thenOpen(location, utils.isFunction(then) ? then : this.createStep(function _step(self) {
self.log("start page is loaded", "debug");
return this.thenOpen(location, utils.isFunction(then) ? then : this.createStep(function _step() {
this.log("start page is loaded", "debug");
}));
}
return this;
......
......@@ -29,13 +29,13 @@
*/
(function(exports) {
exports.create = function create() {
return new ClientUtils();
return new this.ClientUtils();
};
/**
* Casper client-side helpers.
*/
ClientUtils = function ClientUtils() {
exports.ClientUtils = function ClientUtils() {
var BASE64_ENCODE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var BASE64_DECODE_CHARS = new Array(
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
......@@ -553,7 +553,6 @@
}
};
};
exports.ClientUtils = ClientUtils;
// silly "hack" to force having an instance available
exports.__utils__ = new exports.ClientUtils();
......
......@@ -6,7 +6,9 @@ casper.cli.drop "cli"
casper.cli.drop "casper-path"
if casper.cli.args.length is 0 and Object.keys(casper.cli.options).length is 0
casper.echo("Pass some args and options to see how they are handled by CasperJS").exit()
casper
.echo("Pass some args and options to see how they are handled by CasperJS")
.exit(1)
casper.echo "Casper CLI passed args:"
dump casper.cli.args
......
......@@ -6,7 +6,10 @@ casper.cli.drop("cli");
casper.cli.drop("casper-path");
if (casper.cli.args.length === 0 && Object.keys(casper.cli.options).length === 0) {
casper.echo("Pass some args and options to see how they are handled by CasperJS").exit();
casper
.echo("Pass some args and options to see how they are handled by CasperJS")
.exit(1)
;
}
casper.echo("Casper CLI passed args:");
......
""" A basic custom logging implementation. The idea is to (extremely) verbosely
log every received resource.
"""
###
A basic custom logging implementation. The idea is to (extremely) verbosely
log every received resource.
###
casper = require('casper').create
# Every time a resource is received, a new log entry is added to the stack
......
......@@ -20,8 +20,9 @@ casper.fetchScore = ->
terms = casper.cli.args # terms are passed through command-line arguments
if terms.length < 3
casper.echo 'Usage: casperjs googlematch.js term1, term2 [, term3]...'
casper.exit()
casper
.echo 'Usage: casperjs googlematch.js term1, term2 [, term3]...'
.exit(1)
scores = []
......
......@@ -21,7 +21,10 @@ casper.fetchScore = function() {
};
if (terms.length < 2) {
casper.echo('Usage: casperjs googlematch.js term1, term2 [, term3]...').exit();
casper
.echo('Usage: casperjs googlematch.js term1, term2 [, term3]...')
.exit(1)
;
}
casper.echo('Let the match begin!');
......
......@@ -8,8 +8,9 @@ casper = require('casper').create()
currentPage = 1
if casper.cli.args.length == 0
casper.echo "usage: $ casperjs my search terms"
casper.exit()
casper
.echo "usage: $ casperjs my search terms"
.exit(1)
processPage = ->
@echo "capturing page #{currentPage}"
......
......@@ -4,8 +4,10 @@ casper = require('casper').create();
currentPage = 1;
if (casper.cli.args.length === 0) {
casper.echo("usage: $ casperjs my search terms");
casper.exit();
casper
.echo("usage: $ casperjs my search terms")
.exit(1)
;
}
processPage = function() {
......@@ -37,4 +39,4 @@ casper.start('http://google.fr/', function() {
casper.then(processPage);
casper.run();
\ No newline at end of file
casper.run();
......
......@@ -3,8 +3,9 @@ url = casper.cli.get 0
metas = []
if not url
casper.echo "Usage: casperjs [url]"
casper.exit()
casper
.echo "Usage: casperjs [url]"
.exit(1)
casper.start url, ->
metas = @evaluate ->
......
......@@ -3,7 +3,10 @@ var casper = require("casper").create()
, metas = [];
if (!url) {
casper.echo('Usage: casperjs [url]').exit();
casper
.echo('Usage: casperjs [url]')
.exit(1)
;
}
casper.start(url, function() {
......
......@@ -11,8 +11,9 @@ twitterAccount = casper.cli.get 0
filename = casper.cli.get 1
if not twitterAccount or not filename or not /\.(png|jpg|pdf)$/i.test filename
casper.echo "Usage $ casperjs samples/screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>"
casper.exit()
casper
.echo "Usage $ casperjs samples/screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>"
.exit(1)
casper.start "https://twitter.com/#!/#{twitterAccount}", ->
capture = ->
......
......@@ -14,8 +14,10 @@ var twitterAccount = casper.cli.get(0);
var filename = casper.cli.get(1);
if (!twitterAccount || !filename || !/\.(png|jpg|pdf)$/i.test(filename)) {
casper.echo("Usage $ casperjs samples/screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>");
casper.exit();
casper
.echo("Usage $ casperjs samples/screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>")
.exit(1)
;
}
casper.start('https://twitter.com/#!/' + twitterAccount, function() {
......
......@@ -21,8 +21,9 @@ casper = require('casper').create
timeout = ~~casper.cli.get 0
if timeout < 1
casper.echo "You must pass a valid timeout value"
casper.exit()
casper
.echo "You must pass a valid timeout value"
.exit(1)
casper.echo "Will google.com load in less than #{timeout}ms?"
casper.options.timeout = timeout
......
......@@ -22,7 +22,10 @@ var casper = require('casper').create({
var timeout = ~~casper.cli.get(0);
if (timeout < 1) {
casper.echo('You must pass a valid timeout value').exit();
casper
.echo('You must pass a valid timeout value')
.exit(1)
;
}
casper.echo('Will google.com load in less than ' + timeout + 'ms?');
casper.options.timeout = timeout;
......@@ -31,4 +34,4 @@ casper.start('http://www.google.com/', function(self) {
self.echo('YES!', 'GREEN_BAR').exit();
});
casper.run();
\ No newline at end of file
casper.run();
......