From f442463ab06a700fab533d9214dcac7793f619d0 Mon Sep 17 00:00:00 2001 From: es128 Date: Mon, 25 Mar 2013 18:58:03 -0300 Subject: [PATCH 1/3] config-able dumpLineNumbers option for easier debugging --- src/index.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.coffee b/src/index.coffee index 4d9d6dc..fb6b7cf 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -13,7 +13,8 @@ module.exports = class LESSCompiler compile: (data, path, callback) -> parser = new less.Parser paths: [@config.paths.root, (sysPath.dirname path)], - filename: path + filename: path, + dumpLineNumbers: if @config.optimize then null else @config.plugins?.less?.dumpLineNumbers parser.parse data, (error, tree) => return callback error.message if error? result = null From 18d40789021ded7399890789201d0afbf1080a4e Mon Sep 17 00:00:00 2001 From: es128 Date: Mon, 25 Mar 2013 19:06:25 -0300 Subject: [PATCH 2/3] instructions for configuring dumpLineNumbers option --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 5aaef55..1ffb3d9 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,12 @@ Pick a plugin version that corresponds to your minor (y) brunch version. If you want to use git version of plugin, add `"less-brunch": "git+ssh://git@github.com:brunch/less-brunch.git"`. + +### Options +Print source-file references in output via brunch config (supported options: ['comments', 'mediaquery', 'all']): +``` +config: + plugins: + less: + dumpLineNumbers: 'comments' +``` From 6e812e7a120d8e9e50c1c23b5aa6bcf7161c80df Mon Sep 17 00:00:00 2001 From: Elan Shanker Date: Tue, 26 Mar 2013 10:23:45 -0400 Subject: [PATCH 3/3] adding compiled script to repo --- lib/index.js | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 lib/index.js diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..0aba0e3 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,90 @@ +// Generated by CoffeeScript 1.6.2 +(function() { + var LESSCompiler, less, sysPath, + __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + + less = require('less'); + + sysPath = require('path'); + + module.exports = LESSCompiler = (function() { + LESSCompiler.prototype.brunchPlugin = true; + + LESSCompiler.prototype.type = 'stylesheet'; + + LESSCompiler.prototype.extension = 'less'; + + LESSCompiler.prototype._dependencyRegExp = /^ *@import ['"](.*)['"]/; + + function LESSCompiler(config) { + this.config = config; + this.getDependencies = __bind(this.getDependencies, this); + null; + } + + LESSCompiler.prototype.compile = function(data, path, callback) { + var parser, _ref, _ref1, + _this = this; + + parser = new less.Parser({ + paths: [this.config.paths.root, sysPath.dirname(path)], + filename: path, + dumpLineNumbers: this.config.optimize ? null : (_ref = this.config.plugins) != null ? (_ref1 = _ref.less) != null ? _ref1.dumpLineNumbers : void 0 : void 0 + }); + return parser.parse(data, function(error, tree) { + var err, ex, result; + + if (error != null) { + return callback(error.message); + } + result = null; + err = null; + try { + result = tree.toCSS(); + } catch (_error) { + ex = _error; + err = "" + ex.type + "Error:" + ex.message; + if (ex.filename) { + err += " in '" + ex.filename + ":" + ex.line + ":" + ex.column + "'"; + } + } + return callback(err, result); + }); + }; + + LESSCompiler.prototype.getDependencies = function(data, path, callback) { + var dependencies, parent, + _this = this; + + parent = sysPath.dirname(path); + dependencies = data.split('\n').map(function(line) { + return line.match(_this._dependencyRegExp); + }).filter(function(match) { + return (match != null ? match.length : void 0) > 0; + }).map(function(match) { + return match[1]; + }).filter(function(path) { + return !!path && path !== 'nib'; + }).map(function(path) { + if (sysPath.extname(path) !== ("." + _this.extension)) { + return path + ("." + _this.extension); + } else { + return path; + } + }).map(function(path) { + if (path.charAt(0) === '/') { + return sysPath.join(_this.config.paths.root, path.slice(1)); + } else { + return sysPath.join(parent, path); + } + }); + return process.nextTick(function() { + return callback(null, dependencies); + }); + }; + + return LESSCompiler; + + })(); + +}).call(this);