|
[
Permalink
| « Hide
]
Jonathan Carlson added a comment - 19/Sep/06 03:50 PM
Come to think of it, the problem may be in the File.write(aString) method. I'm not sure where to find that, though.
SimpleTemplateEngine was not the problem. I'll open a new issue for File.write(string)
I'm sorry I didn't get this straight before, but File.write(string) is working just like Java println does so that is not the problem. The problem still remains that a Windows template file (with \r\n) generates output with just \n
Thanks in advance! The template script generates a lot of out.print "whatever \n" commands (notice the \n at the end of the line). If, instead, these types of lines could be converted to out.println "whatever" (use println with no \n at the end of the line) then it would always behave as it should.
I'm sorry, it's been a long time since I've worked on this on Windows. Now I'm using a Mac and I haven't used the Template Engine since then, although I hope to use it again!
Here's a very basic template test script I found in my scripting archive if it would help you! It seems to break the lines fine on Mac.
// This script is an example for generating code or e-mails or HTML or whatever import groovy.text.Template // ===== Define the Template ===== println "\n=========== Generated Text 1 ===========" println "\n=========== Generated Text 2 ===========" Made the following little patch to SimpleTemplateEngine (partial code):
/* Handle raw new line characters. */ if (c == '\n' || c == '\r') { if (c == '\r') { // on Windows, "\r\n" is a new line. reader.mark(1); c = reader.read(); if (c != '\n') { reader.reset(); } } sw.write("\\r\\n\");\nout.print(\""); continue; } sw.write(c); Works as we are windows only. Better solution: Should use println's to get platform dependent lf. Oh, here's the TemplateFile.txt content that the script uses:
Dear ${firstname} ${lastname}, |
|||||||||||||||||||||||||||||||||||||||||||||||