Author: julien_viet
Date: 2009-10-30 16:42:31 -0400 (Fri, 30 Oct 2009)
New Revision: 465
Modified:
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScriptBuilder.java
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
Log:
fix gtmpl bug where a line comment was propagated to the markup
Modified:
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScriptBuilder.java
===================================================================
---
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScriptBuilder.java 2009-10-30
19:05:32 UTC (rev 464)
+++
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScriptBuilder.java 2009-10-30
20:42:31 UTC (rev 465)
@@ -82,8 +82,6 @@
{
case STRING:
accumulatedText.append("\n");
-// script.appendText(accumulatedText.toString());
-// accumulatedText.setLength(0);
break;
case SCRIPTLET:
script.appendGroovy("\n");
@@ -112,6 +110,7 @@
}
break;
case SCRIPTLET:
+ script.appendGroovy("\n");
break;
case EXPR:
script.appendGroovy("}\");");
@@ -204,6 +203,7 @@
}
else
{
+/*
String code = Integer.toHexString(c);
switch (code.length())
{
@@ -222,6 +222,8 @@
break;
}
builder.append("\\u").append(code);
+*/
+ builder.append(c);
}
}
return "public static final " + GroovyText.class.getName() + "
" + name + " = new " + GroovyText.class.getName() + "(\"" +
builder + "\");";
Modified:
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
===================================================================
---
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2009-10-30
19:05:32 UTC (rev 464)
+++
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2009-10-30
20:42:31 UTC (rev 465)
@@ -48,7 +48,6 @@
public void testFoo() throws Exception
{
GroovyTemplate template = new GroovyTemplate("a");
-// System.out.println("template = " + template.getGroovyText());
String render = template.render();
assertEquals("a", render);
}
@@ -56,7 +55,6 @@
public void testBar() throws Exception
{
GroovyTemplate template = new GroovyTemplate("<%='a'%>");
-// System.out.println("template = " + template.getGroovyText());
String render = template.render();
assertEquals("a", render);
}
@@ -64,7 +62,6 @@
public void testFooBar() throws Exception
{
GroovyTemplate template = new
GroovyTemplate("a<%='b'%>c");
-// System.out.println("template = " + template.getGroovyText());
String render = template.render();
assertEquals("abc", render);
}
@@ -72,7 +69,6 @@
public void testJuu() throws Exception
{
GroovyTemplate template = new GroovyTemplate("<%
out.print(\"a\"); %>");
-// System.out.println("template = " + template.getGroovyText());
String render = template.render();
assertEquals("a", render);
}
@@ -102,10 +98,18 @@
"a\n" +
"<% if (true) {\n %>" +
"b\n" +
- "<% } %>\n"
- );
+ "<% } %>");
+ String s = template.render();
+ assertEquals("a\nb\n", s);
}
+ public void testLineComment() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<% // foo %>a\nb");
+ String s = template.render();
+ assertEquals("a\nb", s);
+ }
+
public void testContextResolution() throws Exception
{
GroovyTemplate template = new GroovyTemplate("<%= foo %>");