[Pkg-javascript-commits] [node-cssstyle] 32/39: Define style object getters/setters for hyphenated CSS properties too #10
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 af8545b6d33f0bb862e9314296c0a7598380df2e
Author: Chad Walker <chad at chad-cat-lore-eddie.com>
Date: Mon Mar 3 11:29:17 2014 -0600
Define style object getters/setters for hyphenated CSS properties too #10
added dashed properties as well as camelCase ones.
---
lib/CSSStyleDeclaration.js | 13 +++++++++++--
lib/parsers.js | 15 +++++++++++++++
package.json | 2 +-
tests/tests.js | 14 ++++++++++++++
4 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/lib/CSSStyleDeclaration.js b/lib/CSSStyleDeclaration.js
index aac7586..e83b6b7 100644
--- a/lib/CSSStyleDeclaration.js
+++ b/lib/CSSStyleDeclaration.js
@@ -3,11 +3,12 @@
* https://github.com/NV/CSSOM
********************************************************************/
"use strict";
-/*jslint es5: true*/
var CSSOM = require('cssom');
var fs = require('fs');
var path = require('path');
+var camelToDashed = require('./parsers').camelToDashed;
+
/**
* @constructor
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration
@@ -101,6 +102,7 @@ CSSStyleDeclaration.prototype = {
getPropertyCSSValue: function () {
//FIXME
+ return;
},
/**
@@ -110,10 +112,12 @@ CSSStyleDeclaration.prototype = {
*/
getPropertyShorthand: function () {
//FIXME
+ return;
},
isPropertyImplicit: function () {
//FIXME
+ return;
},
/**
@@ -190,9 +194,14 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
*/
var property_files = fs.readdirSync(__dirname + '/properties');
property_files.forEach(function (property) {
+ var dashed;
+ var definition;
if (property.substr(-3) === '.js') {
property = path.basename(property, '.js');
- Object.defineProperty(CSSStyleDeclaration.prototype, property, require('./properties/' + property).definition);
+ dashed = camelToDashed(property);
+ definition = require('./properties/' + property).definition;
+ Object.defineProperty(CSSStyleDeclaration.prototype, property, definition);
+ Object.defineProperty(CSSStyleDeclaration.prototype, dashed, definition);
}
});
diff --git a/lib/parsers.js b/lib/parsers.js
index a867b05..ca9dc47 100644
--- a/lib/parsers.js
+++ b/lib/parsers.js
@@ -558,3 +558,18 @@ exports.implicitSetter = function (property_before, property_after, isValid, par
}
};
};
+
+var camel_to_dashed = /[A-Z]/g;
+/*jslint regexp: true*/
+var first_segment = /^\([^\-]\)-/;
+/*jslint regexp: false*/
+var vendor_prefixes = ['o', 'moz', 'ms', 'webkit'];
+exports.camelToDashed = function (camel_case) {
+ var match;
+ var dashed = camel_case.replace(camel_to_dashed, '-$1').toLowerCase();
+ match = dashed.match(first_segment);
+ if (match && vendor_prefixes.indexOf(match[1]) !== -1) {
+ dashed = '-' + dashed;
+ }
+ return dashed;
+};
diff --git a/package.json b/package.json
index 1ea4bae..d6114e2 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.9",
+ "version": "0.2.10",
"homepage": "https://github.com/chad3814/CSSStyleDeclaration",
"maintainers": [{
"name": "Chad Walker",
diff --git a/tests/tests.js b/tests/tests.js
index b482176..4114f09 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -2,11 +2,16 @@
var util = require('util');
var cssstyle = require('../lib/CSSStyleDeclaration');
+var camelToDashed = require('../lib/parsers').camelToDashed;
+
/**
* These are the required properties
* see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties
**/
var properties = [ 'azimuth', 'background', 'backgroundAttachment', 'backgroundColor', 'backgroundImage', 'backgroundPosition', 'backgroundRepeat', 'border', 'borderCollapse', 'borderColor', 'borderSpacing', 'borderStyle', 'borderTop', 'borderRight', 'borderBottom', 'borderLeft', 'borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor', 'borderTopStyle', 'borderRightStyle', 'borderBottomStyle', 'borderLeftStyle', 'borderTopWidth', 'borderRightWidth', 'borderBottomWidt [...]
+var dashed_properties = properties.map(function (property) {
+ return camelToDashed(property);
+});
module.exports = {
'Verify Has Properties': function (test) {
@@ -18,6 +23,15 @@ module.exports = {
});
test.done();
},
+ 'Verify Has Dashed Properties': function (test) {
+ var style = new cssstyle.CSSStyleDeclaration();
+ test.expect(dashed_properties.length * 2);
+ dashed_properties.forEach(function (property) {
+ test.ok(style.__lookupGetter__(property), 'missing ' + property + ' property');
+ test.ok(style.__lookupSetter__(property), 'missing ' + property + ' property');
+ });
+ test.done();
+ },
'Verify Has Functions': function (test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(6);
--
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