[Pkg-javascript-commits] [less.js] 128/285: change render and tree to return an object containing css and map and in the future possibly other things

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:46 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v2.0.0
in repository less.js.

commit e1726029381d56ad85695d9a3a19da844eab9020
Author: Luke Page <luke.a.page at gmail.com>
Date:   Sat Sep 20 00:29:05 2014 +0100

    change render and tree to return an object containing css and map and in the future possibly other things
---
 bin/lessc                 |  9 ++++-----
 lib/less-browser/index.js | 10 +++++-----
 lib/less/parse-tree.js    | 15 +++++++++------
 lib/less/render.js        |  4 ++--
 test/less-test.js         | 12 ++++++------
 test/modify-vars.js       |  6 +++---
 6 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/bin/lessc b/bin/lessc
index e42aac6..3f1b327 100755
--- a/bin/lessc
+++ b/bin/lessc
@@ -350,20 +350,19 @@ var parseLessFile = function (e, data) {
     options.plugins = pluginManager;
 
     less.render(data, options)
-        .then(function(css) {
+        .then(function(result) {
             if(!options.lint) {
                 if (output) {
                     ensureDirectory(output);
-                    fs.writeFileSync(output, css, 'utf8');
+                    fs.writeFileSync(output, result.css, 'utf8');
                     if (options.verbose) {
                         console.log('lessc: wrote ' + output);
                     }
                 } else {
-                    process.stdout.write(css);
+                    process.stdout.write(result.css);
                 }
                 if (options.sourceMap && !sourceMapFileInline) {
-                    // TODO change to return object instead of css.. so much simpler and can also return metrics
-                    writeSourceMap(options.sourceMap.getExternalSourceMap());
+                    writeSourceMap(result.map);
                 }
             }
         },
diff --git a/lib/less-browser/index.js b/lib/less-browser/index.js
index ba43b44..a767c60 100644
--- a/lib/less-browser/index.js
+++ b/lib/less-browser/index.js
@@ -350,12 +350,12 @@ function loadStyles(modifyVars) {
             /*jshint loopfunc:true */
             // use closure to store current style
             less.render(lessText, instanceOptions)
-                .then(bind(function(style, css) {
+                .then(bind(function(style, result) {
                     style.type = 'text/css';
                     if (style.styleSheet) {
-                        style.styleSheet.cssText = css;
+                        style.styleSheet.cssText = result.css;
                     } else {
-                        style.innerHTML = css;
+                        style.innerHTML = result.css;
                     }
                 }, null, style),
                 function(e) {
@@ -411,8 +411,8 @@ function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
         if (data) {
             instanceOptions.currentFileInfo = newFileInfo;
             less.render(data, instanceOptions)
-                .then(function(css) {
-                    callback(null, css, data, sheet, webInfo, path);
+                .then(function(result) {
+                    callback(null, result.css, data, sheet, webInfo, path);
                 },
                 function(e) {
                     callback(e, null, null, sheet);
diff --git a/lib/less/parse-tree.js b/lib/less/parse-tree.js
index baa4d93..c0ade10 100644
--- a/lib/less/parse-tree.js
+++ b/lib/less/parse-tree.js
@@ -7,13 +7,13 @@ var ParseTree = function(root, imports) {
 };
 
 ParseTree.prototype.toCSS = function(options) {
-    var evaldRoot;
+    var evaldRoot, result = {};
     try {
         evaldRoot = transformTree(this.root, options);
     } catch (e) {
         throw new LessError(e, this.imports);
     }
-    var css;
+
     try {
         var toCSSOptions = {
             compress: Boolean(options.compress),
@@ -22,9 +22,9 @@ ParseTree.prototype.toCSS = function(options) {
             numPrecision: 8};
 
         if (options.sourceMap) {
-            css = options.sourceMap.toCSS(evaldRoot, toCSSOptions, this.imports);
+            result.css = options.sourceMap.toCSS(evaldRoot, toCSSOptions, this.imports);
         } else {
-            css = evaldRoot.toCSS(toCSSOptions);
+            result.css = evaldRoot.toCSS(toCSSOptions);
         }
     } catch (e) {
         throw new LessError(e, this.imports);
@@ -35,9 +35,12 @@ ParseTree.prototype.toCSS = function(options) {
         for(var i = 0; i < postProcessors.length; i++) {
             // TODO - pass source maps
             // TODO - async
-            css = postProcessors[i].process(css, options, this.imports);
+            result.css = postProcessors[i].process(result.css, options, this.imports);
         }
     }
-    return css;
+    if (options.sourceMap) {
+        result.map = options.sourceMap.getExternalSourceMap();
+    }
+    return result;
 };
 module.exports = ParseTree;
diff --git a/lib/less/render.js b/lib/less/render.js
index 3048d92..ad98a19 100644
--- a/lib/less/render.js
+++ b/lib/less/render.js
@@ -32,8 +32,8 @@ module.exports = function(environment) {
                     if (e) { return reject(e); }
                     try {
                         var parseTree = new ParseTree(root, imports);
-                        var css = parseTree.toCSS(options);
-                        resolve(css);
+                        var result = parseTree.toCSS(options);
+                        resolve(result);
                     }
                     catch (err) { reject( err); }
                 }, options);
diff --git a/test/less-test.js b/test/less-test.js
index f00582e..8719ac9 100644
--- a/test/less-test.js
+++ b/test/less-test.js
@@ -121,10 +121,10 @@ module.exports = function() {
                 return JSON.parse(fs.readFileSync(getFilename(getBasename(file), 'vars'), 'utf8'));
             };
 
-            toCSS(options, path.join('test/less/', foldername + file), function (err, less) {
+            toCSS(options, path.join('test/less/', foldername + file), function (err, result) {
 
                 if (verifyFunction) {
-                    return verifyFunction(name, err, less, doReplacements, options.sourceMap.getExternalSourceMap());
+                    return verifyFunction(name, err, result.css, doReplacements, result.map);
                 }
                 var css_name = name;
                 if(nameModifier) { css_name = nameModifier(name); }
@@ -132,7 +132,7 @@ module.exports = function() {
                     process.stdout.write("- " + css_name + ": ");
 
                     css = css && doReplacements(css, 'test/less/' + foldername);
-                    if (less === css) { ok('OK'); }
+                    if (result.css === css) { ok('OK'); }
                     else if (err) {
                         fail("ERROR: " + (err && err.message));
                         if (isVerbose) {
@@ -140,7 +140,7 @@ module.exports = function() {
                             process.stdout.write(err.stack + "\n");
                         }
                     } else {
-                        difference("FAIL", css, less);
+                        difference("FAIL", css, result.css);
                     }
                 });
             });
@@ -216,9 +216,9 @@ module.exports = function() {
             }
 
             less.render(str, options)
-                .then(function(css) {
+                .then(function(result) {
                     // TODO integration test that calling toCSS twice results in the same css?
-                    callback(null, css);
+                    callback(null, result);
                 }, function(e) {
                     callback(e);
                 });
diff --git a/test/modify-vars.js b/test/modify-vars.js
index c4c6c5b..2aa324f 100644
--- a/test/modify-vars.js
+++ b/test/modify-vars.js
@@ -7,11 +7,11 @@ var options = {
   modifyVars: JSON.parse(fs.readFileSync("./test/less/modifyVars/extended.json", 'utf8'))
 }
 
-less.render(input, options, function (err, css) {
+less.render(input, options, function (err, result) {
   if (err) console.log(err);
-  if (css === expectedCss) {
+  if (result.css === expectedCss) {
     console.log("PASS")
   } else {
     console.log("FAIL")
   }
-})
\ No newline at end of file
+})

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list