This commit is contained in:
Rafael Caricio 2014-09-06 18:13:10 +02:00
parent a55f942895
commit fde01a6cf1
2 changed files with 11 additions and 37 deletions

View file

@ -113,23 +113,11 @@ module.exports = (function() {
}
function matchSideOrCorner() {
var captures = scan(tokens.sideOrCorner);
if (captures) {
return {
type: 'directional',
value: captures[1].toLowerCase()
};
}
return match('directional', tokens.sideOrCorner, 1);
}
function matchAngle() {
var captures = scan(tokens.angleValue);
if (captures) {
return {
type: 'angle',
value: captures[1]
};
}
return match('angular', tokens.angleValue, 1);
}
function matchListing(matcher) {
@ -170,25 +158,11 @@ module.exports = (function() {
}
function matchLiteralColor() {
var captures = scan(tokens.literalColor);
if (captures) {
return {
type: 'literal',
value: captures[0].toLowerCase()
};
}
return match('literal', tokens.literalColor, 0);
}
function matchHexColor() {
var captures = scan(tokens.hexColor);
if (captures) {
return {
type: 'hex',
value: captures[1]
};
}
return match('hex', tokens.hexColor, 1);
}
function matchRGBColor() {
@ -214,17 +188,17 @@ module.exports = (function() {
}
function matchLength() {
return matchMetric(tokens.pixelValue, 'px') ||
matchMetric(tokens.percentageValue, '%') ||
matchMetric(tokens.emValue, 'em');
return match('px', tokens.pixelValue, 1) ||
match('%', tokens.percentageValue, 1) ||
match('em', tokens.emValue, 1);
}
function matchMetric(pattern, metric) {
function match(type, pattern, captureIndex) {
var captures = scan(pattern);
if (captures) {
return {
type: metric,
value: captures[1]
type: type,
value: captures[captureIndex]
};
}
}

View file

@ -153,7 +153,7 @@ describe('gradient-parser.js', function () {
});
[
{type: 'angle', unparsedValue: '145deg', value: '145'},
{type: 'angular', unparsedValue: '145deg', value: '145'},
{type: 'directional', unparsedValue: 'to left top', value: 'left top'}
].forEach(function(orientation) {
describe('parse orientation ' + orientation.type, function() {