Revision: 9912
Author:   [email protected]
Date:     Tue Mar 29 12:27:56 2011
Log: Adds support for the CSS_ATTRIBUTE_START parse context to HtmlTemplateParser.

Review at http://gwt-code-reviews.appspot.com/1392801

http://code.google.com/p/google-web-toolkit/source/detail?r=9912

Modified:
 /trunk/user/src/com/google/gwt/safehtml/rebind/HtmlTemplateParser.java
 /trunk/user/src/com/google/gwt/safehtml/rebind/ParsedHtmlTemplate.java
 /trunk/user/test/com/google/gwt/safehtml/rebind/HtmlTemplateParserTest.java

=======================================
--- /trunk/user/src/com/google/gwt/safehtml/rebind/HtmlTemplateParser.java Thu Dec 9 08:34:53 2010 +++ /trunk/user/src/com/google/gwt/safehtml/rebind/HtmlTemplateParser.java Tue Mar 29 12:27:56 2011
@@ -74,10 +74,14 @@
* <dd>This context corresponds to a parameter that appears at the very start of * a URL-valued HTML attribute's value; in the above example this applies to
  * parameter #1.
+ * <dt>{@link HtmlContext.Type#CSS_ATTRIBUTE_START}
+ * <dd>This context corresponds to a parameter that appears at the very
+ * beginning of a {@code style} attribute's value; in the above example this
+ * applies to parameter #0.
  * <dt>{@link HtmlContext.Type#CSS_ATTRIBUTE}
* <dd>This context corresponds to a parameter that appears in the context of a
- * {@code style} attribute; in the above example this applies to
- * parameter #0.
+ * {@code style} attribute, except at the very beginning of the attribute's
+ * value.
  * <dt>{@link HtmlContext.Type#ATTRIBUTE_VALUE}
* <dd>This context corresponds to a parameter that appears within an attribute
  * and is not in one of the more specific in-attribute contexts above. In
@@ -210,7 +214,11 @@
    */
   private HtmlContext getHtmlContextFromParseState()
       throws UnableToCompleteException {
-
+ // TODO(xtof): Consider refactoring such that state related to the position
+    // of the template variable in an attribute is exposed separately (as
+ // HtmlContext#isAttributeStart(), etc). In doing so, consider trade off
+    // between combinatorial explosion of possible states vs. complexity of
+    // client code.
     if (streamHtmlParser.getState().equals(HtmlParser.STATE_ERROR)) {
       logger.log(TreeLogger.ERROR,
           "Parsing template resulted in parse error: "
@@ -250,7 +258,11 @@
       if (streamHtmlParser.isUrlStart()) {
         return new HtmlContext(HtmlContext.Type.URL_START, tag, attribute);
       } else if (streamHtmlParser.inCss()) {
- return new HtmlContext(HtmlContext.Type.CSS_ATTRIBUTE, tag, attribute);
+        if (streamHtmlParser.getValueIndex() == 0) {
+ return new HtmlContext(HtmlContext.Type.CSS_ATTRIBUTE_START, tag, attribute);
+        } else {
+ return new HtmlContext(HtmlContext.Type.CSS_ATTRIBUTE, tag, attribute);
+        }
       } else {
         return new HtmlContext(
             HtmlContext.Type.ATTRIBUTE_VALUE, tag, attribute);
=======================================
--- /trunk/user/src/com/google/gwt/safehtml/rebind/ParsedHtmlTemplate.java Thu Dec 9 08:34:53 2010 +++ /trunk/user/src/com/google/gwt/safehtml/rebind/ParsedHtmlTemplate.java Tue Mar 29 12:27:56 2011
@@ -64,7 +64,11 @@
       /**
        * CSS (style) attribute context.
        */
-      CSS_ATTRIBUTE
+      CSS_ATTRIBUTE,
+      /**
+       * At the very start of a CSS (style) attribute context.
+       */
+      CSS_ATTRIBUTE_START
     }

     private final Type type;
=======================================
--- /trunk/user/test/com/google/gwt/safehtml/rebind/HtmlTemplateParserTest.java Thu Dec 9 08:34:53 2010 +++ /trunk/user/test/com/google/gwt/safehtml/rebind/HtmlTemplateParserTest.java Tue Mar 29 12:27:56 2011
@@ -134,10 +134,15 @@
     // Test correct detection of CSS context.
     assertParseTemplateResult(
"[L(<div class=\"), P((ATTRIBUTE_VALUE,div,class),0), L(\" style=\"), "
-            + "P((CSS_ATTRIBUTE,div,style),2), L(\">Hello ), "
+            + "P((CSS_ATTRIBUTE_START,div,style),2), L(\">Hello ), "
             + "P((TEXT,null,null),1)]",
         "<div class=\"{0}\" style=\"{2}\">Hello {1}");
     assertParseTemplateResult(
+ "[L(<div class=\"), P((ATTRIBUTE_VALUE,div,class),0), L(\" style=\"color:green; ), "
+            + "P((CSS_ATTRIBUTE,div,style),2), L(\">Hello ), "
+            + "P((TEXT,null,null),1)]",
+        "<div class=\"{0}\" style=\"color:green; {2}\">Hello {1}");
+    assertParseTemplateResult(
         "[L(<div>), P((TEXT,null,null),0), L(<style>foo ), "
             + "P((CSS,null,null),1), L(</style>)]",
         "<div>{0}<style>foo {1}</style>");

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

Reply via email to