From 91025dbe7e2f184a869fa4e55fd1b1f15c535fe9 Mon Sep 17 00:00:00 2001 From: Luke Page Date: Tue, 7 Oct 2014 21:05:26 +0100 Subject: [PATCH] move browser log code out to log listener and remove option I added temporarily that wasn't an opiption --- lib/less-browser/index.js | 49 +------------------------------- lib/less-browser/log-listener.js | 43 ++++++++++++++++++++++++++++ lib/less/contexts.js | 3 +- 3 files changed, 45 insertions(+), 50 deletions(-) create mode 100644 lib/less-browser/log-listener.js diff --git a/lib/less-browser/index.js b/lib/less-browser/index.js index 86e5ec9e..4ddb66b7 100644 --- a/lib/less-browser/index.js +++ b/lib/less-browser/index.js @@ -7,9 +7,6 @@ var less; /* TODO - options is now hidden - we should expose it on the less object, but not have it "as" the less object - alternately even have it on environment - e.g. less.environment.options.fileAsync = true; - is it weird you do less = { fileAsync: true } then access as less.environment.options.fileAsync ? */ @@ -22,39 +19,7 @@ var environment = less.environment, browserImport = require("./browser-import")(options, isFileProtocol, less.logger); environment.addFileManager(browserImport); -var logLevel = { - debug: 3, - info: 2, - errors: 1, - none: 0 -}; -if (!options.loggers) { - options.loggers = [{ - debug: function(msg) { - if (options.logLevel >= logLevel.debug) { - console.log(msg); - } - }, - info: function(msg) { - if (options.logLevel >= logLevel.info) { - console.log(msg); - } - }, - warn: function(msg) { - if (options.logLevel >= logLevel.warn) { - console.warn(msg); - } - }, - error: function(msg) { - if (options.logLevel >= logLevel.error) { - console.error(msg); - } - } - }]; -} -for(var i = 0; i < options.loggers.length; i++) { - less.logger.addListener(options.loggers[i]); -} +require("./log-listener")(less, options); less.env = options.env || (location.hostname == '127.0.0.1' || location.hostname == '0.0.0.0' || @@ -64,18 +29,6 @@ less.env = options.env || (location.hostname == '127.0.0.1' || isFileProtocol ? 'development' : 'production'); -if (!options.hasOwnProperty('disableDataURIs')) { - options.disableDataURIs = true; -} - -// The amount of logging in the javascript console. -// 3 - Debug, information and errors -// 2 - Information and errors -// 1 - Errors -// 0 - None -// Defaults to 2 -less.logLevel = typeof(options.logLevel) != 'undefined' ? options.logLevel : (less.env === 'development' ? logLevel.debug : logLevel.errors); - // Load styles asynchronously (default: false) // // This is set to `false` by default, so that the body diff --git a/lib/less-browser/log-listener.js b/lib/less-browser/log-listener.js new file mode 100644 index 00000000..1b1ad59a --- /dev/null +++ b/lib/less-browser/log-listener.js @@ -0,0 +1,43 @@ +module.exports = function(less, options) { + + var logLevel_debug = 3, + logLevel_info = 2, + logLevel_errors = 1, + logLevel_none = 0; + + // The amount of logging in the javascript console. + // 3 - Debug, information and errors + // 2 - Information and errors + // 1 - Errors + // 0 - None + // Defaults to 2 + options.logLevel = typeof(options.logLevel) !== 'undefined' ? options.logLevel : (options.env === 'development' ? logLevel_debug : logLevel_errors); + + if (!options.loggers) { + options.loggers = [{ + debug: function(msg) { + if (options.logLevel >= logLevel_debug) { + console.log(msg); + } + }, + info: function(msg) { + if (options.logLevel >= logLevel_info) { + console.log(msg); + } + }, + warn: function(msg) { + if (options.logLevel >= logLevel_warn) { + console.warn(msg); + } + }, + error: function(msg) { + if (options.logLevel >= logLevel_error) { + console.error(msg); + } + } + }]; + } + for(var i = 0; i < options.loggers.length; i++) { + less.logger.addListener(options.loggers[i]); + } +}; diff --git a/lib/less/contexts.js b/lib/less/contexts.js index ca340513..96335a7a 100644 --- a/lib/less/contexts.js +++ b/lib/less/contexts.js @@ -47,8 +47,7 @@ var evalCopyProperties = [ 'sourceMap', // whether to output a source map 'importMultiple', // whether we are currently importing multiple copies 'urlArgs', // whether to add args into url tokens - 'javascriptEnabled',// option - whether JavaScript is enabled. if undefined, defaults to true - 'disableDataURIs' // option - disable data URIs (they will be converted to URL()) + 'javascriptEnabled'// option - whether JavaScript is enabled. if undefined, defaults to true ]; contexts.Eval = function(options, frames) {