[Pkg-javascript-commits] [node-cssstyle] 26/39: parse values for clip and clear, removed clipPath and clipRule
Wolfgang Borgert
debacle at moszumanska.debian.org
Sat Sep 20 20:22:36 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to branch master
in repository node-cssstyle.
commit 9ff7adf940718a7ac796847657caf6c4a94f84ea
Author: Chad Walker <chad at chad-cat-lore-eddie.com>
Date: Sun Dec 1 21:12:17 2013 -0600
parse values for clip and clear, removed clipPath and clipRule
---
lib/parsers.js | 18 ++++++++++++++++++
lib/properties/clear.js | 6 +++++-
lib/properties/clip.js | 39 ++++++++++++++++++++++++++++++++++++++-
lib/properties/clipPath.js | 12 ------------
lib/properties/clipRule.js | 12 ------------
tests/tests.js | 22 ++++++++++++++++++++++
6 files changed, 83 insertions(+), 26 deletions(-)
diff --git a/lib/parsers.js b/lib/parsers.js
index 32d8dcb..4c60f93 100644
--- a/lib/parsers.js
+++ b/lib/parsers.js
@@ -377,6 +377,24 @@ exports.parseAngle = function parseAngle(val) {
return flt + 'deg';
};
+exports.parseKeyword = function parseKeyword(val, valid_keywords) {
+ var type = exports.valueType(val);
+ if (type === exports.TYPES.NULL_OR_EMPTY_STR) {
+ return val;
+ }
+ if (type !== exports.TYPES.KEYWORD) {
+ return undefined;
+ }
+ val = val.toString().toLowerCase();
+ var i;
+ for (i = 0; i < valid_keywords.length; i++) {
+ if (valid_keywords[i].toLowerCase() === val) {
+ return valid_keywords[i];
+ }
+ }
+ return undefined;
+};
+
// utility to translate from border-width to borderWidth
var dashedToCamelCase = function (dashed) {
var i;
diff --git a/lib/properties/clear.js b/lib/properties/clear.js
index c9663ba..00d954a 100644
--- a/lib/properties/clear.js
+++ b/lib/properties/clear.js
@@ -1,8 +1,12 @@
'use strict';
+var parseKeyword = require('../parsers').parseKeyword;
+
+var clear_keywords = [ 'none', 'left', 'right', 'both', 'inherit' ];
+
module.exports.definition = {
set: function (v) {
- this.setProperty('clear', v);
+ this.setProperty('clear', parseKeyword(v, clear_keywords));
},
get: function () {
return this.getPropertyValue('clear');
diff --git a/lib/properties/clip.js b/lib/properties/clip.js
index eeb91e9..e1497e0 100644
--- a/lib/properties/clip.js
+++ b/lib/properties/clip.js
@@ -1,8 +1,45 @@
'use strict';
+var parseMeasurement = require('../parsers').parseMeasurement;
+
+/*jslint regexp: true*/
+var shape_regex = /^rect\((.*)\)$/i;
+/*jslint regexp: false*/
+
+var parse = function (val) {
+ if (val === '' || val === null) {
+ return val;
+ }
+ if (typeof val !== 'string') {
+ return undefined;
+ }
+ val = val.toLowerCase();
+ if (val === 'auto' || val === 'inherit') {
+ return val;
+ }
+ var matches = val.match(shape_regex);
+ if (!matches) {
+ return undefined;
+ }
+ var parts = matches[1].split(/\s*,\s*/);
+ if (parts.length !== 4) {
+ return undefined;
+ }
+ var valid = parts.every(function (part, index) {
+ var measurement = parseMeasurement(part);
+ parts[index] = measurement;
+ return measurement !== undefined;
+ });
+ if (!valid) {
+ return undefined;
+ }
+ parts = parts.join(', ');
+ return val.replace(matches[1], parts);
+};
+
module.exports.definition = {
set: function (v) {
- this.setProperty('clip', v);
+ this.setProperty('clip', parse(v));
},
get: function () {
return this.getPropertyValue('clip');
diff --git a/lib/properties/clipPath.js b/lib/properties/clipPath.js
deleted file mode 100644
index 1df43b7..0000000
--- a/lib/properties/clipPath.js
+++ /dev/null
@@ -1,12 +0,0 @@
-'use strict';
-
-module.exports.definition = {
- set: function (v) {
- this.setProperty('clip-path', v);
- },
- get: function () {
- return this.getPropertyValue('clip-path');
- },
- enumerable: true,
- configurable: true
-};
diff --git a/lib/properties/clipRule.js b/lib/properties/clipRule.js
deleted file mode 100644
index 1b39ed4..0000000
--- a/lib/properties/clipRule.js
+++ /dev/null
@@ -1,12 +0,0 @@
-'use strict';
-
-module.exports.definition = {
- set: function (v) {
- this.setProperty('clip-rule', v);
- },
- get: function () {
- return this.getPropertyValue('clip-rule');
- },
- enumerable: true,
- configurable: true
-};
diff --git a/tests/tests.js b/tests/tests.js
index ca2e34c..03b6173 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -136,5 +136,27 @@ module.exports = {
test.ok(4 === style.length, 'length is not 4');
test.ok('top: 0px; left: 0%; right: 5em; bottom: 12pt;' === style.cssText, 'text is not "top: 0px; left: 0%; right: 5em; bottom: 12pt;"');
test.done();
+ },
+ 'Test Clear and Clip Properties': function (test) {
+ var style = new cssstyle.CSSStyleDeclaration();
+ test.expect(10);
+ style.clear = 'none';
+ test.ok('none' === style.clear, 'clear is not none');
+ style.clear = 'lfet'; // intentionally wrong
+ test.ok('none' === style.clear, 'clear is not still none');
+ style.clear = 'left';
+ test.ok('left' === style.clear, 'clear is not left');
+ style.clear = 'right';
+ test.ok('right' === style.clear, 'clear is not right');
+ style.clear = 'both';
+ test.ok('both' === style.clear, 'clear is not both');
+ style.clip = 'elipse(5px, 10px)';
+ test.ok('' === style.clip, 'clip should not be set');
+ test.ok(1 === style.length, 'length is not 1');
+ style.clip = 'rect(0, 3Em, 2pt, 50%)';
+ test.ok('rect(0px, 3em, 2pt, 50%)' === style.clip, 'clip is not "rect(0px, 3em, 2pt, 50%)", "' + style.clip + '"');
+ test.ok(2 === style.length, 'length is not 2');
+ test.ok('clear: both; clip: rect(0px, 3em, 2pt, 50%);' === style.cssText, 'cssText is not "clear: both; clip: rect(0px, 3em, 2pt, 50%);"');
+ test.done();
}
};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-cssstyle.git
More information about the Pkg-javascript-commits
mailing list