Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

git add

  • Loading branch information...
commit b76a247d2cfad1051d8e624c5414a96add366637 1 parent 0e3e64b
James Campos authored

Showing 2 changed files with 68 additions and 0 deletions. Show diff stats Hide diff stats

  1. +54 0 lib/ccss.js
  2. +14 0 package.json
54 lib/ccss.js
... ... @@ -0,0 +1,54 @@
  1 +var extend, fs;
  2 +fs = require('fs');
  3 +extend = function(object, properties) {
  4 + var key, value;
  5 + for (key in properties) {
  6 + value = properties[key];
  7 + object[key] = value;
  8 + }
  9 + return object;
  10 +};
  11 +this.compile = function(rules) {
  12 + var css, declarations, key, mix, mixin, nested, pairs, selector, value, _i, _len;
  13 + css = '';
  14 + for (selector in rules) {
  15 + pairs = rules[selector];
  16 + declarations = '';
  17 + nested = {};
  18 + if (mixin = pairs.mixin, pairs) {
  19 + delete pairs.mixin;
  20 + if (!(mixin instanceof Array)) {
  21 + mixin = [mixin];
  22 + }
  23 + for (_i = 0, _len = mixin.length; _i < _len; _i++) {
  24 + mix = mixin[_i];
  25 + extend(pairs, mix);
  26 + }
  27 + }
  28 + for (key in pairs) {
  29 + value = pairs[key];
  30 + if (typeof value === 'object') {
  31 + nested["" + selector + " " + key] = value;
  32 + } else {
  33 + key = key.replace(/[A-Z]/g, function(s) {
  34 + return '-' + s.toLowerCase();
  35 + });
  36 + declarations += " " + key + ": " + value + ";\n";
  37 + }
  38 + }
  39 + if (declarations) {
  40 + css += selector + ' {\n';
  41 + css += declarations;
  42 + css += '}\n';
  43 + }
  44 + css += this.compile(nested);
  45 + }
  46 + return css;
  47 +};
  48 +this.compileFile = function(infile, outfile) {
  49 + var css, rules;
  50 + rules = require(process.cwd() + '/' + infile);
  51 + css = this.compile(rules);
  52 + outfile || (outfile = infile.replace(/coffee$/, 'css'));
  53 + return fs.writeFileSync(outfile, css);
  54 +};
14 package.json
... ... @@ -0,0 +1,14 @@
  1 +{
  2 + "name": "ccss",
  3 + "description": "CoffeeScript CSS",
  4 + "version": "0.0.0",
  5 + "repository": "git://github.com/aeosynth/ccss.git",
  6 + "author": "James Campos <james.r.campos@gmail.com>",
  7 + "main": "ccss",
  8 + "directories": {
  9 + "lib": "lib"
  10 + },
  11 + "engines": {
  12 + "node": "*"
  13 + }
  14 +}

0 comments on commit b76a247

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