Skip to content

Commit 8519aad

Browse files
committed
More tests, fixes, documentation and new version
1 parent 9b62113 commit 8519aad

File tree

7 files changed

+161
-17
lines changed

7 files changed

+161
-17
lines changed

README.md

+69-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,74 @@ $ npm install -g less-plugin-rtl
3434
$ lessc --rtl file.less out.css
3535
```
3636

37-
and to run in LTR mode..
37+
Variables
38+
=========
39+
40+
Three variables are injected `ltr` and `rtl` which will be set to true or false and `dir` which will be set to `rtl` or `ltr`.
41+
42+
Property Reversing
43+
==================
44+
45+
To be more in control of properties that get reversed, you can specify property directives
46+
47+
```
48+
.test {
49+
-ltr-padding: 0; // rule only appears in LTR
50+
-rtl-margin: 3px; // rule only appears in RTL
51+
-ltr-rtl-float: left; // rule does not get reversed in either direction if autoReverse is on
52+
-rtl-ltr-float: left; // rule does not get reversed in either direction if autoReverse is on
53+
-ltr-reverse-text-align: left; // rule gets reversed for LTR, so in this case RTL = left, LTR = right
54+
-rtl-reverse-text-align: left; // rule gets reversed for RTL, so in this case RTL = right, LTR = left
55+
}
56+
```
57+
58+
Note: The reverse rules only make sense if autoreverse is off.
59+
60+
And this produces in RTL..
61+
```
62+
.test {
63+
margin: 3px;
64+
float: left;
65+
float: left;
66+
text-align: left;
67+
text-align: right;
68+
}
69+
```
70+
71+
and in LTR...
72+
```
73+
.test {
74+
padding: 0;
75+
float: left;
76+
float: left;
77+
text-align: right;
78+
text-align: left;
79+
}
80+
```
81+
82+
CLI Options
83+
===========
3884

3985
```bash
40-
$ lessc --rtl="dir=LTR" file.less out.css
41-
```
86+
$ lessc --rtl="dir=LTR auto-reverse=false vars=false" file.less out.css
87+
```
88+
89+
auto-reverse
90+
------------
91+
92+
Whether rules should be auto reversed or require property directives as above. Defaults to true.
93+
94+
vars
95+
----
96+
97+
Whether the variables should be available. Defaults to true.
98+
99+
dir
100+
---
101+
102+
The intended direction. Defaults to RTL.
103+
104+
Programmatic Options
105+
====================
106+
107+
As above, but use `dir`, `vars` and `autoReverse` on the options object.

lib/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ LessPluginRTL.prototype = {
3131
spaceSepOptions.forEach(function(arg) {
3232
var match = arg.match(/^(--)?dir=(RTL|LTR)$/);
3333
if (match) {
34-
options.dir = match[1];
34+
options.dir = match[2];
3535
return;
3636
}
3737
match = arg.match(/^(--)?vars(=(true|false))?$/);
3838
if (match) {
39-
options.vars = match[1] !== false;
39+
options.vars = match[2] !== "false";
4040
return;
4141
}
4242

4343
match = arg.match(/^(--)?auto-reverse(=(true|false))?$/);
4444
if (match) {
45-
options.autoReverse = match[1] !== false;
45+
options.autoReverse = match[2] !== "false";
4646
return;
4747
}
4848

@@ -52,7 +52,7 @@ LessPluginRTL.prototype = {
5252

5353
options.autoReverse = options.autoReverse !== false;
5454
options.vars = options.vars !== false;
55-
options.dir = options.dir || "LTR";
55+
options.dir = options.dir || "RTL";
5656

5757
if (options.dir !== "LTR" && options.dir !== "RTL") {
5858
throw new Error("Bad direction - use LTR or RTL");

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "less-plugin-rtl",
3-
"version": "0.1.0",
3+
"version": "1.0.0",
44
"description": "ltr to rtl less plugin",
55
"homepage": "http://lesscss.org",
66
"author": {

test/css/properties-ltr/test.css

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.reverse {
2+
float: right;
3+
float: left;
4+
float: left;
5+
margin-right: 5px;
6+
margin-left: 5px;
7+
margin-left: 5px;
8+
font-size: 12px;
9+
/* unchanged*/
10+
right: 3px;
11+
left: 3px;
12+
left: 3px;
13+
}
14+
.shorthands {
15+
margin: 5px;
16+
margin: 6px 7px;
17+
margin: 1px 7px 3px;
18+
margin: 1px 4px 3px 2px;
19+
margin: 5px;
20+
margin: 6px 7px;
21+
margin: 1px 7px 3px;
22+
margin: 1px 2px 3px 4px;
23+
margin: 5px;
24+
margin: 6px 7px;
25+
margin: 1px 7px 3px;
26+
margin: 1px 2px 3px 4px;
27+
}

test/css/properties-rtl/test.css

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
.reverse {
2-
float: right;
3-
float: left;
42
float: left;
5-
margin-right: 5px;
6-
margin-left: 5px;
3+
float: right;
4+
float: right;
75
margin-left: 5px;
6+
margin-right: 5px;
7+
margin-right: 5px;
88
font-size: 12px;
99
/* unchanged*/
10-
right: 3px;
11-
left: 3px;
1210
left: 3px;
11+
right: 3px;
12+
right: 3px;
1313
}
1414
.shorthands {
1515
margin: 5px;
1616
margin: 6px 7px;
1717
margin: 1px 7px 3px;
18-
margin: 1px 4px 3px 2px;
18+
margin: 1px 2px 3px 4px;
1919
margin: 5px;
2020
margin: 6px 7px;
2121
margin: 1px 7px 3px;
22-
margin: 1px 2px 3px 4px;
22+
margin: 1px 4px 3px 2px;
2323
margin: 5px;
2424
margin: 6px 7px;
2525
margin: 1px 7px 3px;
26-
margin: 1px 2px 3px 4px;
26+
margin: 1px 4px 3px 2px;
2727
}

test/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var less = require("less"),
55
rtlPlugin = new Plugin(),
66
ltrPlugin = new Plugin("dir=LTR --auto-reverse vars=true"),
77
propertiesRtlPlugin = new Plugin("dir=RTL --auto-reverse=false"),
8+
propertiesLtrPlugin = new Plugin("dir=LTR --auto-reverse=false"),
89
stylize = less.lesscHelper.stylize;
910

1011
console.log("\n" + stylize("LESS - RTL", 'underline') + "\n");
@@ -20,6 +21,9 @@ lessTester.runTestSet(
2021
{strictMath: true, relativeUrls: true, silent: true, plugins: [propertiesRtlPlugin] },
2122
"properties-rtl/");
2223

24+
lessTester.runTestSet(
25+
{strictMath: true, relativeUrls: true, silent: true, plugins: [propertiesLtrPlugin] },
26+
"properties-ltr/");
2327

2428
if (lessTester.finish) {
2529
lessTester.finish();

test/less/properties-ltr/test.less

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.reverse {
2+
-ltr-reverse-float: left;
3+
-ltr-float: left;
4+
-rtl-reverse-float: left;
5+
-rtl-float: left;
6+
7+
-ltr-reverse-margin-left: 5px;
8+
-ltr-margin-left: 5px;
9+
-rtl-reverse-margin-left: 5px;
10+
-rtl-margin-left: 5px;
11+
12+
font-size: 12px; /* unchanged*/
13+
14+
-ltr-reverse-left: 3px;
15+
-ltr-left: 3px;
16+
-rtl-reverse-left: 3px;
17+
-rtl-left: 3px;
18+
}
19+
.shorthands {
20+
@top: 1px;
21+
@right: 2px;
22+
@bottom: 3px;
23+
@left: 4px;
24+
@all: 5px;
25+
@vertical: 6px;
26+
@horizontal: 7px;
27+
28+
-ltr-reverse-margin: @all;
29+
-ltr-reverse-margin: @vertical @horizontal;
30+
-ltr-reverse-margin: @top @horizontal @bottom;
31+
-ltr-reverse-margin: @top @right @bottom @left;
32+
33+
-ltr-margin: @all;
34+
-ltr-margin: @vertical @horizontal;
35+
-ltr-margin: @top @horizontal @bottom;
36+
-ltr-margin: @top @right @bottom @left;
37+
38+
-rtl-reverse-margin: @all;
39+
-rtl-reverse-margin: @vertical @horizontal;
40+
-rtl-reverse-margin: @top @horizontal @bottom;
41+
-rtl-reverse-margin: @top @right @bottom @left;
42+
43+
-rtl-margin: @all;
44+
-rtl-margin: @vertical @horizontal;
45+
-rtl-margin: @top @horizontal @bottom;
46+
-rtl-margin: @top @right @bottom @left;
47+
}

0 commit comments

Comments
 (0)