Make easier to match different gradient types

This commit is contained in:
Rafael Caricio 2014-09-06 12:47:36 +02:00
parent e1399c0168
commit a7981cc9dc

View file

@ -21,6 +21,7 @@ module.exports = (function() {
var tokens = { var tokens = {
linearGradient: /^linear\-gradient/i, linearGradient: /^linear\-gradient/i,
radialGradient: /^radial\-gradient/i,
sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|left|right|top|bottom)/i, sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|left|right|top|bottom)/i,
startCall: /^\(/, startCall: /^\(/,
endCall: /^\)/, endCall: /^\)/,
@ -68,11 +69,14 @@ module.exports = (function() {
} }
function matchDefinition() { function matchDefinition() {
return matchLinearGradient(); return matchGradient(
'linear-gradient',
tokens.linearGradient,
matchOrientation);
} }
function matchLinearGradient() { function matchGradient(gradientType, token, orientationMatcher) {
var captures = scan(tokens.linearGradient), var captures = scan(token),
orientation, orientation,
colorStops; colorStops;
@ -81,7 +85,7 @@ module.exports = (function() {
error('Missing ('); error('Missing (');
} }
orientation = matchOrientation(); orientation = orientationMatcher();
if (orientation) { if (orientation) {
if (!scan(tokens.comma)) { if (!scan(tokens.comma)) {
error('Missing comma before color stops'); error('Missing comma before color stops');
@ -98,7 +102,7 @@ module.exports = (function() {
} }
return { return {
type: 'linear-gradient', type: gradientType,
orientation: orientation, orientation: orientation,
colorStops: colorStops colorStops: colorStops
}; };