Author: evan
Date: Fri Nov 21 15:36:00 2008
New Revision: 719750

URL: http://svn.apache.org/viewvc?rev=719750&view=rev
Log:
SHINDIG-687:
Small fixes to OS Templates

A number of small-ish fixes:

- ${Context.Index} and ${Context.Count} now work.
- Errors are caught and logged if they happen during bootstrapping.
- Template libraries can define named templates in addition to custom tag (via 
the @name attribute) 

Modified:
    incubator/shindig/trunk/features/opensocial-templates/compiler.js
    incubator/shindig/trunk/features/opensocial-templates/container.js
    incubator/shindig/trunk/features/opensocial-templates/loader.js

Modified: incubator/shindig/trunk/features/opensocial-templates/compiler.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/compiler.js?rev=719750&r1=719749&r2=719750&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/compiler.js (original)
+++ incubator/shindig/trunk/features/opensocial-templates/compiler.js Fri Nov 
21 15:36:00 2008
@@ -182,6 +182,12 @@
  * @return {string} Expression with replacements
  */
 os.replaceTopLevelVars_ = function(text) {
+       
+  // Currently, values specced to be inside the "Context" variable are placed
+  // by JSTemplate into the top-level of the data context.
+  // To make references like "Context.Index" work, remove the "Context." 
prefix. 
+  text = text.replace(/Context[.]/g, "");
+       
   // This line needed because there wasn't an obvious way to match
   // [^.$a-zA-Z0-9] or the start of the line
   text = ' ' + text;
@@ -719,9 +725,12 @@
  * Object, Element or array of Elements.
  */
 os.getValueFromNode_ = function(node, name) {
-  var ret = node[name] || node.getAttribute(name);
+  var ret = node[name];
+  if (typeof(ret) == "undefined" || ret == null) {
+    ret = node.getAttribute(name);
+  }
   
-  if (!ret) {
+  if (typeof(ret) == "undefined" || ret == null) {
     if (name) {
       name = name.toLowerCase();
     }

Modified: incubator/shindig/trunk/features/opensocial-templates/container.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/container.js?rev=719750&r1=719749&r2=719750&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/container.js 
(original)
+++ incubator/shindig/trunk/features/opensocial-templates/container.js Fri Nov 
21 15:36:00 2008
@@ -97,7 +97,11 @@
     return;
   }
   while (os.Container.domLoadCallbacks_.length) {
-    os.Container.domLoadCallbacks_.pop()();
+  try {
+      os.Container.domLoadCallbacks_.pop()();
+    } catch (e) {
+      os.log(e);
+    }
   }
   os.Container.domLoaded_ = true;  
 };

Modified: incubator/shindig/trunk/features/opensocial-templates/loader.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/loader.js?rev=719750&r1=719749&r2=719750&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/loader.js (original)
+++ incubator/shindig/trunk/features/opensocial-templates/loader.js Fri Nov 21 
15:36:00 2008
@@ -186,12 +186,13 @@
  */
 os.Loader.processTemplateDefNode = function(node) {
   var tag = node.getAttribute("tag");
+  var name = node.getAttribute("name");
   for (var child = node.firstChild; child; child = child.nextSibling) {
     if (child.nodeType == DOM_ELEMENT_NODE) {
       // TODO(levik): This won't work once compiler does name mangling.
       var handler = os.Loader.getProcessorFunction_(child.tagName);
       if (handler) {
-        handler(child, tag);
+        handler(child, tag, name);
       }
     }
   }
@@ -200,8 +201,9 @@
 /**
  * Processes the <Template> node
  */
-os.Loader.processTemplateNode = function(node, opt_tag) {
+os.Loader.processTemplateNode = function(node, opt_tag, opt_name) {
   var tag = opt_tag || node.getAttribute("tag");
+  var name = opt_name || node.getAttribute("name");
   if (tag) {
     var tagParts = tag.split(":");
     if (tagParts.length != 2) {
@@ -214,7 +216,11 @@
     }
     var template = os.compileXMLNode(node);
     nsObj[tagParts[1]] = os.createTemplateCustomTag(template);
-  } 
+  } else if (name) {
+    var template = os.compileXMLNode(node);
+    template.id = name;
+    os.registerTemplate(template);
+  }
 };
 
 /**


Reply via email to