Match repeating-linear-gradient
This commit is contained in:
parent
fdcbd0beb9
commit
d6c91b4757
2 changed files with 78 additions and 43 deletions
|
@ -7,6 +7,7 @@ module.exports = (function() {
|
|||
var types = {
|
||||
gradients: [
|
||||
'linear-gradient',
|
||||
'repeating-linear-gradient',
|
||||
'radial-gradient',
|
||||
'repeating-radial-gradient'
|
||||
],
|
||||
|
@ -24,7 +25,9 @@ module.exports = (function() {
|
|||
|
||||
var tokens = {
|
||||
linearGradient: /^linear\-gradient/i,
|
||||
repeatingLinearGradient: /^repeating\-linear\-gradient/i,
|
||||
radialGradient: /^radial\-gradient/i,
|
||||
repeatingRadialGradient: /^repeating\-radial\-gradient/i,
|
||||
sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|left|right|top|bottom)/i,
|
||||
pixelValue: /^([0-9]+)px/,
|
||||
percentageValue: /^([0-9]+)\%/,
|
||||
|
@ -66,7 +69,11 @@ module.exports = (function() {
|
|||
return matchGradient(
|
||||
'linear-gradient',
|
||||
tokens.linearGradient,
|
||||
matchOrientation);
|
||||
matchLinearOrientation) ||
|
||||
matchGradient(
|
||||
'repeating-linear-gradient',
|
||||
tokens.repeatingLinearGradient,
|
||||
matchLinearOrientation);
|
||||
}
|
||||
|
||||
function matchGradient(gradientType, pattern, orientationMatcher) {
|
||||
|
@ -105,7 +112,7 @@ module.exports = (function() {
|
|||
}
|
||||
}
|
||||
|
||||
function matchOrientation() {
|
||||
function matchLinearOrientation() {
|
||||
return matchSideOrCorner() ||
|
||||
matchAngle();
|
||||
}
|
||||
|
|
|
@ -132,7 +132,12 @@ describe('gradient-parser.js', function () {
|
|||
});
|
||||
});
|
||||
|
||||
['px', 'em', '%'].forEach(function(metric) {
|
||||
describe('parse all metric values', function() {
|
||||
[
|
||||
'px',
|
||||
'em',
|
||||
'%'
|
||||
].forEach(function(metric) {
|
||||
describe('parse color stop for metric '+ metric, function() {
|
||||
beforeEach(function() {
|
||||
ast = gradients.parse('linear-gradient(blue 10' + metric + ', transparent)');
|
||||
|
@ -151,7 +156,9 @@ describe('gradient-parser.js', function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('parse all linear directional', function() {
|
||||
[
|
||||
{type: 'angular', unparsedValue: '145deg', value: '145'},
|
||||
{type: 'directional', unparsedValue: 'to left top', value: 'left top'}
|
||||
|
@ -168,7 +175,9 @@ describe('gradient-parser.js', function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('parse all color types', function() {
|
||||
[
|
||||
{type: 'literal', unparsedValue: 'red', value: 'red'},
|
||||
{type: 'hex', unparsedValue: '#c2c2c2', value: 'c2c2c2'},
|
||||
|
@ -187,4 +196,23 @@ describe('gradient-parser.js', function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('parse linear gradients', function() {
|
||||
[
|
||||
'linear-gradient',
|
||||
'repeating-linear-gradient'
|
||||
].forEach(function(gradient) {
|
||||
describe('parse ' + gradient + ' gradient', function() {
|
||||
beforeEach(function() {
|
||||
ast = gradients.parse(gradient + '(red, blue)');
|
||||
subject = ast[0];
|
||||
});
|
||||
|
||||
it('should parse the gradient', function() {
|
||||
expect(subject.type).to.equal(gradient);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue