On 4/24/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
this example brings up the issue of making #local(...) a
core directive:

i'm always forgetting that #local is out there.  do we have a JIRA
issue open about putting this in the core?  even if we couldn't reach
consensus there (and with the #springBind issue, i'm sure we're
getting closer to that), then it would be a good reminder and a place
to keep discussion centralized.

> #macro( truncate $stringVariable $length )
#local( $truncateMe )
> #set( $truncateMe = "$!stringVariable" )
> #if( $truncateMe.length() <=
> $length)$truncateMe#else$!{truncateMe.substring(0,$length)}...#end##
#end
> #end

I prefer #local vs velocimacro.context.localscope because
you can create macro libraries that allow declaring local vars
without polluting the namespace, but also enables setting global
variables. See the thread ending on 16.04.2007 "RE: 
velocimacro.context.localscope"
with the #springBind example for such a case.

:) Chirstoph

Nathan Bubna wrote:
> Sorry, i didn't realize we had not fully covered the functions of
> VelocityFormatter in Tools.  Looks like we missed some utils for
> formatting arrays/vectors too.  I'll have to think about where to add
> these.
>
> In the meantime, i suppose i would recommend writing a tool or macro
> of your own.  The code can be copied straight out of VelocityFormatter
> or written to suit you.  We have typically used a #truncate
> velocimacro to do this in our apps:
>
> #macro( truncate $stringVariable $length )
> #set( $truncateMe = "$!stringVariable" )
> #if( $truncateMe.length() <=
> $length)$truncateMe#else$!{truncateMe.substring(0,$length)}...#end##
> #end
>
>
> On 4/23/07, Sebastian Gumpold <[EMAIL PROTECTED]> wrote:
>> Hi all!
>>
>> I'm new to Velocity and tried to find a way to limit the length of an
>> String. The solution I found worked great for my needs:
>> VelocityFormatter.limitLen().
>> Much to my regret I noticed that with Velocity 1.5 (and Tools 1.3)
>> VelocityFormatter got marked as depricated and I didn't find a proper
>> replacement for this method in any of the both suggested Tools classes
>> NumberTool and DateTool.
>>
>> So here's my question: What's the suggested way to handle this: the usage
>> of other Tools classes? Own code?
>>
>> Thanks in advance,
>> Sebastian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to