Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
support strings as properties
Example:

  @Property: "border-radius";
  ~"-webkit-@{property}": 5px;
  • Loading branch information
NDMarcel committed Mar 9, 2012
commit 3130fced359920aff9ef0af58438a3493a1874de
12 changes: 12 additions & 0 deletions lib/less/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,18 @@ less.Parser = function Parser(env) {
furthest = i;
restore();
}
} else if (name = $(this.entities.quoted)) {
if ($(/\s*:/)) {
value = $(this.value);
important = $(this.important);

if (value && $(this.end)) {
return new(tree.Rule)(name, value, important, memo);
} else {
furthest = i;
restore();
}
}
}
},

Expand Down
10 changes: 7 additions & 3 deletions lib/less/tree/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@ tree.Rule = function (name, value, important, index, inline) {
this.important = important ? ' ' + important.trim() : '';
this.index = index;
this.inline = inline || false;
this.quotedName = false;

if (name.charAt(0) === '@') {
if (!name.charAt) {
this.quotedName = true;
} else if (name.charAt(0) === '@') {
this.variable = true;
} else { this.variable = false }
};
tree.Rule.prototype.toCSS = function (env) {
if (this.variable) { return "" }
else {
return this.name + (env.compress ? ':' : ': ') +
return (this.quotedName ? this.name.toCSS(env) : this.name) +
(env.compress ? ':' : ': ') +
this.value.toCSS(env) +
this.important + (this.inline ? "" : ";");
}
};

tree.Rule.prototype.eval = function (context) {
return new(tree.Rule)(this.name,
return new(tree.Rule)(this.quotedName ? this.name.eval(context) : this.name,
this.value.eval(context),
this.important,
this.index, this.inline);
Expand Down
4 changes: 4 additions & 0 deletions test/css/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
a:nth-child(2) {
border: 1px;
}
div {
-webkit-border-radius: 5px;
border-radius: 5px;
}
7 changes: 7 additions & 0 deletions test/less/variables.less
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@quotes: "~" "~";
@q: @quotes;

@property: "border-radius";

.variables {
height: @b + @x + 0px; // 24px
color: @c;
Expand Down Expand Up @@ -52,3 +54,8 @@
a:nth-child(@a) {
border: 1px;
}

div {
~"-webkit-@{property}": 5px;
~"@{property}": 5px;
}