css2stylus
Advanced tools
Comparing version 0.1.4 to 0.2.0
@@ -24,3 +24,3 @@ /*! | ||
Css2Stylus.Converter.prototype = Css2Stylus.prototype = { | ||
Css2Stylus.Converter.prototype = { | ||
@@ -58,3 +58,3 @@ // default options | ||
this.options.closingBracket = ''; | ||
this.options.semicolon = ''; | ||
this.options.semicolon = options.keepColons ? ':' : ''; | ||
this.options.eol = ''; | ||
@@ -67,3 +67,3 @@ } | ||
} else { | ||
this.indentation = this.repeat(' ', this.options.indent); | ||
this.indentation = this._repeat(' ', this.options.indent); | ||
} | ||
@@ -75,3 +75,3 @@ | ||
// actualy parse css | ||
this.parse(); | ||
this._parse(); | ||
@@ -81,7 +81,6 @@ return this; | ||
parse: function () { | ||
var tree = { children: {} }, | ||
self = this; | ||
_parse: function () { | ||
var tree = { children: {} }; | ||
var self = this; | ||
this.css | ||
@@ -98,10 +97,10 @@ // remove comments | ||
if (self.options.unPrefix) { | ||
declaration = self.unPrefix(declaration); | ||
declaration = self._unPrefix(declaration); | ||
} | ||
selector = self.trim(selector); | ||
selector = self._trim(selector); | ||
// skip grouped selector | ||
if (/,/.test(selector)) { | ||
path = self.addRule(path, selector); | ||
path = self._addRule(path, selector); | ||
@@ -120,10 +119,10 @@ // process | ||
_sel = selectors[i].replace(/&(.)/g, '& $1 ').replace(/& ([:\.]) /g, '&$1'); | ||
path = self.addRule(path, _sel); | ||
path = self._addRule(path, _sel); | ||
} | ||
} | ||
declaration.replace(/([^:;]+):(.+);$/mg, function (_declaration, property, value) { | ||
declaration.replace(/([^:;]+):([^;]+)/g, function (_declaration, property, value) { | ||
path.declarations.push({ | ||
property: self.trim(property), | ||
value: self.trim(value) | ||
property: self._trim(property), | ||
value: self._trim(value) | ||
}); | ||
@@ -133,6 +132,6 @@ }); | ||
this.output = this.generateOutput(tree); | ||
this.output = this._generateOutput(tree); | ||
}, | ||
unPrefix: function (declaration) { | ||
_unPrefix: function (declaration) { | ||
var propValues = {}; | ||
@@ -153,16 +152,15 @@ | ||
addRule: function (path, selector) { | ||
_addRule: function (path, selector) { | ||
return (path.children[selector] = path.children[selector] || { children: {}, declarations: [] }); | ||
}, | ||
depth: 0, | ||
generateOutput: function (tree) { | ||
_depth: 0, | ||
_generateOutput: function (tree) { | ||
var output = '', key, j, l, declarations, declaration, | ||
openingBracket = (this.options.openingBracket ? ' ' + this.options.openingBracket : ''); | ||
for (key in tree.children) { | ||
if (tree.children.hasOwnProperty(key)) { | ||
output += this.getIndent() + key + openingBracket + '\n'; | ||
this.depth++; | ||
output += this._getIndent() + key + openingBracket + '\n'; | ||
this._depth++; | ||
declarations = tree.children[key].declarations; | ||
@@ -172,8 +170,8 @@ | ||
declaration = declarations[j]; | ||
output += this.getIndent() + declaration.property + this.options.semicolon + ' ' + declaration.value + this.options.eol + '\n'; | ||
output += this._getIndent() + declaration.property + this.options.semicolon + ' ' + declaration.value + this.options.eol + '\n'; | ||
} | ||
output += this.generateOutput(tree.children[key]); | ||
this.depth--; | ||
output += this.getIndent() + this.options.closingBracket + '\n' + (this.depth === 0 ? '$n' : ''); | ||
output += this._generateOutput(tree.children[key]); | ||
this._depth--; | ||
output += this._getIndent() + this.options.closingBracket + '\n' + (this._depth === 0 ? '$n' : ''); | ||
} | ||
@@ -189,4 +187,4 @@ } | ||
// calculate correct indent | ||
getIndent: function () { | ||
return this.repeat(this.indentation, this.depth); | ||
_getIndent: function () { | ||
return this._repeat(this.indentation, this._depth); | ||
}, | ||
@@ -200,9 +198,9 @@ | ||
// string helpers | ||
trim: function (str) { | ||
// trim tabs and spaces | ||
_trim: function (str) { | ||
// _trim tabs and spaces | ||
return str.replace(/\t+/, ' ').replace(/^\s+|\s+$/g, ''); | ||
}, | ||
// repeat same string n times | ||
repeat: function (str, n) { | ||
// _repeat same string n times | ||
_repeat: function (str, n) { | ||
n = window.parseInt(n, 10); | ||
@@ -209,0 +207,0 @@ return new Array(n + 1).join(str); |
{ | ||
"name": "css2stylus", | ||
"description": "Converts CSS to Stylus.", | ||
"version": "0.1.4", | ||
"author": "Denis Ciccale (@tdecs)", | ||
"version": "0.2.0", | ||
"homepage": "http://css2stylus.com", | ||
"author": { | ||
"name": "Denis Ciccale", | ||
"email": "dciccale@gmail.com", | ||
"web": "http://twitter.com/tdecs" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Jonathan Dumaine", | ||
"email": "jonathan.dumaine@dumstruck.com", | ||
"web": "http://www.jonathan-dumaine.com" | ||
} | ||
], | ||
"repository": { | ||
@@ -24,7 +35,12 @@ "type": "git", | ||
}, | ||
"scripts": { | ||
"test": "./node_modules/.bin/nodeunit test/*.js" | ||
}, | ||
"preferGlobal": "true", | ||
"dependencies": { | ||
"yargs": "^1.2.2" | ||
"yargs": "3.*.*" | ||
}, | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"nodeunit": "^0.9.1" | ||
}, | ||
"keywords": [ | ||
@@ -31,0 +47,0 @@ "css2stylus", |
@@ -28,11 +28,14 @@ # [css2stylus.js](http://css2stylus.com) [![NPM version](https://badge.fury.io/js/css2stylus.png)](http://badge.fury.io/js/css2stylus) | ||
Examples: | ||
css2stylus -u -i 4 file1.css Use 4 space ndent and convert file1.css while unprefixing. | ||
css2stylus -c file1.css file2.css Preserve CSS syntax while converting multiple files. | ||
css2stylus -u -i 4 file1.css Use 4 space ndent and convert file1.css while unprefixing | ||
css2stylus -c file1.css file2.css Preserve CSS syntax while converting multiple files | ||
css2stylus file1.css -o styl Save processed files files into the `styl` directoy | ||
Options: | ||
-u, --unPrefix Un-prefix any property with vendor prefixes. | ||
-c, --cssSyntax Keep CSS syntax punctuation. | ||
-f, --force Overwrite existing .styl files | ||
-i, --indent Set indentation level | ||
-u, --unPrefix Un-prefix any property with vendor prefixes | ||
-c, --cssSyntax Keep CSS syntax punctuation | ||
-f, --force Overwrite existing .styl files | ||
-i, --indent Set indentation level | ||
-o, --out Specify an output directory | ||
-:, --keep-colons Keep colons: in rules | ||
``` | ||
@@ -51,9 +54,20 @@ | ||
Vim mapping to convert the selected CSS text to stylus: | ||
### Bash pipe | ||
Supports bash-style piping from stdin to stdout. | ||
Useful for integrating into an editor of choice. | ||
``sh | ||
$ cat myFile.css | css2stylus | ||
``` | ||
### Vim mapping | ||
To convert the selected CSS to stylus inside vim use the following mapping: | ||
``` | ||
" CSS2Stylus | ||
:vnoremap <leader>cs :!css2stylus -u -i 4<cr><esc> | ||
:vnoremap <leader>cs :!css2stylus -u<cr><esc> | ||
``` | ||
### Browser | ||
@@ -60,0 +74,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15647
9
186
102
1
+ Addedansi-regex@2.1.1(transitive)
+ Addedcamelcase@2.1.1(transitive)
+ Addedcliui@3.2.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedinvert-kv@1.0.0(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedlcid@1.0.0(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedos-locale@1.4.0(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedwindow-size@0.1.4(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
+ Addedy18n@3.2.2(transitive)
+ Addedyargs@3.32.0(transitive)
- Removedyargs@1.3.3(transitive)
Updatedyargs@3.*.*