Reviewers: shindig-dev,

Description:
OpenSocial Temlates:

NameSpace registration happens automatically if @tag="ns:Tag" is defined
for unknown namespace prefix (the URL can be supplied later)

OST now depends on opensocial-0.8 feature

Please review this at http://codereview.appspot.com/11910

Affected files:
  features/opensocial-templates
  features/opensocial-templates/container.js
  features/opensocial-templates/data.js
  features/opensocial-templates/feature.xml
  features/opensocial-templates/namespaces.js



Property changes on: features/opensocial-templates
___________________________________________________________________
Name: svn:ignore
   + jsunit


Index: features/opensocial-templates/data.js
===================================================================
--- features/opensocial-templates/data.js       (revision 734489)
+++ features/opensocial-templates/data.js       (working copy)
@@ -612,7 +612,7 @@
  * Pre-populate a Data Set based on application's URL parameters.
  */
 (os.data.populateParams_ = function() {
-  if (gadgets.util.hasFeature("views")) {
+  if (window["gadgets"] && gadgets.util.hasFeature("views")) {
os.data.DataContext.putDataSet("ViewParams", gadgets.views.getParams());
   }
 })();
\ No newline at end of file
Index: features/opensocial-templates/feature.xml
===================================================================
--- features/opensocial-templates/feature.xml   (revision 734489)
+++ features/opensocial-templates/feature.xml   (working copy)
@@ -31,6 +31,7 @@
 -->
 <feature>
   <name>opensocial-templates</name>
+  <dependency>opensocial-0.8</dependency>
   <gadget>
<script src="http://google-jstemplate.googlecode.com/svn/trunk/util.js";></script> <script src="http://google-jstemplate.googlecode.com/svn/trunk/jsevalcontext.js";></script>
Index: features/opensocial-templates/namespaces.js
===================================================================
--- features/opensocial-templates/namespaces.js (revision 734489)
+++ features/opensocial-templates/namespaces.js (working copy)
@@ -65,6 +65,9 @@
     tags = {};
     os.nsmap_[ns] = tags;
     os.nsurls_[ns] = url;
+  } else if (os.nsurls_[ns] == null ) {
+    // Lazily register an auto-created namespace.
+    os.nsurls_[ns] = url;
   } else if (os.nsurls_[ns] != url) {
throw("Namespace " + ns + " already defined with url " + os.nsurls_[ns]);
   }
@@ -78,9 +81,15 @@
   return os.nsmap_[prefix];
 };

-os.addNamespace = function(ns, url, nsObj) {
+os.addNamespace = function(ns, url, nsObj) {
   if (os.nsmap_[ns]) {
-    throw ("Namespace '" + ns + "' already exists!");
+    if (os.nsurls_[ns] == null) {
+      // Lazily register an auto-created namespace.
+      os.nsurls_[ns] = url;
+      return;
+    } else {
+      throw ("Namespace '" + ns + "' already exists!");
+    }
   }
   os.nsmap_[ns] = nsObj;
   os.nsurls_[ns] = url;
Index: features/opensocial-templates/container.js
===================================================================
--- features/opensocial-templates/container.js  (revision 734489)
+++ features/opensocial-templates/container.js  (working copy)
@@ -360,10 +360,10 @@
   if (template) {
     var tagParts = name.split(':');
     var nsObj = os.getNamespace(tagParts[0]);
-    if (nsObj) {
-      nsObj[tagParts[1]] = os.createTemplateCustomTag(template);
-    } else {
-      os.warn('Namespace ' + tagParts[0] + ' is not registered.');
+    if (!nsObj) {
+      // Auto Create a namespace for lazy registration.
+      nsObj = os.createNamespace(tagParts[0], null);
     }
+    nsObj[tagParts[1]] = os.createTemplateCustomTag(template);
   }
 };


Reply via email to