shale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gvanma...@apache.org
Subject svn commit: r426856 - in /shale/framework/trunk: shale-apps/shale-clay-usecases/src/main/webapp/symbols/ shale-clay/src/main/java/org/apache/shale/clay/parser/ shale-clay/src/test/java/org/apache/shale/clay/parser/
Date Sun, 30 Jul 2006 01:08:51 GMT
Author: gvanmatre
Date: Sat Jul 29 18:08:50 2006
New Revision: 426856

URL: http://svn.apache.org/viewvc?rev=426856&view=rev
Log:
Add comment tokens that removes a block of markup when using Clay html templates. The beginning
and ending token delimiters must be self terminated comments that are verbatim to the following:


<!-- ### clay:remove ### --> 
<!-- ### /clay:remove ### --> 

This feature was requested by Rene Zanner (SHALE-240).

Modified:
    shale/framework/trunk/shale-apps/shale-clay-usecases/src/main/webapp/symbols/fullperson.html
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/Parser.java
    shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/parser/ParserTestCase.java

Modified: shale/framework/trunk/shale-apps/shale-clay-usecases/src/main/webapp/symbols/fullperson.html
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-clay-usecases/src/main/webapp/symbols/fullperson.html?rev=426856&r1=426855&r2=426856&view=diff
==============================================================================
--- shale/framework/trunk/shale-apps/shale-clay-usecases/src/main/webapp/symbols/fullperson.html
(original)
+++ shale/framework/trunk/shale-apps/shale-clay-usecases/src/main/webapp/symbols/fullperson.html
Sat Jul 29 18:08:50 2006
@@ -1,8 +1,10 @@
-<html jsfid="void">
-<head jsfid="void" allowBody="false">
+<!-- ### clay:remove ### -->
+<html>
+<head>
 <title>Mock Title</title>
 </head>
-<body jsfid="void">
+<body>
+<!-- ### /clay:remove ### -->
 <span jsfid="page2Panel">
 <table>
 	<tr>
@@ -47,5 +49,7 @@
 	</tr>
 </table>
 </span>
+<!-- ### clay:remove ### -->
 </body>
 </html>
+<!-- ### /clay:remove ### -->

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/Parser.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/Parser.java?rev=426856&r1=426855&r2=426856&view=diff
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/Parser.java
(original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/Parser.java
Sat Jul 29 18:08:50 2006
@@ -257,6 +257,15 @@
 
     }
 
+    /**
+     * <p>Starting remove block delimiter.  It must be a self contained commment.<p>
+     */
+    private static final String BEGIN_REMOVE_TOKEN = "<!-- ### clay:remove ### -->";
+
+    /**
+     * <p>Ending remove block delimiter.</p>
+     */
+    private static final String END_REMOVE_TOKEN = "<!-- ### /clay:remove ### -->";
 
     /**
      * <p>
@@ -269,6 +278,7 @@
      */
     public List parse(StringBuffer document) {
 
+        boolean isWithinRemoveBlock = false;
         Node root = new Node(null);
         Node current = root;
         current.setName("namingContainer");
@@ -278,8 +288,29 @@
         Iterator i = t.iterator();
         next: while (i.hasNext()) {
             Token token = (Token) i.next();
-
             Node node = buildNode(token);
+
+            // self contained comment matching the begin/end remove token delimiter
+            // skip all tokens within the remove block
+            if (node.isComment() && node.isStart() && node.isEnd()) {
+
+                if (isWithinRemoveBlock && node.getToken().getRawText().equals(END_REMOVE_TOKEN))
{
+
+                   isWithinRemoveBlock = false;
+                   continue next;
+
+                } else if (node.getToken().getRawText().equals(BEGIN_REMOVE_TOKEN)) {
+
+                  isWithinRemoveBlock = true;
+                  continue next;
+
+               } else if (isWithinRemoveBlock) {
+                  continue next;
+               }
+            } else if (isWithinRemoveBlock) {
+                continue next;
+            }
+
 
             //play forward on comments making all nodes child nodes until a
             //ending comment is hit

Modified: shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/parser/ParserTestCase.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/parser/ParserTestCase.java?rev=426856&r1=426855&r2=426856&view=diff
==============================================================================
--- shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/parser/ParserTestCase.java
(original)
+++ shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/parser/ParserTestCase.java
Sat Jul 29 18:08:50 2006
@@ -775,8 +775,48 @@
            
            
         }
-   
+                
+    }
+    
+    
+    public void testRemoveBlock() {
+        Parser p = new Parser();
+        StringBuffer doc = new StringBuffer();
+        doc.append("<!-- ### clay:remove ### -->")
+           .append("<html>")
+           .append("<div class=\"content\">")
+           .append("<!-- ### /clay:remove ### -->")
+           .append("<!--")
+           .append("    this is the body content to be placed")
+           .append("    in the basic layout HTML template defined elsewhere")
+           .append("-->")
+           .append("<form>")
+           .append("<input type=\"text\" value=\"#{contentBean.inputText}\"/>")
+           .append("<input type=\"submit\" action=\"#{contentBean.doSubmit}\"/>")
+           .append("</form>")
+           .append("<!-- ### clay:remove ### -->")
+           .append("</div>")
+           .append("<!--   this is the basic layout to be removed when converting to an
include -->")
+           .append("</html>")
+           .append("<!-- ### /clay:remove ### -->");     
+        
+        List roots = p.parse(doc);
+        assertNotNull(roots);
+        
+        assertEquals("root nodes", 2, roots.size());
+        
+        Node comment = (Node) roots.get(0);
+        
+        assertEquals("isComment", true, comment.isComment());
+        
+        Node form = (Node) roots.get(1);
+        
+        assertEquals("form well-formed", true, form.isWellFormed());
+        assertEquals("form name", "form", form.getName());
+        assertEquals("form children", 2, form.getChildren().size());
+        
         
     }
+
 
 }



Mime
View raw message