First thoughts about how it should work
This commit is contained in:
parent
3f394d3f24
commit
810666de6a
2 changed files with 90 additions and 0 deletions
25
package.json
Normal file
25
package.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"name": "gradient-parser",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "Parse gradient definitions and return AST.",
|
||||||
|
"main": "./parser.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/rafaelcaricio/gradient-parser.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"parser",
|
||||||
|
"gradient",
|
||||||
|
"css",
|
||||||
|
"ast"
|
||||||
|
],
|
||||||
|
"author": "Rafael Caricio <rafael@caricio.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/rafaelcaricio/gradient-parser/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/rafaelcaricio/gradient-parser"
|
||||||
|
}
|
65
parser.js
Normal file
65
parser.js
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
// Copyright (c) 2014 Rafael Caricio. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
var Parser = (function() {
|
||||||
|
|
||||||
|
var types = {
|
||||||
|
gradients: [
|
||||||
|
'linear-gradient',
|
||||||
|
'radial-gradient',
|
||||||
|
'repeating-radial-gradient'
|
||||||
|
],
|
||||||
|
colors: [
|
||||||
|
'hex',
|
||||||
|
'rgb',
|
||||||
|
'rgba',
|
||||||
|
'hsl',
|
||||||
|
'literal'
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
function Constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
Constructor.prototype.parse = function(input) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Constructor;
|
||||||
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
var p = new Parser('linear-gradient(to right, transparent 10px, #c2c2c2 10px)');
|
||||||
|
var ast = p.parse();
|
||||||
|
|
||||||
|
if (ast == [
|
||||||
|
{
|
||||||
|
type: 'linear-gradient',
|
||||||
|
orientation: {
|
||||||
|
type: 'directional',
|
||||||
|
value: 'right'
|
||||||
|
},
|
||||||
|
colorStops: [
|
||||||
|
{
|
||||||
|
type: 'literal',
|
||||||
|
value: 'transparent',
|
||||||
|
length: {
|
||||||
|
value: '10',
|
||||||
|
type: 'px'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'hex',
|
||||||
|
value: 'c2c2c2',
|
||||||
|
length: {
|
||||||
|
value: '10',
|
||||||
|
type: 'px'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}]) {
|
||||||
|
console.log('Done!');
|
||||||
|
} else {
|
||||||
|
console.log('Keep working...');
|
||||||
|
}
|
Loading…
Reference in a new issue