Kévin Tessier 04fab6ba46 install gulp | 6 jaren geleden | |
---|---|---|
.. | ||
bin | 6 jaren geleden | |
doc | 6 jaren geleden | |
lib | 6 jaren geleden | |
.npmignore | 6 jaren geleden | |
.travis.yml | 6 jaren geleden | |
CHANGELOG.md | 6 jaren geleden | |
MIT-LICENSE.txt | 6 jaren geleden | |
README.md | 6 jaren geleden | |
TODO.nani | 6 jaren geleden | |
package.json | 6 jaren geleden |
Parse CSS.
Parameters:
{String} css
{{syntax: String, rule: String}} options
Returns:
{Object} ast
.Example:
var css = 'a {color: tomato}';
var ast = gonzales.parse(css);
Example:
var less = 'a {$color: tomato}';
var ast = gonzales.parse(less, {syntax: 'less'});
Example:
var less = '$color: tomato';
var ast = gonzales.parse(less, {syntax: 'less', rule: 'declaration'});
Creates a new node.
Parameters:
{{type: String, content: String|Array}} options
Returns:
{Object} ast
Example:
var css = 'a {color: tomato}';
var ast = gonzales.parse(css);
var node = gonzales.createNode({ type: 'animal', content: 'panda' });
ast.content.push(node);
Converts AST to code.
Parameters:
{String} syntax
Returns:
{String} css
Example:
var css = ast.toCSS('css');
var less = ast.toCSS('less');
Checks whether there is a child node of given type.
Parameters:
{String} type
Returns:
{Boolean}
Example:
if (ast.contains('panda'))
doSomething();
Returns the first child node of given type.
Parameters:
{String=} type
Returns:
{Node} node
Example:
var node = ast.first();
node.content = 'panda';
Example:
var node = ast.first('commentML');
node.content = 'panda';
Calls the function for every child node of given type.
Parameters:
{String=} type
{Function} function
Example:
ast.forEach('commentML', function(node) {
node.content = 'panda';
});
Checks whether the node is of given type.
Parameters:
{String} type
Returns:
{Boolean}
Example:
if (ast.is('s'))
ast.content = '';
Returns the last child node of given type.
Parameters:
{String=} type
Returns:
{Node} node
Example:
var node = ast.last()
node.content = 'panda';
Example:
var node = ast.last('commentML');
node.content = 'panda';
Calls the function for every node in a tree. Modifies the tree!
Parameters:
{Function} function
Example:
ast.map(function(node) {
if (node.type === 'commentML') node.content = 'panda';
});
To run tests:
npm test
This command will build library files from sources and run tests on all files in syntax directories.
Every test has 3 files: source stylesheet, expected AST and expected string compiled back from AST to css.
If some tests fail, you can find information in test logs:
log/test.log
contains all information from stdout;log/expected.txt
contains only expected text;log/result.txt
contains only result text.The last two are made for your convenience: you can use any diff app to see the defference between them.
If you want to test one specific string or get a general idea of how Gonzales
works, you can use test/ast.js
file.
Simply change the first two strings (css
and syntax
vars) and run:
node test/single-test.js
If you find a bug or want to add a feature, welcome to Issues.
If you are shy but have a question, feel free to drop me a line.