0.7.0 • Published 10 years ago

codio-css-utils v0.7.0

Weekly downloads
2
License
MIT
Repository
bitbucket
Last release
10 years ago

codio-css-utils

This packages was developed for easing the use of the npm 'css' package.

It was developed for http://codio.com to ease the development of assessing student's code during the web development course.

It takes a css file path and return a AST object (which include the ast parsed by css package)

Example :

var ast_object = cssutils.get_ast(stylepath);

Then, the ast_object has 1 variable that you can access :

  • ast which returns the css ast as parsed by the css package

And 4 functions :

  • get_rules_for_selector = function(selector)

This returns all the css rules found for a specific selector.

  • get_declarations_for_selector = function(selector)

This returns all the declarations found for a specific selector

  • selector_has_property_anyvalue = function(selector, property)

This returns true if selector has the property given with any value.

  • selector_has_property = function(selector, property, property_value)

This returns true if selector has the property given with the value property_value.

Here is a full example :

var cssutils = require('codio-css-utils');

var errors = [];
var basepath = '/home/codio/workspace';
var stylepath = basepath + "/9-text-color/style.css";


var ast = cssutils.get_ast(stylepath);

if (ast.ast == undefined) {
    errors.push(stylepath + " doesn't exist or cannot be parsed");   
} else {
    if (!ast.selector_has_property("h1","color","red")) {
      errors.push("h1 doesnt have color red");
    }
  
    if (!ast.selector_has_property("h2","color","orange")) {
      errors.push("h2 doesnt have color orange");
    }
  
    if (!ast.selector_has_property("p","color","blue")) {
      errors.push("p doesnt have color blue");
    }
}

if( errors.length <= 0 ) {
    process.stdout.write('Well done!!!');
    process.exit(0);
}
else {
    process.stdout.write(errors.join("\n"));
    process.exit(1);
}
0.7.0

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago