Skip to content

Commit

Permalink
Add a rtl and ltr variable
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeapage committed Feb 18, 2015
1 parent cdd8318 commit fd1cf38
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
var getRTLPlugin = require("./rtl-plugin");
var getRTLPlugin = require("./rtl-plugin"),
RTLVariablePlugin = require("./rtl-variable-plugin");

module.exports = {
install: function(less, pluginManager) {
var RTLPlugin = getRTLPlugin(less);
pluginManager.addVisitor(new RTLPlugin());
pluginManager.addPreProcessor(new RTLVariablePlugin());
}
};
13 changes: 13 additions & 0 deletions lib/rtl-variable-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function RTLVariablePlugin() {
}

RTLVariablePlugin.prototype.process = function(src, extra) {
var variable = "@rtl: true; @ltr: false;\n"
var contentsIgnoredChars = extra.imports.contentsIgnoredChars;
var filename = extra.fileInfo.filename;
contentsIgnoredChars[filename] = contentsIgnoredChars[filename] || 0;
contentsIgnoredChars[filename] += variable.length;
return variable + src;
};

module.exports = RTLVariablePlugin;
3 changes: 3 additions & 0 deletions test/css/rtl/test.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
margin: 1px 7px 3px;
margin: 1px 4px 3px 2px;
}
.rtl-only {
margin: 3px;
}
5 changes: 5 additions & 0 deletions test/less/rtl/test.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
margin: @vertical @horizontal;
margin: @top @horizontal @bottom;
margin: @top @right @bottom @left;
}
& when (@rtl) {
.rtl-only {
margin: 3px;
}
}

0 comments on commit fd1cf38

Please sign in to comment.