Skip to content
Browse files

handles important declarations. fixes and closes #11

  • Loading branch information...
1 parent 313dea6 commit 99ad94030bcba0eb22c7defc125716f9077866d4 @ded committed
Showing with 22 additions and 14 deletions.
  1. +1 −0 -o
  2. +10 −6 example.css
  3. +1 −1 example.rtl.css
  4. +1 −1 package.json
  5. +9 −6 r2.js
View
1 -o
@@ -0,0 +1 @@
+body{direction:rtl;float:right;margin-right:2px;padding:1px 4px 3px 2px;left:5px;}div{text-align:left;margin-right:5px !important;float:left!important;}
View
16 example.css
@@ -1,10 +1,14 @@
body {
- direction: ltr;
- float: left;
- margin-left: 2px;
- padding: 1px 2px 3px 4px;
- right: 5px;
+ direction: ltr; /* special value swap */
+ float: left; /* basic value swap */
+ margin-left: 2px; /* basic property swap */
+ padding: 1px 2px 3px 4px; /* quad swap */
+ right: 5px; /* basic property swap */
}
div {
- text-align: right;
+ text-align: right; /* value swap */
+ margin-right: 5px !important; /* property swap and keeps !important */
+ float: right!important; /* changes to float:left!important */
+ color: blue; /* don't mess with normal properties */
+ font-family: helvetica !important; /* put back important on normal properties */
}
View
2 example.rtl.css
@@ -1 +1 @@
-body{direction:rtl;float:right;margin-right:2px;padding:1px 4px 3px 2px;left:5px;}div{text-align:left;}
+body{direction:rtl;float:right;margin-right:2px;padding:1px 4px 3px 2px;left:5px;}div{text-align:left;margin-left:5px !important;float:left!important;color:blue;font-family:helvetica !important;}
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "R2",
"description": "a CSS LTR ∞ RTL converter",
- "version": "1.1.2",
+ "version": "1.2.0",
"homepage": "https://github.com/ded/r2",
"author": "Dustin Diaz <@ded>",
"main": "r2.js",
View
15 r2.js
@@ -26,12 +26,12 @@ function quad_radius(v, m) {
}
function direction(v) {
- return v == 'ltr' ? 'rtl' : v == 'rtl' ? 'ltr' : v
+ return v.match(/ltr/) ? 'rtl' : v.match(/rtl/) ? 'ltr' : v
}
function rtltr(v) {
- if (v == 'left') return 'right'
- if (v == 'right') return 'left'
+ if (v.match(/left/)) return 'right'
+ if (v.match(/right/)) return 'left'
return v
}
@@ -114,8 +114,11 @@ function r2(css) {
if (!m) return ''
var prop = m[1]
, val = m[2]
+ , important = /!important/
+ , isImportant = val.match(important)
prop = propertyMap[prop] || prop
val = valueMap[prop] ? valueMap[prop](val) : val
+ if (!val.match(important) && isImportant) val += '!important'
return prop + ':' + val + ';'
}).join('') + '}'
@@ -141,7 +144,7 @@ module.exports.exec = function (args) {
var buffer = ''
process.stdin.resume()
process.stdin.setEncoding('utf8')
-
+
process.stdin.on('data', function(chunk) {
buffer += chunk
});
@@ -152,12 +155,12 @@ module.exports.exec = function (args) {
}
});
} else {
- /*
+ /*
/ If reading from a file then print to stdout or out arg
/ To stdout: r2 styles.css
/ To file: r2 styles.cc styles-rtl.css
*/
- data = fs.readFileSync(read, 'utf8')
+ data = fs.readFileSync(read, 'utf8')
if (out) {
console.log('Swapping ' + read + ' to ' + out + '...')
fs.writeFileSync(out, r2(data), 'utf8')

0 comments on commit 99ad940

Please sign in to comment.
Something went wrong with that request. Please try again.