fixes #130 - added a Dummy colorizer
This is to allow having no output coloration. A new `colorizerType` casper option has been added to choose between the `Colorizer` and `Dummy` types. Usage: var casper = require('casper').create({ colorizerType: 'Dummy' // no color added });
Showing
2 changed files
with
38 additions
and
6 deletions
... | @@ -66,6 +66,7 @@ var Casper = function Casper(options) { | ... | @@ -66,6 +66,7 @@ var Casper = function Casper(options) { |
66 | // default options | 66 | // default options |
67 | this.defaults = { | 67 | this.defaults = { |
68 | clientScripts: [], | 68 | clientScripts: [], |
69 | colorizerType: 'Colorizer', | ||
69 | exitOnError: true, | 70 | exitOnError: true, |
70 | logLevel: "error", | 71 | logLevel: "error", |
71 | httpStatusHandlers: {}, | 72 | httpStatusHandlers: {}, |
... | @@ -88,10 +89,12 @@ var Casper = function Casper(options) { | ... | @@ -88,10 +89,12 @@ var Casper = function Casper(options) { |
88 | timeout: null, | 89 | timeout: null, |
89 | verbose: false | 90 | verbose: false |
90 | }; | 91 | }; |
92 | // options | ||
93 | this.options = utils.mergeObjects(this.defaults, options); | ||
91 | // properties | 94 | // properties |
92 | this.checker = null; | 95 | this.checker = null; |
93 | this.cli = phantom.casperArgs; | 96 | this.cli = phantom.casperArgs; |
94 | this.colorizer = colorizer.create(); | 97 | this.colorizer = this.getColorizer(); |
95 | this.currentUrl = 'about:blank'; | 98 | this.currentUrl = 'about:blank'; |
96 | this.currentHTTPStatus = 200; | 99 | this.currentHTTPStatus = 200; |
97 | this.defaultWaitTimeout = 5000; | 100 | this.defaultWaitTimeout = 5000; |
... | @@ -106,7 +109,6 @@ var Casper = function Casper(options) { | ... | @@ -106,7 +109,6 @@ var Casper = function Casper(options) { |
106 | error: 'ERROR' | 109 | error: 'ERROR' |
107 | }; | 110 | }; |
108 | this.mouse = mouse.create(this); | 111 | this.mouse = mouse.create(this); |
109 | this.options = utils.mergeObjects(this.defaults, options); | ||
110 | this.page = null; | 112 | this.page = null; |
111 | this.pendingWait = false; | 113 | this.pendingWait = false; |
112 | this.requestUrl = 'about:blank'; | 114 | this.requestUrl = 'about:blank'; |
... | @@ -125,7 +127,7 @@ var Casper = function Casper(options) { | ... | @@ -125,7 +127,7 @@ var Casper = function Casper(options) { |
125 | this.initErrorHandler(); | 127 | this.initErrorHandler(); |
126 | 128 | ||
127 | this.on('error', function(msg, backtrace) { | 129 | this.on('error', function(msg, backtrace) { |
128 | var c = colorizer.create(); | 130 | var c = this.getColorizer(); |
129 | var match = /^(.*): __mod_error(.*):: (.*)/.exec(msg); | 131 | var match = /^(.*): __mod_error(.*):: (.*)/.exec(msg); |
130 | var notices = []; | 132 | var notices = []; |
131 | if (match && match.length === 4) { | 133 | if (match && match.length === 4) { |
... | @@ -574,6 +576,16 @@ Casper.prototype.forward = function forward(then) { | ... | @@ -574,6 +576,16 @@ Casper.prototype.forward = function forward(then) { |
574 | }; | 576 | }; |
575 | 577 | ||
576 | /** | 578 | /** |
579 | * Creates a new Colorizer instance. Sets `Casper.options.type` to change the | ||
580 | * colorizer type name (see the `colorizer` module). | ||
581 | * | ||
582 | * @return Object | ||
583 | */ | ||
584 | Casper.prototype.getColorizer = function getColorizer() { | ||
585 | return colorizer.create(this.options.colorizerType || 'Colorizer'); | ||
586 | }; | ||
587 | |||
588 | /** | ||
577 | * Retrieves current document url. | 589 | * Retrieves current document url. |
578 | * | 590 | * |
579 | * @return String | 591 | * @return String | ... | ... |
... | @@ -31,13 +31,19 @@ | ... | @@ -31,13 +31,19 @@ |
31 | var fs = require('fs'); | 31 | var fs = require('fs'); |
32 | var utils = require('utils'); | 32 | var utils = require('utils'); |
33 | 33 | ||
34 | exports.create = function create() { | 34 | exports.create = function create(type) { |
35 | return new Colorizer(); | 35 | if (!type) { |
36 | return; | ||
37 | } | ||
38 | if (!(type in exports)) { | ||
39 | throw new Error(utils.format('Unsupported colorizer type "%s"', type)); | ||
40 | } | ||
41 | return new exports[type](); | ||
36 | }; | 42 | }; |
37 | 43 | ||
38 | /** | 44 | /** |
39 | * This is a port of lime colorizer. | 45 | * This is a port of lime colorizer. |
40 | * http://trac.symfony-project.org/browser/tools/lime/trunk/lib/lime.php) | 46 | * http://trac.symfony-project.org/browser/tools/lime/trunk/lib/lime.php |
41 | * | 47 | * |
42 | * (c) Fabien Potencier, Symfony project, MIT license | 48 | * (c) Fabien Potencier, Symfony project, MIT license |
43 | */ | 49 | */ |
... | @@ -102,3 +108,17 @@ var Colorizer = function Colorizer() { | ... | @@ -102,3 +108,17 @@ var Colorizer = function Colorizer() { |
102 | }; | 108 | }; |
103 | }; | 109 | }; |
104 | exports.Colorizer = Colorizer; | 110 | exports.Colorizer = Colorizer; |
111 | |||
112 | /** | ||
113 | * Dummy colorizer. Does basically nothing. | ||
114 | * | ||
115 | */ | ||
116 | var Dummy = function Dummy() { | ||
117 | this.colorize = function colorize(text, styleName, pad) { | ||
118 | return text; | ||
119 | }; | ||
120 | this.format = function format(text, style, pad){ | ||
121 | return text; | ||
122 | }; | ||
123 | }; | ||
124 | exports.Dummy = Dummy; | ... | ... |
-
Please register or sign in to post a comment