[Templates] Re: CHOMP feature request

chocolateboy chocolate.boy@email.com
Sun, 12 Feb 2006 20:59:24 +0000


Hi.

Thanks for taking a look at Template::Parser::Greedy.

> Looks like we uploaded them about the same time.

I released an earlier version last week, but rewrote and renamed the 
module to incorporate most (in fact, I think all) of the suggestions in 
this thread and the "Removing even more whitespace" thread from a week 
or so ago. I think I've included all of your earlier suggestions, so you 
certainly uploaded the inspiration first :-)

> but I'd rather have the functionality in the core Toolkit

I don't mind maintaining a separate module, but, yes, the whole point 
was to add functionality that I'd always expected/wanted to be in the core.

> Looking at the code it looks like Template-Parser-Greedy doesn't
> handle counting the prelines quite right

Unless there's a bug in the test, it does count the prelines correctly: see

http://search.cpan.org/src/CHOCOLATE/Template-Parser-Greedy-1.00/t/preline.t

and:

http://search.cpan.org/src/CHOCOLATE/Template-Parser-Greedy-1.00/t/t2_line_count_bug.t

I'd also recommend running your patch against the test suite, 
particularly options.t, which is exhaustive:

http://search.cpan.org/src/CHOCOLATE/Template-Parser-Greedy-1.00/t/options.t

chocolateboy

mail-vAmMQTyk7hpBDgjK7y7TUQ@public.gmane.org wrote:
 > On Saturday 11 February 2006 09:52 am, Clayton Scott wrote:
 >> Did anyone see Template::Parser::Greedy get uploaded to CPAN yesterday?
 >
 > Hrm - no I hadn't.  I guess I should've released my patches sooner.  The
 > separate module is fine I guess - but I'd rather have the 
functionality in
 > the core Toolkit - not that anybody has heard any word either way.
 >
 > Looks like we uploaded them about the same time.
 >
 > Looking at the code it looks like Template-Parser-Greedy doesn't handle
 > counting the prelines quite right so debug will be off some possibly 
a lot -
 > but that may not be an issue.
 >
 > Also I chose the name of CHOMP_HTML vs his CHOMP_COALESCE because it 
does what
 > HTML does, its short and it is somewhat different than the name COLLAPSE.
 >
 > I'd hope my patches may still be considered - they are wanted enough 
that
 > somebody went to the trouble of making a separate module.
 >
 > I guess we'll wait and see.
 >
 > Paul
 >
 >> http://search.cpan.org/dist/Template-Parser-Greedy/
 >>
 >> DESCRIPTION
 >>
 >> It's easy to write readable templates in Template::Toolkit, and it's
 >> easy to exercise fine-grained control over the output of Template
 >> Toolkit templates. Achieving both at the same time, however, can be
 >> tricky given the default parser's whitespace chomping rules, which
 >> consume no more than one newline character on either side of a
 >> directive.
 >>
 >> This means that template authors optimizing for readability (and
 >> writability) may be obliged to compromise the indentation and spacing
 >> of the output and vice versa.
 >>
 >> This module allows templates to be laid out in a readable way, while
 >> at the same time enhancing control over the spacing of the generated
 >> output. It does this by providing two new options, CHOMP_GREEDY and
 >> CHOMP_COALESCE, and their corresponding directive modifiers, ~ and ^.
 >>
 >> In addition, a new modifier, =, for the old CHOMP_COLLAPSE option has
 >> been added.
 >>
 >>
 >> Clayton
 >>
 >> On 2/10/06, mail-vAmMQTyk7hpBDgjK7y7TUQ@public.gmane.org 
<mail-vAmMQTyk7hpBDgjK7y7TUQ@public.gmane.org> wrote:
 >>>> There is one change in functionality with these patches
 >>> Actually - there is one more change.
 >>>
 >>> In the old TT behavior if PRE_CHOMP or POST_CHOMP were set to
 >>> CHOMP_COLLAPSE, the following would happen:
 >>>
 >>> "[% 1 -%]  [%- 2 %]" would result in "1 2".  The "-" would have no 
effect
 >>> - which seems a bit odd.
 >>>
 >>> Under the new rules "[% 1 -%]  [%- 2 %]" would always result in "12" no
 >>> matter what PRE_CHOMP or POST_CHOMP is set to - which again seems 
closer
 >>> to what the user would desire (at least this user would desire it to do
 >>> what I told it to do - and anecdoteally evidence would suggest that 
other
 >>> users would desire this also - as there was a Note in in the Config.pod
 >>> to warn of this behavior).
 >>>
 >>> The config_pod.diff file in the prior post file already removes the 
noted
 >>> exception about the former behavior in TT (since the behavior is now
 >>> removed).
 >>>
 >>> If this is unacceptable, putting the space back in can be 
accommodated -
 >>> but again I think this is more consistent.
 >>>
 >>> Paul Seamons
 >>> mail-vAmMQTyk7hpBDgjK7y7TUQ@public.gmane.org
 >>>
 >>> _______________________________________________
 >>> templates mailing list
 >>> templates-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@public.gmane.org
 >>> http://lists.template-toolkit.org/mailman/listinfo/templates
 >> --
 >>
 >> Clayton Scott
 >> clayton.scott-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

mail-vAmMQTyk7hpBDgjK7y7TUQ@public.gmane.org wrote:
> On Saturday 11 February 2006 09:52 am, Clayton Scott wrote:
>> Did anyone see Template::Parser::Greedy get uploaded to CPAN yesterday?
> 
> Hrm - no I hadn't.  I guess I should've released my patches sooner.  The 
> separate module is fine I guess - but I'd rather have the functionality in 
> the core Toolkit - not that anybody has heard any word either way.
> 
> Looks like we uploaded them about the same time.
> 
> Looking at the code it looks like Template-Parser-Greedy doesn't handle 
> counting the prelines quite right so debug will be off some possibly a lot - 
> but that may not be an issue.
> 
> Also I chose the name of CHOMP_HTML vs his CHOMP_COALESCE because it does what 
> HTML does, its short and it is somewhat different than the name COLLAPSE.
> 
> I'd hope my patches may still be considered - they are wanted enough that 
> somebody went to the trouble of making a separate module.
> 
> I guess we'll wait and see.
> 
> Paul
> 
>> http://search.cpan.org/dist/Template-Parser-Greedy/
>>
>> DESCRIPTION
>>
>> It's easy to write readable templates in Template::Toolkit, and it's
>> easy to exercise fine-grained control over the output of Template
>> Toolkit templates. Achieving both at the same time, however, can be
>> tricky given the default parser's whitespace chomping rules, which
>> consume no more than one newline character on either side of a
>> directive.
>>
>> This means that template authors optimizing for readability (and
>> writability) may be obliged to compromise the indentation and spacing
>> of the output and vice versa.
>>
>> This module allows templates to be laid out in a readable way, while
>> at the same time enhancing control over the spacing of the generated
>> output. It does this by providing two new options, CHOMP_GREEDY and
>> CHOMP_COALESCE, and their corresponding directive modifiers, ~ and ^.
>>
>> In addition, a new modifier, =, for the old CHOMP_COLLAPSE option has
>> been added.
>>
>>
>> Clayton
>>
>> On 2/10/06, mail-vAmMQTyk7hpBDgjK7y7TUQ@public.gmane.org <mail-vAmMQTyk7hpBDgjK7y7TUQ@public.gmane.org> wrote:
>>>> There is one change in functionality with these patches
>>> Actually - there is one more change.
>>>
>>> In the old TT behavior if PRE_CHOMP or POST_CHOMP were set to
>>> CHOMP_COLLAPSE, the following would happen:
>>>
>>> "[% 1 -%]  [%- 2 %]" would result in "1 2".  The "-" would have no effect
>>> - which seems a bit odd.
>>>
>>> Under the new rules "[% 1 -%]  [%- 2 %]" would always result in "12" no
>>> matter what PRE_CHOMP or POST_CHOMP is set to - which again seems closer
>>> to what the user would desire (at least this user would desire it to do
>>> what I told it to do - and anecdoteally evidence would suggest that other
>>> users would desire this also - as there was a Note in in the Config.pod
>>> to warn of this behavior).
>>>
>>> The config_pod.diff file in the prior post file already removes the noted
>>> exception about the former behavior in TT (since the behavior is now
>>> removed).
>>>
>>> If this is unacceptable, putting the space back in can be accommodated -
>>> but again I think this is more consistent.
>>>
>>> Paul Seamons
>>> mail-vAmMQTyk7hpBDgjK7y7TUQ@public.gmane.org
>>>
>>> _______________________________________________
>>> templates mailing list
>>> templates-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@public.gmane.org
>>> http://lists.template-toolkit.org/mailman/listinfo/templates
>> --
>>
>> Clayton Scott
>> clayton.scott-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org