[Pkg-javascript-commits] [less.js] 01/88: Adding gsub function

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:22:20 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 d5f29b6b33f15a782b23bd76d56da5ea09d0b770
Author: Jake Bellacera <hi at jakebellacera.com>
Date:   Fri Aug 23 15:45:09 2013 -0700

    Adding gsub function
---
 lib/less/functions.js    | 7 +++++++
 test/css/functions.css   | 1 +
 test/less/functions.less | 1 +
 3 files changed, 9 insertions(+)

diff --git a/lib/less/functions.js b/lib/less/functions.js
index fbde54f..9968c59 100644
--- a/lib/less/functions.js
+++ b/lib/less/functions.js
@@ -213,6 +213,13 @@ tree.functions = {
     escape: function (str) {
         return new(tree.Anonymous)(encodeURI(str.value).replace(/=/g, "%3D").replace(/:/g, "%3A").replace(/#/g, "%23").replace(/;/g, "%3B").replace(/\(/g, "%28").replace(/\)/g, "%29"));
     },
+    gsub: function (str, regexp, replacement) {
+        var str = str.value;
+
+        str = str.replace(new RegExp(regexp.value, "g"), replacement.value);
+
+        return new(tree.Quoted)('"' + str + '"', str)
+    },
     '%': function (quoted /* arg, arg, ...*/) {
         var args = Array.prototype.slice.call(arguments, 1),
             str = quoted.value;
diff --git a/test/css/functions.css b/test/css/functions.css
index eacebd8..499b614 100644
--- a/test/css/functions.css
+++ b/test/css/functions.css
@@ -8,6 +8,7 @@
 }
 #built-in {
   escaped: -Some::weird(#thing, y);
+  gsub: "Hello, World!";
   lighten: #ffcccc;
   darken: #330000;
   saturate: #203c31;
diff --git a/test/less/functions.less b/test/less/functions.less
index f60dab4..d84ae6b 100644
--- a/test/less/functions.less
+++ b/test/less/functions.less
@@ -12,6 +12,7 @@
 #built-in {
   @r: 32;
   escaped: e("-Some::weird(#thing, y)");
+  gsub: gsub("Hello, Foo.", "Foo\.$", "World!");
   lighten: lighten(#ff0000, 40%);
   darken: darken(#ff0000, 40%);
   saturate: saturate(#29332f, 20%);

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