Commit 2af64a19 2af64a195d4d60bdf0f2c580a8b81d6e6cd339d5 by Nicolas Perriault

Merge branch 'master' into issue-114

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