svg2-tools: Functionality required for SVG Integration table generation.

details:   https://svgwg.org/hg/svg2-tools/rev/acecf885de3c
branches:  
changeset: 79:acecf885de3c
user:      Cameron McCormack <cam@mcc.id.au>
date:      Tue Apr 09 09:36:03 2013 +1000
description:
Functionality required for SVG Integration table generation.

diffstat:

 publish/config.js      |  42 ++++++++++++++++++++++++++++++++++++++++++
 publish/definitions.js |   3 +++
 publish/processing.js  |  24 ++++++++++++++----------
 publish/utils.js       |  22 ++++++++++++++++++----
 4 files changed, 77 insertions(+), 14 deletions(-)

diffs (241 lines):

diff --git a/publish/config.js b/publish/config.js
--- a/publish/config.js
+++ b/publish/config.js
@@ -268,13 +268,55 @@ Config.prototype = {
 
   getSectionHierarchy: function(page) {
     if (this.pages[page].sectionHierarchy === void 0) {
       gatherSections(this, page);
     }
 
     return this.pages[page].sectionHierarchy;
   },
+
+  lookupElementBySpec: function(specid, elementName) {
+    var element = this.definitionsBySpec[specid].elements[elementName];
+    if (!element) {
+      for (var id in this.definitionMainSpecs) {
+        if (this.definitionMainSpecs[id] == specid) {
+          element = this.definitionsBySpec[id].elements[elementName];
+          if (element) {
+            break;
+          }
+        }
+      }
+    }
+    return element;
+  },
+
+  lookupElementAttributeBySpec: function(specid, elementName, attributeName) {
+    var element = this.definitionsBySpec[specid].elements[elementName];
+    if (!element || !element.attributes[attributeName]) {
+      for (var id in this.definitionMainSpecs) {
+        if (this.definitionMainSpecs[id] == specid) {
+          element = this.definitionsBySpec[id].elements[elementName];
+          if (element && element.attributes[attributeName]) {
+            break;
+          }
+        }
+      }
+    }
+    return element && element.attributes[attributeName];
+  },
+
+  lookupElementAttributeCategoryBySpec: function(specid, elementName, attributeCategoryName) {
+    var element = this.definitionsBySpec[specid].elements[elementName];
+    if (element) {
+      for (var i = 0; i < element.attributeCategories.length; i++) {
+        var catName = element.attributeCategories[i];
+        if (catName == attributeCategoryName) {
+          return this.definitionsBySpec[specid].attributeCategories[catName];
+        }
+      }
+    }
+  },
 };
 
 exports.load = function(filename) {
   return new Config(filename);
 };
diff --git a/publish/definitions.js b/publish/definitions.js
--- a/publish/definitions.js
+++ b/publish/definitions.js
@@ -319,16 +319,17 @@ function loadInto(filename, base, specid
       specid: specid
     });
 
     forEachChild(e, 'attribute', function(c) {
       element.specificAttributes.push(new Attribute({
         name: c.getAttribute('name'),
         href: utils.resolveURL(base, c.getAttribute('href')),
         animatable: c.getAttribute('animatable') == 'yes',
+        specific: true,
         specid: specid
       }));
     });
 
     forEachChild(e, 'contentmodel', function(c) {
       element.contentModelDescription = utils.cloneChildren(c);
     });
 
@@ -346,16 +347,17 @@ function loadInto(filename, base, specid
     defs.elementCategories[category.name] = category;
   });
 
   forEachChild(doc.documentElement, 'attribute', function(a) {
     var attribute = new Attribute({
       name: a.getAttribute('name'),
       href: utils.resolveURL(base, a.getAttribute('href')),
       animatable: a.getAttribute('animatable') == 'yes',
+      common: true,
       specid: specid
     });
     if (a.hasAttribute('elements')) {
       attribute.elements = utils.set(utils.splitList(a.getAttribute('elements')));
       defs.commonAttributesForElements.push(attribute);
     } else {
       defs.commonAttributes[attribute.name] = attribute;
     }
@@ -371,16 +373,17 @@ function loadInto(filename, base, specid
       specid: specid
     });
 
     forEachChild(ac, 'attribute', function(a) {
       category.attributes.push(new Attribute({
         name: a.getAttribute('name'),
         href: utils.resolveURL(base, a.getAttribute('href')),
         animatable: a.getAttribute('animatable') == 'yes',
+        category: category,
         specid: specid
       }));
     });
 
     defs.attributeCategories[category.name] = category;
   });
 
   forEachChild(doc.documentElement, 'property', function(p) {
diff --git a/publish/processing.js b/publish/processing.js
--- a/publish/processing.js
+++ b/publish/processing.js
@@ -800,56 +800,60 @@ exports.processLinks = function(conf, pa
 
     while (n.localName != 'table') {
       n = n.parentNode;
     }
 
     return n.getAttribute("class") == 'proptable';
   }
 
-  utils.forEachNode(doc, function(n) {
+  utils.forEachNode(doc, function(n, speclinks) {
     if (n.nodeType != n.ELEMENT_NODE ||
         n.localName != 'a' ||
         n.hasAttribute('href') ||
         !n.firstChild) {
       return;
     }
 
     var text = n.textContent;
 
+    var definitions = speclinks ? conf.definitionsBySpec[speclinks] : conf.definitions;
+
     if (/^'(\S+)\s+element'$/.test(text)) {
-      utils.replace(n, conf.definitions.formatElementLink(RegExp.$1, n));
+      utils.replace(n, definitions.formatElementLink(RegExp.$1, n));
     } else if (/^'(\S+)\s+attribute'$/.test(text)) {
-      utils.replace(n, conf.definitions.formatAttributeLink(RegExp.$1, n));
+      utils.replace(n, definitions.formatAttributeLink(RegExp.$1, n));
     } else if (/^'(\S+)\s+property'$/.test(text)) {
-      utils.replace(n, conf.definitions.formatPropertyLink(RegExp.$1, n, shouldOmitQuotes(n)));
+      utils.replace(n, definitions.formatPropertyLink(RegExp.$1, n, shouldOmitQuotes(n)));
     } else if (/^'(\S+)\s+presentationattribute'$/.test(text)) {
-      utils.replace(n, conf.definitions.formatPresentationAttributeLink(RegExp.$1, n));
+      utils.replace(n, definitions.formatPresentationAttributeLink(RegExp.$1, n));
     } else if (/^'([^\/]+)\/([^\/]+)'$/.test(text)) {
-      utils.replace(n, conf.definitions.formatElementAttributeLink(RegExp.$1, RegExp.$2, n));
+      utils.replace(n, definitions.formatElementAttributeLink(RegExp.$1, RegExp.$2, n));
     } else if (/^'(\S+)'$/.test(text)) {
-      utils.replace(n, conf.definitions.formatNameLink(RegExp.$1, n, shouldOmitQuotes(n)));
+      utils.replace(n, definitions.formatNameLink(RegExp.$1, n, shouldOmitQuotes(n)));
     } else if (/^([^:]+)::([^:]+)$/.test(text)) {
       var interfaceName = RegExp.$1;
       var memberName = RegExp.$2;
-      if (/^(.*)#/.test(conf.definitions.interfaces[interfaceName].href)) {
+      if (/^(.*)#/.test(definitions.interfaces[interfaceName].href)) {
         var beforeHash = RegExp.$1;
         utils.replace(n, utils.parse('<a href="{{base}}#__svg__{{interface}}__{{member}}">{{prefix}}{{member}}</a>',
                                      { base: beforeHash,
                                        interface: interfaceName,
                                        prefix: n.getAttributeNS(namespaces.edit, 'format') == "expanded" ? interfaceName + '::' : '',
                                        member: memberName }));
       } else {
         utils.warn('unknown interface name "' + interfaceName + '"', n);
       }
     } else if (/^<(.*)>$/.test(text)) {
-      utils.replace(n, conf.definitions.formatSymbolLink(RegExp.$1, n));
+      utils.replace(n, definitions.formatSymbolLink(RegExp.$1, n));
     } else {
-      utils.replace(n, conf.definitions.formatTermLink(text, n));
+      utils.replace(n, definitions.formatTermLink(text, n));
     }
+  }, function(n) {
+    return n.nodeType == 1 && n.getAttributeNS(namespaces.edit, 'speclinks');
   });
 };
 
 
 // -- Use rounded quotes around element, attribute and property names. --------
 
 exports.formatQuotes = function(conf, page, doc) {
   utils.forEachNode(doc, function(n) {
diff --git a/publish/utils.js b/publish/utils.js
--- a/publish/utils.js
+++ b/publish/utils.js
@@ -255,29 +255,43 @@ exports.firstIndexOfAny = function(withi
   return false;
 };
 
 exports.compare = function(s1, s2) {
   if (s1 == s2) return 0;
   return s1 < s2 ? -1 : 1;
 };
 
-exports.forEachNode = function(n, fn) {
-  var a = fn(n);
+exports.forEachNode = function(n, fn, stackfn, stackval) {
+  stackval = stackfn && stackfn(n) || stackval;
+  var a = fn(n, stackval);
   if (Array.isArray(a)) {
-    a.forEach(function(n) { exports.forEachNode(n, fn) });
+    a.forEach(function(n) { exports.forEachNode(n, fn, stackfn, stackval) });
   } else {
     n = n.firstChild;
     while (n) {
       var next = n.nextSibling;
-      exports.forEachNode(n, fn);
+      exports.forEachNode(n, fn, stackfn, stackval);
       n = next;
     }
   }
 };
 
 exports.warn = function(message, node) {
   if (node) {
     console.warn([node.ownerDocument.documentURI, node.lineNumber, node.columnNumber, ' warning: ' + message].join(':'));
   } else {
     console.warn('warning: ' + message);
   }
 };
+
+exports.allEqual = function(a) {
+  if (a.length == 0) {
+    return true;
+  }
+  var x = a[0];
+  for (var i = 1; i < a.length; i++) {
+    if (a[i] != x) {
+      return false;
+    }
+  }
+  return true;
+};

Received on Monday, 8 April 2013 23:36:48 UTC