[Pkg-javascript-commits] [less.js] 14/88: Implement postProcessor callback feature for less.ls browser environment #1835

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


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

js pushed a commit to annotated tag v1.7.0
in repository less.js.

commit 0a7954355a503d190dd73856bbe3c361f2f2b216
Author: Cloud Chen <cloudcmh at gmail.com>
Date:   Mon Feb 3 00:02:49 2014 +0800

    Implement postProcessor callback feature for less.ls browser environment #1835
    
    Add `jasmine:postProcessor` task and corresponding spec as well
---
 Gruntfile.js                                       |  8 ++++++++
 lib/less/browser.js                                | 15 +++++++++++++--
 test/browser/css/postProcessor/postProcessor.css   |  4 ++++
 test/browser/less/postProcessor/postProcessor.less |  4 ++++
 test/browser/runner-postProcessor-options.js       |  4 ++++
 test/browser/runner-postProcessor.js               |  3 +++
 6 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/Gruntfile.js b/Gruntfile.js
index f931cad..c684401 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -214,6 +214,14 @@ module.exports = function(grunt) {
           specs: 'test/browser/runner-global-vars-spec.js',
           outfile: 'tmp/browser/test-runner-global-vars.html'
         }
+      },
+      postProcessor: {
+        src: ['test/browser/less/postProcessor/*.less'],
+        options: {
+          helpers: 'test/browser/runner-postProcessor-options.js',
+          specs: 'test/browser/runner-postProcessor.js',
+          outfile: 'tmp/browser/test-postProcessor.html'
+        }
       }
     },
 
diff --git a/lib/less/browser.js b/lib/less/browser.js
index ffcf82f..f89eb9e 100644
--- a/lib/less/browser.js
+++ b/lib/less/browser.js
@@ -159,6 +159,13 @@ function createCSS(styles, sheet, lastModified) {
     }
 }
 
+function postProcessCSS(styles) {
+    if (less.postProcessor && typeof less.postProcessor === 'function') {
+        styles = less.postProcessor.call(styles, styles) || styles;
+    }
+    return styles;
+}
+
 function errorHTML(e, rootHref) {
     var id = 'less-error-message:' + extractId(rootHref || "");
     var template = '<li><label>{line}</label><pre class="{class}">{content}</pre></li>';
@@ -575,7 +582,9 @@ function initRunningMode(){
                     if (e) {
                         error(e, sheet.href);
                     } else if (root) {
-                        createCSS(root.toCSS(less), sheet, env.lastModified);
+                        var styles = root.toCSS(less);
+                        styles = postProcessCSS(styles);
+                        createCSS(styles, sheet, env.lastModified);
                     }
                 });
             }
@@ -645,7 +654,9 @@ less.refresh = function (reload, modifyVars) {
             log("loading " + sheet.href + " from cache.", logLevel.info);
         } else {
             log("parsed " + sheet.href + " successfully.", logLevel.info);
-            createCSS(root.toCSS(less), sheet, env.lastModified);
+            var styles = root.toCSS(less);
+            styles = postProcessCSS(styles);
+            createCSS(styles, sheet, env.lastModified);
         }
         log("css for " + sheet.href + " generated in " + (new Date() - endTime) + 'ms', logLevel.info);
         if (env.remaining === 0) {
diff --git a/test/browser/css/postProcessor/postProcessor.css b/test/browser/css/postProcessor/postProcessor.css
new file mode 100644
index 0000000..76de30b
--- /dev/null
+++ b/test/browser/css/postProcessor/postProcessor.css
@@ -0,0 +1,4 @@
+hr {height:50px;}
+.test {
+  color: #ffffff;
+}
diff --git a/test/browser/less/postProcessor/postProcessor.less b/test/browser/less/postProcessor/postProcessor.less
new file mode 100644
index 0000000..0d4c030
--- /dev/null
+++ b/test/browser/less/postProcessor/postProcessor.less
@@ -0,0 +1,4 @@
+ at color: white;
+.test {
+    color: @color;
+}
diff --git a/test/browser/runner-postProcessor-options.js b/test/browser/runner-postProcessor-options.js
new file mode 100644
index 0000000..94044da
--- /dev/null
+++ b/test/browser/runner-postProcessor-options.js
@@ -0,0 +1,4 @@
+var less = {};
+less.postProcessor = function(styles) {
+    return 'hr {height:50px;}\n' + styles;
+};
diff --git a/test/browser/runner-postProcessor.js b/test/browser/runner-postProcessor.js
new file mode 100644
index 0000000..be9eb24
--- /dev/null
+++ b/test/browser/runner-postProcessor.js
@@ -0,0 +1,3 @@
+describe("less.js postProcessor", function() {
+  testLessEqualsInDocument();
+});

-- 
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