dlr 01/05/11 19:04:26
Modified: src/java/org/apache/velocity/convert WebMacro.java
Log:
Files with no JavaScript in them now have WebMacro every nuance that
I'm aware of converted.
Revision Changes Path
1.14 +20 -9
jakarta-velocity/src/java/org/apache/velocity/convert/WebMacro.java
Index: WebMacro.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/convert/WebMacro.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- WebMacro.java 2001/05/11 19:49:34 1.13
+++ WebMacro.java 2001/05/12 02:04:25 1.14
@@ -71,7 +71,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
- * @version $Id: WebMacro.java,v 1.13 2001/05/11 19:49:34 dlr Exp $
+ * @version $Id: WebMacro.java,v 1.14 2001/05/12 02:04:25 dlr Exp $
*/
public class WebMacro
{
@@ -90,10 +90,12 @@
"#if( $1 )",
// Remove the WM #end #else #begin usage.
- "[ \\t]?(#end|})(\\s*)#else\\s*(#begin|{)[ \\t]?(\\w)",
+ "[ \\t]?(#end|})[ \\t]*\n(\\s*)#else\\s*(#begin|{)[ \\t]?(\\w)",
"$2#else#**#$4", // avoid touching followup word with embedded comment
- "[ \\t]?(#end|})(\\s*)#else\\s*(#begin|{)[ \\t]?",
+ "[ \\t]?(#end|})[ \\t]*\n(\\s*)#else\\s*(#begin|{)[ \\t]?",
"$2#else",
+ "(#end|})(\\s*#else)\\s*(#begin|{)[ \\t]?",
+ "$1\n$2",
// Convert WM style #foreach to Velocity directive style.
"#foreach\\s+(\\$\\w+)\\s+in\\s+(\\$[^\\s#]+)\\s*(#begin|{)[ \\t]?",
@@ -283,15 +285,24 @@
contents += "\n";
}
+ // Convert most markup.
Perl5Util perl = new Perl5Util();
- String re;
for (int i = 0; i < perLineREs.length; i += 2)
{
- re = makeSubstRE(i);
- while (perl.match('/' + perLineREs[i] + '/', contents))
- {
- contents = perl.substitute(re, contents);
- }
+ contents = perl.substitute(makeSubstRE(i), contents);
+ }
+
+ // Convert closing curlies.
+ if (perl.match("m/javascript/i", contents))
+ {
+ // ASSUMPTION: JavaScript is indented, WM is not.
+ contents = perl.substitute("s/\n}/\n#end/g", contents);
+ }
+ else
+ {
+ contents = perl.substitute("s/(\n\\s*)}/$1#end/g", contents);
+ contents = perl.substitute("s/#end\\s*\n\\s*#else/#else/g",
+ contents);
}
return contents;