Skip to content

Commit aa232dd

Browse files
author
Frederic Massart
committed
Add options to add, remove and ignore CSS during flipping
1 parent 4b70752 commit aa232dd

File tree

5 files changed

+1684
-14
lines changed

5 files changed

+1684
-14
lines changed

README.md

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,135 @@ Add the library to your composer.json
2424
### Flipping
2525

2626
```php
27-
$tree = new Sabberworm\CSS\Parser($css);
27+
$parser = new Sabberworm\CSS\Parser($css);
28+
$tree = $parser->parse()
2829
$rtlcss = new MoodleHQ\RTLCSS\RTLCSS($tree);
2930
$rtlcss->flip();
3031
echo $tree->render();
3132
```
3233

3334
For parsing options and rendering, refer to [Sabeerword/PHP-CSS-Parser](https://github.com/sabberworm/PHP-CSS-Parser).
3435

36+
## Output sample
37+
38+
```css
39+
.div {
40+
direction: ltr;
41+
left: 10px;
42+
border: 10px 5px 0px 2px;
43+
float: left;
44+
}
45+
```
46+
47+
Becomes:
48+
49+
```css
50+
.div {
51+
direction: rtl;
52+
right: 10px;
53+
border: 10px 2px 0px 5px;
54+
float: right;
55+
}
56+
```
57+
58+
## Options
59+
60+
You can prefix your CSS with comments starting with `/*rtl:*/` for special handling.
61+
62+
### Do not flip values
63+
64+
Prepend with `/*rtl:ignore*/`, or wrap within `/*rtl:begin:ignore*/` and `/*rtl:end:ignore*/`.
65+
66+
```css
67+
.div {
68+
/*rtl:ignore*/
69+
float: left;
70+
left: 10px;
71+
}
72+
.div {
73+
direction: ltr;
74+
/*rtl:begin:ignore*/
75+
float: left;
76+
left: 10px;
77+
/*rtl:end:ignore*/
78+
}
79+
```
80+
81+
Becomes:
82+
83+
```css
84+
.div {
85+
float: left;
86+
right: 10px;
87+
}
88+
.div {
89+
direction: rtl;
90+
float: left;
91+
left: 10px;
92+
}
93+
```
94+
95+
### Remove CSS
96+
97+
Prepend with `/*rtl:remove*/`, wrap within `/*rtl:begin:remove*/` and `/*rtl:end:remove*/`.
98+
99+
```css
100+
.div {
101+
/*rtl:remove*/
102+
float: left;
103+
left: 10px;
104+
}
105+
.div {
106+
direction: ltr;
107+
/*rtl:begin:remove*/
108+
float: left;
109+
left: 10px;
110+
/*rtl:end:remove*/
111+
}
112+
```
113+
114+
Becomes:
115+
116+
```css
117+
.div {
118+
right: 10px;
119+
}
120+
.div {
121+
direction: rtl;
122+
}
123+
```
124+
125+
### Additional CSS
126+
127+
Write the CSS in a content starting with `/*rtl:raw:`.
128+
129+
```css
130+
.div {
131+
/*rtl:raw:
132+
text-align: left;
133+
*/
134+
float: left;
135+
}
136+
```
137+
138+
Becomes:
139+
140+
```css
141+
.div {
142+
text-align: left;
143+
float: right;
144+
}
145+
```
146+
35147
## About this tool
36148

37149
This tool is very heavily inspired by [MohammaYounes/rtlcss](https://github.com/MohammadYounes/rtlcss), even though at this stage it does not include all of its features. See this library as a partial port of the latter.
38150

151+
## Credits
152+
153+
* [MohammaYounes/rtlcss](https://github.com/MohammadYounes/rtlcss) for being the example we followed.
154+
* [Sabeerword/PHP-CSS-Parser](https://github.com/sabberworm/PHP-CSS-Parser) for parsing CSS in PHP.
155+
39156
## License
40157

41158
Licensed under the [GNU GPL License](http://www.gnu.org/copyleft/gpl.html).

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"minimum-stability": "dev",
88
"repositories": [{
99
"type": "vcs",
10-
"url": "https://github.com/moodlehq/PHP-CSS-Parser"
10+
"url": "/home/fred/apps/PHP-CSS-Parser"
1111
}],
1212
"require": {
1313
"php": ">=5.4",

0 commit comments

Comments
 (0)