[Pkg-javascript-commits] [less.js] 58/88: minor `%` func improvement: preserve quote char and escaped flag, updated tests.
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:22:26 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 768a5cbc8459d82c4cc725719024900b6b264850
Author: seven-phases-max <seven.phases.max at gmail.com>
Date: Tue Feb 18 18:56:46 2014 +0400
minor `%` func improvement: preserve quote char and escaped flag, updated tests.
---
lib/less/functions.js | 18 +++++++++---------
test/css/functions.css | 5 +++++
test/less/functions.less | 7 ++++++-
3 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/lib/less/functions.js b/lib/less/functions.js
index 552f052..2c269a9 100644
--- a/lib/less/functions.js
+++ b/lib/less/functions.js
@@ -218,25 +218,25 @@ 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"));
},
- replace: function (subject, pattern, replacement, flags) {
- var str = subject.value;
+ replace: function (string, pattern, replacement, flags) {
+ var result = string.value;
- str = str.replace(new RegExp(pattern.value, flags ? flags.value : ""), replacement.value);
- return new(tree.Quoted)(subject.quote || '', str, subject.escaped);
+ result = result.replace(new RegExp(pattern.value, flags ? flags.value : ''), replacement.value);
+ return new(tree.Quoted)(string.quote || '', result, string.escaped);
},
- '%': function (quoted /* arg, arg, ...*/) {
+ '%': function (string /* arg, arg, ...*/) {
var args = Array.prototype.slice.call(arguments, 1),
- str = quoted.value;
+ result = string.value;
for (var i = 0; i < args.length; i++) {
/*jshint loopfunc:true */
- str = str.replace(/%[sda]/i, function(token) {
+ result = result.replace(/%[sda]/i, function(token) {
var value = token.match(/s/i) ? args[i].value : args[i].toCSS();
return token.match(/[A-Z]$/) ? encodeURIComponent(value) : value;
});
}
- str = str.replace(/%%/g, '%');
- return new(tree.Quoted)('"' + str + '"', str);
+ result = result.replace(/%%/g, '%');
+ return new(tree.Quoted)(string.quote || '', result, string.escaped);
},
unit: function (val, unit) {
if(!(val instanceof tree.Dimension)) {
diff --git a/test/css/functions.css b/test/css/functions.css
index 277bb1b..17509c1 100644
--- a/test/css/functions.css
+++ b/test/css/functions.css
@@ -48,10 +48,15 @@
replace: "Hello, World!";
replace-captured: "This is a new string.";
replace-with-flags: "2 + 2 = 4";
+ replace-single-quoted: 'foo-2';
+ replace-escaped-string: bar-2;
+ replace-keyword: baz-2;
format: "rgb(32, 128, 64)";
format-string: "hello world";
format-multiple: "hello earth 2";
format-url-encode: "red is %23ff0000";
+ format-single-quoted: 'hello single world';
+ format-escaped-string: hello escaped world;
eformat: rgb(32, 128, 64);
unitless: 12;
unit: 14em;
diff --git a/test/less/functions.less b/test/less/functions.less
index ba9fe07..87686be 100644
--- a/test/less/functions.less
+++ b/test/less/functions.less
@@ -52,10 +52,15 @@
replace: replace("Hello, Mars.", "Mars\.", "World!");
replace-captured: replace("This is a string.", "(string)\.$", "new $1.");
replace-with-flags: replace("One + one = 4", "one", "2", "gi");
+ replace-single-quoted: replace('foo-1', "1", "2");
+ replace-escaped-string: replace(~"bar-1", "1", "2");
+ replace-keyword: replace(baz-1, "1", "2");
format: %("rgb(%d, %d, %d)", @r, 128, 64);
format-string: %("hello %s", "world");
format-multiple: %("hello %s %d", "earth", 2);
- format-url-encode: %('red is %A', #ff0000);
+ format-url-encode: %("red is %A", #ff0000);
+ format-single-quoted: %('hello %s', "single world");
+ format-escaped-string: %(~"hello %s", "escaped world");
eformat: e(%("rgb(%d, %d, %d)", @r, 128, 64));
unitless: unit(12px);
--
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