I'm having one of those bang-head-against-the-wall moments with Velocity
1.4. I've got a formatter class with the following methods:
public String currency(float amount) {
Format formatter = NumberFormat.getCurrencyInstance();
return formatter.format(new Float(amount));
}
public String leftPad(String string, int width) {
if (string.length() >= width) {
return string.substring( string.length()-(width+1));
}
StringBuffer output = new StringBuffer();
for (int i=0; i < (width - string.length()); i++) {
output.append(' ');
}
output.append(string);
return output.toString();
}
And have defined macros in my template:
#macro(leftpad $message)
${formatter.leftpad($message, 8)}
#end
#macro(currency $amount)${formatter.currency($amount)}#end
And called them in the template:
#foreach($orderLine in $orderLines)
#leftpad($orderLine.quantity)
#currency($order.shippingPrice)
#end
Strangely, the #currency macro fully executes, but the #leftpad macro leaves
$formatter.leftpad($orderLine.quantity, 8) after the template has been
processed. Is there something I'm doing wrong here? And is there a
different way I should be doing this?
Thanks,
Rob