Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

backup changes

  • Loading branch information...
commit a80eb710469fbaa107b8b85bc2a9641f17c65dcf 1 parent e3d0583
@afelix afelix authored
View
0  USAGE
No changes.
View
1  VERSION
@@ -0,0 +1 @@
+CSSP v0.0.1
View
14 bin/cssp
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && SELF_PATH="$SELF_PATH/$(basename -- "$0")"
+
+while [ -h "$SELF_PATH" ]; do
+ DIR=$(dirname -- "$SELF_PATH")
+ SYM=$(readlink -- "$SELF_PATH")
+ SELF_PATH=$(cd -- "$DIR" && cd -- $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
+done
+
+CSSP_HOME=$(dirname -- "$(dirname -- "$SELF_PATH")")
+
+node $CSSP_HOME/lib/cssp.js $@
+
View
82 lib/cssp.js
@@ -0,0 +1,82 @@
+var fs = require('fs'),
+ cssptt = require('./../src/cssptt.js'),
+ parser = cssptt.CSSParser,
+ transformer = cssptt.CSSTransformer,
+ translator = cssptt.CSSTranslator,
+ tree, trans;
+
+var args = process.argv.slice(2),
+ opts = args.length ? getOpts(args, [
+ '-v', '--version',
+ '-h', '--help',
+ '-d', '--dump'
+ ]) : null,
+ single = opts && opts.single,
+ pairs = opts && opts.pairs,
+ other = opts && opts.other,
+ fileName = other && other[0];
+
+var src = fs.readFileSync(fileName).toString().trim();
+
+tree = parser.matchAll(src, 'stylesheet');
+trans = transformer.matchAll(tree, 'stylesheet');
+
+if (!opts || single.contains(['-h', '--help']) || other.length > 1) {
+ printFile('USAGE');
+} else if (single.contains(['-v', '--version'])) {
+ printFile('VERSION');
+} else {
+ if (single.contains(['-d', '--dump'])) {
+ console.log(array2string(trans, 0));
+ } else {
+ console.log(translator.matchAll(trans, 'stylesheet'));
+ }
+}
+
+// Utils
+
+function array2string(a, level) {
+ var spaces = dummySpaces(level),
+ s = (level ? '\n' + spaces : '') + '[', t;
+
+ a.forEach(function(e) {
+ s += (Array.isArray(e) ? array2string(e, level + 1) : e.toString()) + ', ';
+ });
+
+ return s.substr(0, s.length - 2) + ']';
+}
+
+function dummySpaces(num) {
+ return ' '.substr(0, num * 2);
+}
+
+function getOpts(argv, o_single, o_pairs) {
+ var opts = { single : [], pairs : {}, other : [] },
+ arg,
+ i = 0;
+
+ for (; i < argv.length;) {
+ arg = argv[i];
+ if (o_single && o_single.indexOf(arg) !== -1 && (!o_pairs || o_pairs.indexOf(arg) === -1)) {
+ opts.single.push(arg);
+ } else if (o_pairs && o_pairs.indexOf(arg) !== -1 && (!o_single || o_single.indexOf(arg) === -1)) {
+ opts.pairs[arg] = argv[++i];
+ } else opts.other.push(arg);
+ i++;
+ }
+
+ opts.single.contains = function(value) {
+ if (typeof value === 'string') {
+ return this.indexOf(value) !== -1;
+ } else {
+ for (var i = 0; i < value.length; i++) if (this.indexOf(value[i]) !== -1) return true;
+ }
+ return false;
+ };
+
+ return opts;
+}
+
+function printFile(filename) {
+ console.log(fs.readFileSync(__dirname.slice(0, __dirname.lastIndexOf('/')) + '/' + filename).toString());
+}
View
15 package.json
@@ -0,0 +1,15 @@
+{
+ "name" : "cssp",
+ "description" : "CSSP — Ometa-JS based CSS parser",
+ "version" : "0.0.1",
+ "homepage": "http://github.com/afelix/cssp",
+ "author" : "Sergey Kryzhanovsky <skryzhanovsky@ya.ru> (http://github.com/afelix)",
+ "repository" : {
+ "type" : "git",
+ "url" : "http://github.com/afelix/cssp.git"
+ },
+ "bin" : "./bin/cssp",
+ "engines" : { "node" : ">=0.4.0" },
+ "licenses" : [ { "type" : "MIT" } ]
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.