Author: johnh
Date: Mon Oct  6 12:49:07 2008
New Revision: 702241

URL: http://svn.apache.org/viewvc?rev=702241&view=rev
Log:
Inlines ${Msg.foo} references into template during construction, which in turn 
enables ${}-style markup in messages to be processed appropriately.

See SHINDIG-645 for details. This CL resolves that issue.

Patch provided by Lev Epshteyn ([EMAIL PROTECTED])


Modified:
    incubator/shindig/trunk/features/opensocial-templates/base.js
    incubator/shindig/trunk/features/opensocial-templates/compiler.js
    incubator/shindig/trunk/features/opensocial-templates/util.js

Modified: incubator/shindig/trunk/features/opensocial-templates/base.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/base.js?rev=702241&r1=702240&r2=702241&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/base.js (original)
+++ incubator/shindig/trunk/features/opensocial-templates/base.js Mon Oct  6 
12:49:07 2008
@@ -108,6 +108,7 @@
   
   opt_id = opt_id || node.id;
   var src = node.value || node.innerHTML;
+  src = os.trim(src);
   var template = os.compileTemplateString(src, opt_id);
   return template;
 };
@@ -119,7 +120,7 @@
  * @return {os.Template} A compiled Template object.
  */
 os.compileTemplateString = function(src, opt_id) {
-  var src = os.prepareTemplateXML_(src);
+  src = os.prepareTemplateXML_(src);
   var doc = os.parseXML_(src);
   return os.compileXMLDoc(doc, opt_id);
 };
@@ -197,14 +198,6 @@
 };
 
 /**
- * A convenience function for identifier resolver to be able to use 
- * getPrefMessage() both as ${Msg.foo} and ${Msg('foo')}.
- */
-os.getPrefMessage.get = function(key) {
-  return os.getPrefMessage(key);
-};
-
-/**
  * Globally disallowed dynamic attributes. These are the attributes where
  * ${} notation will be ignored reguardless of the tag.
  */

Modified: incubator/shindig/trunk/features/opensocial-templates/compiler.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/compiler.js?rev=702241&r1=702240&r2=702241&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/compiler.js (original)
+++ incubator/shindig/trunk/features/opensocial-templates/compiler.js Mon Oct  
6 12:49:07 2008
@@ -518,7 +518,6 @@
   var context = JsEvalContext.create(data);
   context.setVariable(os.VAR_callbacks, []);
   context.setVariable(os.VAR_identifierresolver, os.getFromContext);
-  context.setVariable(os.VAR_msg, os.getPrefMessage);
   if (opt_globals) {
     for (var global in opt_globals) {
       context.setVariable(global, opt_globals[global]);
@@ -853,6 +852,18 @@
   if (!os.canStartIdentifier(token.charAt(0))) {
     return token;
   }
+
+  // If the identifier is accessing a message 
+  // (and gadget messages are obtainable), inline it here.
+  // TODO: This is inefficient for times when the message contains no markup - 
+  // such cases should be optimized.  
+  if (token.substring(0, os.VAR_msg.length + 1) == (os.VAR_msg + '.') && 
+      os.gadgetPrefs_) {
+    var key = token.split(".")[1];
+    var msg = os.getPrefMessage(key) || '';
+    return os.parseAttribute_(msg) || os.transformLiteral_(msg);
+  }
+  
   var identifiers = os.tokenToIdentifiers(token);
   var parts = false;
   var buffer = [];

Modified: incubator/shindig/trunk/features/opensocial-templates/util.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-templates/util.js?rev=702241&r1=702240&r2=702241&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-templates/util.js (original)
+++ incubator/shindig/trunk/features/opensocial-templates/util.js Mon Oct  6 
12:49:07 2008
@@ -20,6 +20,16 @@
  * @fileoverview Provides various utility functions used throughout the 
library.
  */
 
+
+/**
+ * Trims leading and trailing whitespace from a string.
+ * @param {string} string The input string.
+ * @returns {string} Input with leading and trailing whitespace removed.
+ */
+os.trim = function(string) {
+  return string.replace(/^\s+/, '').replace(/\s+$/, '');         
+};
+
 /**
  * Checks whether or not a given character is alpha-numeric.
  * @param {string} ch Character to check.


Reply via email to