Commit 3a3df80a 3a3df80a2cd31119552bc6175d4aab6752122a31 by Nicolas Perriault

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
    });
1 parent 5124ea47
......@@ -66,6 +66,7 @@ var Casper = function Casper(options) {
// default options
this.defaults = {
clientScripts: [],
colorizerType: 'Colorizer',
exitOnError: true,
logLevel: "error",
httpStatusHandlers: {},
......@@ -88,10 +89,12 @@ var Casper = function Casper(options) {
timeout: null,
verbose: false
};
// options
this.options = utils.mergeObjects(this.defaults, options);
// properties
this.checker = null;
this.cli = phantom.casperArgs;
this.colorizer = colorizer.create();
this.colorizer = this.getColorizer();
this.currentUrl = 'about:blank';
this.currentHTTPStatus = 200;
this.defaultWaitTimeout = 5000;
......@@ -106,7 +109,6 @@ var Casper = function Casper(options) {
error: 'ERROR'
};
this.mouse = mouse.create(this);
this.options = utils.mergeObjects(this.defaults, options);
this.page = null;
this.pendingWait = false;
this.requestUrl = 'about:blank';
......@@ -125,7 +127,7 @@ var Casper = function Casper(options) {
this.initErrorHandler();
this.on('error', function(msg, backtrace) {
var c = colorizer.create();
var c = this.getColorizer();
var match = /^(.*): __mod_error(.*):: (.*)/.exec(msg);
var notices = [];
if (match && match.length === 4) {
......@@ -574,6 +576,16 @@ Casper.prototype.forward = function forward(then) {
};
/**
* Creates a new Colorizer instance. Sets `Casper.options.type` to change the
* colorizer type name (see the `colorizer` module).
*
* @return Object
*/
Casper.prototype.getColorizer = function getColorizer() {
return colorizer.create(this.options.colorizerType || 'Colorizer');
};
/**
* Retrieves current document url.
*
* @return String
......
......@@ -31,13 +31,19 @@
var fs = require('fs');
var utils = require('utils');
exports.create = function create() {
return new Colorizer();
exports.create = function create(type) {
if (!type) {
return;
}
if (!(type in exports)) {
throw new Error(utils.format('Unsupported colorizer type "%s"', type));
}
return new exports[type]();
};
/**
* This is a port of lime colorizer.
* http://trac.symfony-project.org/browser/tools/lime/trunk/lib/lime.php)
* http://trac.symfony-project.org/browser/tools/lime/trunk/lib/lime.php
*
* (c) Fabien Potencier, Symfony project, MIT license
*/
......@@ -102,3 +108,17 @@ var Colorizer = function Colorizer() {
};
};
exports.Colorizer = Colorizer;
/**
* Dummy colorizer. Does basically nothing.
*
*/
var Dummy = function Dummy() {
this.colorize = function colorize(text, styleName, pad) {
return text;
};
this.format = function format(text, style, pad){
return text;
};
};
exports.Dummy = Dummy;
......