Reviewers: rjrjr,

Description:
Update UiBinder to use SafeHtml instead of String in HtmlPanelParser
constructor

Review by: [email protected]

Please review this at http://gwt-code-reviews.appspot.com/1384805/

Affected files:
  M user/src/com/google/gwt/uibinder/elementparsers/HTMLPanelParser.java
  M user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
  M user/src/com/google/gwt/uibinder/rebind/model/HtmlTemplate.java
  M user/src/com/google/gwt/uibinder/rebind/model/HtmlTemplates.java


Index: user/src/com/google/gwt/uibinder/elementparsers/HTMLPanelParser.java
===================================================================
--- user/src/com/google/gwt/uibinder/elementparsers/HTMLPanelParser.java (revision 9857) +++ user/src/com/google/gwt/uibinder/elementparsers/HTMLPanelParser.java (working copy)
@@ -59,7 +59,8 @@
     String customTag = elem.consumeStringAttribute("tag", null);

     if (null == customTag) {
- writer.setFieldInitializerAsConstructor(fieldName, type, writer.declareTemplateCall(html));
+      writer.setFieldInitializerAsConstructor(fieldName, type,
+          writer.declareTemplateCallNoAsString(html));
     } else {
       writer.setFieldInitializerAsConstructor(fieldName, type, customTag,
           writer.declareTemplateCall(html));
Index: user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
===================================================================
--- user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java (revision 9857) +++ user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java (working copy)
@@ -415,6 +415,19 @@
   public String declareTemplateCall(String html)
     throws IllegalArgumentException {
     return htmlTemplates.addSafeHtmlTemplate(html, tokenator);
+  }
+
+  /**
+ * Writes a new SafeHtml template to the generated BinderImpl. This differs + * from {@link #declareTemplateCall} because the returned template call will
+   * return a SafeHtml object rather than a String.
+   *
+ * @return The invocation of the SafeHtml template function with the arguments
+   * filled in
+   */
+  public String declareTemplateCallNoAsString(String html)
+    throws IllegalArgumentException {
+    return htmlTemplates.addSafeHtmlTemplateNoAsString(html, tokenator);
   }

   /**
Index: user/src/com/google/gwt/uibinder/rebind/model/HtmlTemplate.java
===================================================================
--- user/src/com/google/gwt/uibinder/rebind/model/HtmlTemplate.java (revision 9857) +++ user/src/com/google/gwt/uibinder/rebind/model/HtmlTemplate.java (working copy)
@@ -79,6 +79,17 @@
     return "template." + methodName + "(" + getSafeHtmlArgs()
       + ").asString()";
   }
+
+  /**
+   * Creates the template method invocation.  This differs from
+   * {@link #writeTemplateCall} because the returned template call will
+   * return a SafeHtml object rather than a String.
+   *
+   * @return String the template method call with parameters
+   */
+  public String writeTemplateCallNoAsString() {
+    return "template." + methodName + "(" + getSafeHtmlArgs() + ")";
+  }

   /**
    *  Replaces string tokens with {} placeholders for SafeHtml templating.
Index: user/src/com/google/gwt/uibinder/rebind/model/HtmlTemplates.java
===================================================================
--- user/src/com/google/gwt/uibinder/rebind/model/HtmlTemplates.java (revision 9857) +++ user/src/com/google/gwt/uibinder/rebind/model/HtmlTemplates.java (working copy)
@@ -61,6 +61,34 @@

     return ht.writeTemplateCall();
   }
+
+  /**
+ * Add a SafeHtml template and an instance method for invoking the template + * to the generated BinderImpl class. These templates are declared at the + * beginning of the class and instantiated with a GWT.create(Template.class
+   * call.
+   * <p>
+   * Note that the UiBinder#tokenator is used to determine the arguments to
+   * the generated SafeHtml template. Also, this differs from
+   * {@link #addSafeHtmlTemplate} because the returned template call will
+   * return a SafeHtml object rather than a String.
+   *
+   * @return String the function to call this template
+   */
+  public String addSafeHtmlTemplateNoAsString(String html, Tokenator t)
+    throws IllegalArgumentException {
+    if (html == null) {
+      throw new IllegalArgumentException("Template html cannot be null");
+    }
+    if (t == null) {
+ throw new IllegalArgumentException("Template tokenator cannot be null");
+    }
+
+    HtmlTemplate ht = new HtmlTemplate(html, t, this);
+    htmlTemplates.add(ht);
+
+    return ht.writeTemplateCallNoAsString();
+  }

   public int getNumTemplates() {
     return htmlTemplates.size();


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to