[Pkg-javascript-commits] [node-cssstyle] 23/39: added short hand font properties and bumped package version
Wolfgang Borgert
debacle at moszumanska.debian.org
Sat Sep 20 20:22:35 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 1481fc6ed146701535de10bfcf0cf132240609c3
Author: Chad Walker <chad at chad-cat-lore-eddie.com>
Date: Mon Nov 25 17:17:17 2013 -0600
added short hand font properties and bumped package version
---
lib/parsers.js | 3 +++
lib/properties/border.js | 2 +-
lib/properties/font.js | 36 ++++++++++++++++++++++++++++++++----
lib/properties/fontFamily.js | 18 ++++++++++++++++++
lib/properties/fontSize.js | 13 +++++++++++++
lib/properties/fontStyle.js | 6 ++++++
lib/properties/fontVariant.js | 6 ++++++
lib/properties/fontWeight.js | 6 ++++++
lib/properties/lineHeight.js | 9 +++++++++
package.json | 2 +-
tests/tests.js | 5 ++++-
11 files changed, 99 insertions(+), 7 deletions(-)
diff --git a/lib/parsers.js b/lib/parsers.js
index 6e31bc5..e123fb7 100644
--- a/lib/parsers.js
+++ b/lib/parsers.js
@@ -17,6 +17,7 @@ exports.TYPES = {
NULL_OR_EMPTY_STR: 10
};
+/*jslint regexp: true*/
// rough regular expressions
var integerRegEx = /^[\-+]?[0-9]+$/;
var numberRegEx = /^[\-+]?[0-9]*\.[0-9]+$/;
@@ -28,6 +29,7 @@ var colorRegEx1 = /^#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]([0-9a-fA-F][0-9a-fA-F][0-
var colorRegEx2 = /^rgb\(([^\)]*)\)$/;
var colorRegEx3 = /^rgba\(([^\)]*)\)$/;
var angleRegEx = /^([\-+]?[0-9]?\.?[0-9]+)(deg|grad|rad)$/;
+/*jslint regexp: false*/
// This will return one of the above types based on the passed in string
exports.valueType = function valueType(val) {
@@ -91,6 +93,7 @@ exports.valueType = function valueType(val) {
}
// could still be a color, one of the standard keyword colors
+ val = val.toLowerCase();
switch (val) {
case 'maroon':
case 'red':
diff --git a/lib/properties/border.js b/lib/properties/border.js
index 6844117..45728c2 100644
--- a/lib/properties/border.js
+++ b/lib/properties/border.js
@@ -10,7 +10,7 @@ var shorthand_for = {
'border-color': require('./borderColor')
};
-var isValid = module.exports.isValid = function isValid(v) {
+module.exports.isValid = function isValid(v) {
return shorthandParser(v, shorthand_for) !== undefined;
};
diff --git a/lib/properties/font.js b/lib/properties/font.js
index 0f70344..85e9411 100644
--- a/lib/properties/font.js
+++ b/lib/properties/font.js
@@ -1,12 +1,40 @@
'use strict';
+var TYPES = require('../parsers').TYPES;
+var valueType = require('../parsers').valueType;
+var shorthandParser = require('../parsers').shorthandParser;
+var shorthandSetter = require('../parsers').shorthandSetter;
+var shorthandGetter = require('../parsers').shorthandGetter;
+
+var shorthand_for = {
+ 'font-family': require('./fontFamily'),
+ 'font-size': require('./fontSize'),
+ 'font-style': require('./fontStyle'),
+ 'font-variant': require('./fontVariant'),
+ 'font-weight': require('./fontWeight'),
+ 'line-height': require('./lineHeight')
+};
+
+var static_fonts = ['caption', 'icon', 'menu', 'message-box', 'small-caption', 'status-bar', 'inherit'];
+
+module.exports.isValid = function isValid(v) {
+ return (shorthandParser(v, shorthand_for) !== undefined) ||
+ (valueType(v) === TYPES.KEYWORD && static_fonts.indexOf(v.toLowerCase()) !== -1);
+};
+
+var setter = shorthandSetter('background', shorthand_for);
+
module.exports.definition = {
set: function (v) {
- this.setProperty('font', v);
- },
- get: function () {
- return this.getPropertyValue('font');
+ var short = shorthandParser(v, shorthand_for);
+ if (short !== undefined) {
+ return setter.call(this, v);
+ }
+ if (valueType(v) === TYPES.KEYWORD && static_fonts.indexOf(v.toLowerCase()) !== -1) {
+ this.setProperty('font', v);
+ }
},
+ get: shorthandGetter('background', shorthand_for),
enumerable: true,
configurable: true
};
diff --git a/lib/properties/fontFamily.js b/lib/properties/fontFamily.js
index 0fc834c..5c13c1f 100644
--- a/lib/properties/fontFamily.js
+++ b/lib/properties/fontFamily.js
@@ -1,5 +1,23 @@
'use strict';
+var TYPES = require('../parsers').TYPES;
+var valueType = require('../parsers').valueType;
+
+var partsRegEx = /\s*,\s*/;
+module.exports.isValid = function isValid(v) {
+ var parts = v.split(partsRegEx);
+ var len = parts.len;
+ var i;
+ var type;
+ for (i = 0; i < len; i++) {
+ type = valueType(parts[i]);
+ if (type === TYPES.STRING || type === TYPES.KEYWORD) {
+ return true;
+ }
+ }
+ return false;
+};
+
module.exports.definition = {
set: function (v) {
this.setProperty('font-family', v);
diff --git a/lib/properties/fontSize.js b/lib/properties/fontSize.js
index 9896e50..79962a5 100644
--- a/lib/properties/fontSize.js
+++ b/lib/properties/fontSize.js
@@ -1,5 +1,18 @@
'use strict';
+var TYPES = require('../parsers').TYPES;
+var valueType = require('../parsers').valueType;
+
+var absoluteSizes = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'];
+var relativeSizes = ['larger', 'smaller'];
+
+module.exports.isValid = function (v) {
+ var type = valueType(v.toLowerCase());
+ return type === TYPES.LENGTH || type === TYPES.PERCENT ||
+ (type === TYPES.KEYWORD && absoluteSizes.indexOf(v.toLowerCase()) !== -1) ||
+ (type === TYPES.KEYWORD && relativeSizes.indexOf(v.toLowerCase()) !== -1);
+};
+
module.exports.definition = {
set: function (v) {
this.setProperty('font-size', v);
diff --git a/lib/properties/fontStyle.js b/lib/properties/fontStyle.js
index 3600eb6..41e11f3 100644
--- a/lib/properties/fontStyle.js
+++ b/lib/properties/fontStyle.js
@@ -1,5 +1,11 @@
'use strict';
+var valid_styles = ['normal', 'italic', 'oblique', 'inherit'];
+
+module.exports.isValid = function (v) {
+ return valid_styles.indexOf(v.toLowerCase()) !== -1;
+};
+
module.exports.definition = {
set: function (v) {
this.setProperty('font-style', v);
diff --git a/lib/properties/fontVariant.js b/lib/properties/fontVariant.js
index d98570d..61bfb64 100644
--- a/lib/properties/fontVariant.js
+++ b/lib/properties/fontVariant.js
@@ -1,5 +1,11 @@
'use strict';
+var valid_variants = ['normal', 'small-caps', 'inherit'];
+
+module.exports.isValid = function isValid(v) {
+ return valid_variants.indexOf(v.toLowerCase()) !== -1;
+};
+
module.exports.definition = {
set: function (v) {
this.setProperty('font-variant', v);
diff --git a/lib/properties/fontWeight.js b/lib/properties/fontWeight.js
index 79802eb..44dd39a 100644
--- a/lib/properties/fontWeight.js
+++ b/lib/properties/fontWeight.js
@@ -1,5 +1,11 @@
'use strict';
+var valid_weights = ['normal', 'bold', 'bolder', 'lighter', '100', '200', '300', '400', '500', '600', '700', '800', '900', 'inherit'];
+
+module.exports.isValid = function isValid(v) {
+ return valid_weights.indexOf(v.toLowerCase()) !== -1;
+};
+
module.exports.definition = {
set: function (v) {
this.setProperty('font-weight', v);
diff --git a/lib/properties/lineHeight.js b/lib/properties/lineHeight.js
index e6ff893..3d941fe 100644
--- a/lib/properties/lineHeight.js
+++ b/lib/properties/lineHeight.js
@@ -1,5 +1,14 @@
'use strict';
+var TYPES = require('../parsers').TYPES;
+var valueType = require('../parsers').valueType;
+
+module.exports.isValid = function isValid(v) {
+ var type = valueType(v);
+ return (type === TYPES.KEYWORD && (v.toLowerCase() === 'normal') || (v.toLowerCase() === 'inherit')) ||
+ type === TYPES.NUMBER || type === TYPES.LENGTH || type === TYPES.PERCENT;
+};
+
module.exports.definition = {
set: function (v) {
this.setProperty('line-height', v);
diff --git a/package.json b/package.json
index 59fd034..7878fa5 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "cssstyle",
"description": "CSSStyleDeclaration Object Model implementation",
"keywords": ["CSS", "CSSStyleDeclaration", "StyleSheet"],
- "version": "0.2.5",
+ "version": "0.2.6",
"homepage": "https://github.com/chad3814/CSSStyleDeclaration",
"maintainers": [{
"name": "Chad Walker",
diff --git a/tests/tests.js b/tests/tests.js
index 9e4f0a0..3ee25e4 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -75,7 +75,7 @@ module.exports = {
},
'Test Shorthand Properties': function (test) {
var style = new cssstyle.CSSStyleDeclaration();
- test.expect(9);
+ test.expect(11);
style.background = 'blue url(http://www.example.com/some_img.jpg)';
test.ok('blue' === style.backgroundColor, 'backgroundColor is not blue');
test.ok('url(http://www.example.com/some_img.jpg)' === style.backgroundImage, 'backgroundImage is wrong');
@@ -87,6 +87,9 @@ module.exports = {
test.ok('0px', style.borderTopWidth, 'borderTopWidth is not 0px');
test.ok('solid', style.borderLeftStyle, 'borderLeftStyle is not solid');
test.ok('black', style.borderBottomColor, 'borderBottomColor is not black');
+ style.font = '12em monospace';
+ test.ok('12em', style.fontSize, 'fontSize is not 12em');
+ test.ok('monospace', style.fontFamily, 'fontFamily is not monospace');
test.done();
},
'Test width and height Properties and null and empty strings': function (test) {
--
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