From cbaefaf1bb65adab7a0d819a1dfb959f513000f8 Mon Sep 17 00:00:00 2001 From: jessewang-arvatosystems Date: Wed, 6 Sep 2017 21:22:18 -0400 Subject: [PATCH] Created text-shadow-single. Adapted same code formatting as box-shadow and box-shadow-single --- lib/css/valuebucket.js | 1 + lib/css/values/text-shadow-single.js | 66 ++++++++++++++++++++ lib/css/values/text-shadow.js | 33 ++-------- test/css/values/text-shadow-single-test.js | 53 ++++++++++++++++ test/css/values/text-shadow-test.js | 72 ++++++++-------------- 5 files changed, 148 insertions(+), 77 deletions(-) create mode 100644 lib/css/values/text-shadow-single.js create mode 100644 test/css/values/text-shadow-single-test.js diff --git a/lib/css/valuebucket.js b/lib/css/valuebucket.js index a091be2..e47f44f 100644 --- a/lib/css/valuebucket.js +++ b/lib/css/valuebucket.js @@ -238,6 +238,7 @@ exports['text-decoration-style'] = require('./values/text-decoration-style'); exports['text-indent'] = require('./values/text-indent'); exports['text-overflow'] = require('./values/text-overflow'); exports['text-shadow'] = require('./values/text-shadow'); +exports['text-shadow-single'] = require('./values/text-shadow-single'); exports['text-size-adjust'] = require('./values/text-size-adjust'); exports['text-transform-case'] = require('./values/text-transform-case'); exports['text-transform'] = require('./values/text-transform'); diff --git a/lib/css/values/text-shadow-single.js b/lib/css/values/text-shadow-single.js new file mode 100644 index 0000000..ee849b4 --- /dev/null +++ b/lib/css/values/text-shadow-single.js @@ -0,0 +1,66 @@ +/* + * + * CSS3: none | [ {2,3} && ? ]# + * + */ + +"use strict"; + +var base = require('./base'); +var util = require('../../util'); +var validate = require('./validate'); + +var TextShadowSingle = base.baseConstructor(); + +util.extend(TextShadowSingle.prototype, base.base, { + name: "text-shadow-single" +}); + + +exports.parse = function (unparsedReal, bucket, container) { + var tss = new TextShadowSingle(bucket, container, unparsedReal); + tss.debug('parse', unparsedReal); + var noneFound = false; + validate.call(tss, 'minimumCss', tss.firstToken(), 3); + + if (tss.handleInherit(function () {})) { + return tss; + } + + if (tss.unparsed.isContent('none')) { + noneFound = true; + tss.add(tss.unparsed.advance()); + return tss; + } + + var c = bucket['color'].parse(tss.unparsed, bucket, tss); + + if (c) { + tss.add(c); + tss.unparsed = c.unparsed; + } + + var lengths = tss.repeatParser([ bucket['length'] ], 3); + + if (lengths < 2) { + tss.debug('parse fail'); + return null; + } + + if (! c) { + c = bucket['color'].parse(tss.unparsed, bucket, tss); + + if (c) { + tss.add(c); + tss.unparsed = c.unparsed; + } + } + + if (! noneFound && tss.unparsed.isContent('none')) { + tss.add(tss.unparsed.advance()); + } + + tss.warnIfInherit(); + tss.debug('parse success', tss.unparsed); + return tss; +}; diff --git a/lib/css/values/text-shadow.js b/lib/css/values/text-shadow.js index 4654aa6..8fbd0f7 100644 --- a/lib/css/values/text-shadow.js +++ b/lib/css/values/text-shadow.js @@ -1,7 +1,6 @@ /* * - * CSS3: none | [ {2,3} && ? ]# - * + * CSS3: inherit | none | # */ "use strict"; @@ -16,11 +15,10 @@ util.extend(TextShadow.prototype, base.base, { name: "text-shadow" }); - exports.parse = function (unparsedReal, bucket, container) { var ts = new TextShadow(bucket, container, unparsedReal); + var unparsed = unparsedReal.clone(); ts.debug('parse', unparsedReal); - var noneFound = false; validate.call(ts, 'minimumCss', ts.firstToken(), 3); if (ts.handleInherit(function () {})) { @@ -28,39 +26,16 @@ exports.parse = function (unparsedReal, bucket, container) { } if (ts.unparsed.isContent('none')) { - noneFound = true; ts.add(ts.unparsed.advance()); return ts; } - var c = bucket['color'].parse(ts.unparsed, bucket, ts); - - if (c) { - ts.add(c); - ts.unparsed = c.unparsed; - } + ts.repeatWithCommas = true; - var lengths = ts.repeatParser([ bucket['length'] ], 3); - - if (lengths < 2) { - ts.debug('parse fail'); + if (! ts.repeatParser([ bucket['text-shadow-single'] ])) { return null; } - if (! c) { - c = bucket['color'].parse(ts.unparsed, bucket, ts); - - if (c) { - ts.add(c); - ts.unparsed = c.unparsed; - } - } - - if (! noneFound && ts.unparsed.isContent('none')) { - ts.add(ts.unparsed.advance()); - } - ts.warnIfInherit(); - ts.debug('parse success', ts.unparsed); return ts; }; diff --git a/test/css/values/text-shadow-single-test.js b/test/css/values/text-shadow-single-test.js new file mode 100644 index 0000000..ce86608 --- /dev/null +++ b/test/css/values/text-shadow-single-test.js @@ -0,0 +1,53 @@ +"use strict"; +var util = require('./util'); + +exports.batch = util.makeVows('text-shadow-single', { + 'none': { + 'tokens': ['IDENT'], + 'toString': 'none', + 'unparsed': [], + 'warnings': ['css-minimum:3'] + }, + '12px': { + 'tokens': ['UNIT'], + 'toString': null, + 'unparsed': ['UNIT'], + 'warnings': null + }, + '12px 12px watermelon': { + 'tokens': ['UNIT', 'S', 'UNIT', 'S', 'IDENT'], + 'toString': '12px 12px', + 'unparsed': ['IDENT'], + 'warnings': ['css-minimum:3'] + }, + '12px 12px blue 12px': { + 'tokens': ['UNIT', 'S', 'UNIT', 'S', 'IDENT', 'S', 'UNIT'], + 'toString': '12px 12px blue', + 'unparsed': ['UNIT'], + 'warnings': ['css-minimum:3'] + }, + 'blue 12px 1px 5px': { + 'tokens': ['IDENT', 'S', 'UNIT', 'S', 'UNIT', 'S', 'UNIT'], + 'toString': 'blue 12px 1px 5px', + 'unparsed': [], + 'warnings': ['css-minimum:3'] + }, + '12px 12px inherit': { + 'tokens': ['UNIT', 'S', 'UNIT', 'S', 'IDENT'], + 'toString': '12px 12px inherit', + 'unparsed': [], + 'warnings': ['css-minimum:3', 'inherit-not-allowed'] + }, + 'inherit': { + 'tokens': ['IDENT'], + 'toString': 'inherit', + 'unparsed': [], + 'warnings': ['css-minimum:3'] + }, + 'invalidValue': { + 'tokens': ['IDENT'], + 'toString': null, + 'unparsed': ['IDENT'], + 'warnings': null + } +}); diff --git a/test/css/values/text-shadow-test.js b/test/css/values/text-shadow-test.js index 0b1d95f..3f57559 100644 --- a/test/css/values/text-shadow-test.js +++ b/test/css/values/text-shadow-test.js @@ -2,52 +2,28 @@ var util = require('./util'); exports.batch = util.makeVows('text-shadow', { - 'none': { - 'tokens': ['IDENT'], - 'toString': 'none', - 'unparsed': [], - 'warnings': ['css-minimum:3'] - }, - '12px': { - 'tokens': ['UNIT'], - 'toString': null, - 'unparsed': ['UNIT'], - 'warnings': null - }, - '12px 12px watermelon': { - 'tokens': ['UNIT', 'S', 'UNIT', 'S', 'IDENT'], - 'toString': '12px 12px', - 'unparsed': ['IDENT'], - 'warnings': ['css-minimum:3'] - }, - '12px 12px blue 12px': { - 'tokens': ['UNIT', 'S', 'UNIT', 'S', 'IDENT', 'S', 'UNIT'], - 'toString': '12px 12px blue', - 'unparsed': ['UNIT'], - 'warnings': ['css-minimum:3'] - }, - 'blue 12px 1px 5px': { - 'tokens': ['IDENT', 'S', 'UNIT', 'S', 'UNIT', 'S', 'UNIT'], - 'toString': 'blue 12px 1px 5px', - 'unparsed': [], - 'warnings': ['css-minimum:3'] - }, - '12px 12px inherit': { - 'tokens': ['UNIT', 'S', 'UNIT', 'S', 'IDENT'], - 'toString': '12px 12px inherit', - 'unparsed': [], - 'warnings': ['css-minimum:3', 'inherit-not-allowed'] - }, - 'inherit': { - 'tokens': ['IDENT'], - 'toString': 'inherit', - 'unparsed': [], - 'warnings': ['css-minimum:3'] - }, - 'invalidValue': { - 'tokens': ['IDENT'], - 'toString': null, - 'unparsed': ['IDENT'], - 'warnings': null - } + 'blue 12px 1px 5px, blue 12px 1px 5px': { + 'tokens': ['IDENT', 'S', 'UNIT', 'S', 'UNIT', 'S', 'UNIT', 'OPERATOR', 'S', 'IDENT', 'S', 'UNIT', 'S', 'UNIT', 'S', 'UNIT'], + 'toString': 'blue 12px 1px 5px, blue 12px 1px 5px', + 'unparsed': [], + 'warnings': ['css-minimum:3'] + }, + 'none': { + 'tokens': ['IDENT'], + 'toString': 'none', + 'unparsed': [], + 'warnings': ['css-minimum:3'] + }, + 'inherit': { + 'tokens': ['IDENT'], + 'toString': 'inherit', + 'unparsed': [], + 'warnings': ['css-minimum:3'] + }, + 'invalidValue': { + 'tokens': ['IDENT'], + 'toString': null, + 'unparsed': ['IDENT'], + 'warnings': null + } });