Skip to content

Commit

Permalink
Support for reversing property names
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeapage committed Feb 18, 2015
1 parent 10153ef commit 23b2e72
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
21 changes: 19 additions & 2 deletions lib/rtl-plugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function(less) {

function RTLPlugin() {
this._visitor = new less.visitors.Visitor(this);
};
Expand All @@ -22,7 +22,24 @@ module.exports = function(less) {
return this._visitor.visit(root);
},
visitRule: function (ruleNode, visitArgs) {
if (ruleNode.name === "float") {
if (!ruleNode.variable && ruleNode.name.match(/(^|-)(left|right)($|-)/)) {
return new less.tree.Rule(
ruleNode.name.replace(/(^|-)(left|right)($|-)/, function(allOfMatch, leftPart, replacePart, rightPart) {
if (replacePart === "left") {
replacePart = "right";
} else {
replacePart = "left";
}
return leftPart + replacePart + rightPart;
}),
ruleNode.value,
ruleNode.important,
ruleNode.merge,
ruleNode.index,
ruleNode.currentFileInfo,
ruleNode.inline,
ruleNode.variable);
} else if (ruleNode.name === "float") {
this._reverseKeywords = true;
}
return ruleNode;
Expand Down
6 changes: 6 additions & 0 deletions test/css/rtl/test.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
.reverse {
float: right;
float: left /*comment*/;
margin-right: 5px;
padding-left: 3px;
font-size: 12px;
/* unchanged*/
right: 3px;
border-right-style: dashed;
}
7 changes: 6 additions & 1 deletion test/less/rtl/test.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
.reverse {
float: left;
float: right/*comment*/;
}
margin-left: 5px;
padding-right: 3px;
font-size: 12px; /* unchanged*/
left: 3px;
border-left-style: dashed;
}

0 comments on commit 23b2e72

Please sign in to comment.