From 8a7747d15ba5a8f35aac42967fa6fbda0396b121 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Thu, 25 Feb 2010 21:27:23 -0500 Subject: [PATCH] url() parsing --- lib/less/adapters/server.js | 3 ++- lib/less/node/url.js | 9 +++++++++ lib/less/parser.js | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 lib/less/node/url.js diff --git a/lib/less/adapters/server.js b/lib/less/adapters/server.js index c350a79..b77de3a 100644 --- a/lib/less/adapters/server.js +++ b/lib/less/adapters/server.js @@ -8,7 +8,8 @@ process.mixin(less, require('less/parser')); ['color', 'directive', 'operation', 'dimension', 'keyword', 'variable', 'ruleset', 'element', - 'selector', 'quoted', 'expression', 'rule', 'call' + 'selector', 'quoted', 'expression', 'rule', + 'call', 'url' ].forEach(function (n) { process.mixin(less.parser, require(path.join('less', 'node', n))); }); diff --git a/lib/less/node/url.js b/lib/less/node/url.js new file mode 100644 index 0000000..0be278b --- /dev/null +++ b/lib/less/node/url.js @@ -0,0 +1,9 @@ + +node.URL = function URL(val) { + this.value = val; +}; +node.URL.prototype = { + toCSS: function () { + return "url(" + this.value.toCSS ? this.value.toCSS() : this.value + ")"; + } +}; diff --git a/lib/less/parser.js b/lib/less/parser.js index 0ab3413..dccfb07 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -206,6 +206,13 @@ less.parser = { $(this.entities.string); }, url: function url() { + var value; + + if (! $(/url\(/g)) return; + value = $(this.entities.string) || $(/[-a-zA-Z0-9_%@$\/.&=:;#+?]+/g); + if (! $(')')) throw new(Error)("missing closing ) for url()"); + + return new(node.URL)(value); }, font: function font() { },