PDA

View Full Version : Template feature possibility



Robert Moser II
2003-12-14, 19:17
I've been hacking away at my Moser skin and incorporated a little
javascript, which didn't work at first. The reason was of course all
the {}s and []s in the code. So after going through the code and
replacing everything with &lbrc;&rbrc; and [] I had a thought,
wouldn't it be nice if I had a template directive which would just
skip all this crap?

So, what would everyone think of another directive for templates:
[NOEVAL] (or [CODE], or [LITERAL], or [WHATEVER]). Anything contained
within this directive would be left alone by all the other processing steps.

Of course, as I write this I got to thinking about how exactly such a
directive would work, and came to the conclusion that it would be very
hard to do. The closest I could figure would be to go through the
section of text enclosed by the [NOEVAL] directive and replace the {}s
and []s with their & versions. Then when filltemplate got around to the
end, it would switch them back.

Of course that method has problems if you actually want to have the &
versions of {}[] in the [NOEVAL]'d text.

Comments anyone? For example: "Stop being such a baby and just do the
replacements yourself!"

Dan Sully
2003-12-14, 23:00
* Robert Moser II <rlmoser (AT) earthlink (DOT) net> shaped the electrons to say...

> I've been hacking away at my Moser skin and incorporated a little
> javascript, which didn't work at first. The reason was of course all
> the {}s and []s in the code. So after going through the code and
> replacing everything with &lbrc;&rbrc; and &lsqb;&rsqb; I had a thought,
> wouldn't it be nice if I had a template directive which would just
> skip all this crap?

[snip template requests]

I think I may have brought this up a while ago, and yes it's a lot of
work (and I'd volunteer if I had any free time), but I think that
moving to a standarized Perl/CPAN templating system would benefit the
project greatly.

Template Toolkit - http://www.template-toolkit.org/ is my prefered
solution, and already has a syntax very like what the SlimServer
already has. I'm not wanting to get into template system wars here.

In my professional opinion, TT is the cleanest, and most extensible
solution out there, and is implemented in pure perl (there is a XS
Stash component that can be used for extra speed, but it's optional)

I've used it in a number of other projects, you can see some examples at:

http://electricrain.com/cvs/jukebox/
(started a conversion of netjuke to modperl)

http://electricrain.com/daniel/software/invites/
http://electricrain.com/cvs/invites/lib/ElectricRain/Invites/Control/
http://electricrain.com/cvs/invites/templates/rotk/

Other information can be found at:

http://perl.apache.org/docs/tutorials/tmpl/comparison/comparison.html

Some of these are Apache/mod_perl specific, some aren't, like TT.

One very nice feature of TT is it's ability to deal with objects & methods such as:

if ($foo) {
$obj->method();
}

turns into:

[% IF foo %]
[% obj.method %]
[% END %]

or inlined:

[% IF foo; obj.method; END %]

Ok, that's my slight digression. Now back to the work that lets me pay rent. :/

-D
--
Cynicism is what passes for insight among the mediocre.

dean
2003-12-15, 13:25
I think a [LITERAL] is a great solution.

-dean

On Dec 14, 2003, at 6:17 PM, Robert Moser II wrote:

> I've been hacking away at my Moser skin and incorporated a little
> javascript, which didn't work at first. The reason was of course all
> the {}s and []s in the code. So after going through the code and
> replacing everything with &lbrc;&rbrc; and &lsqb;&rsqb; I had a
> thought, wouldn't it be nice if I had a template directive which
> would just skip all this crap?
>
> So, what would everyone think of another directive for templates:
> [NOEVAL] (or [CODE], or [LITERAL], or [WHATEVER]). Anything contained
> within this directive would be left alone by all the other processing
> steps.
>
> Of course, as I write this I got to thinking about how exactly such a
> directive would work, and came to the conclusion that it would be very
> hard to do. The closest I could figure would be to go through the
> section of text enclosed by the [NOEVAL] directive and replace the {}s
> and []s with their & versions. Then when filltemplate got around to
> the end, it would switch them back.
>
> Of course that method has problems if you actually want to have the &
> versions of {}[] in the [NOEVAL]'d text.
>
> Comments anyone? For example: "Stop being such a baby and just do the
> replacements yourself!"
>

kdf
2003-12-15, 13:43
Truthfully, I'm pretty used to using &lbrc; and &rbrc; at this point. I forget
now and again, but I'm used to the errors it causes and I dont waste time
debugging beyond that.

[LITERAL](or other) would be nice, but I think it is also important to be able
to still use the server variables as they are. Backward compatibility is huge,
so my ideal solution would be out: change variables to be more unique, perhaps
more like Dan suggested {%param%}. the {% combination is less likely to come up
in normal use. Thsu { alone would still work. A translation utility could take
care of the skins.

However, to maintain backward compatibility, perhaps the [LITERAL] tag can
define the bounds of literal inpterpretation, where { translates to &lbrc; and
{& translates to { (or even \{ to {. Likewise for },[ and ]. Maybe this way,
the other variables and [] tags will still function within the literal block

-kdf

Quoting dean blackketter <dean (AT) slimdevices (DOT) com>:

>
> I think a [LITERAL] is a great solution.
>
> -dean
>
> On Dec 14, 2003, at 6:17 PM, Robert Moser II wrote:
>
> > I've been hacking away at my Moser skin and incorporated a little
> > javascript, which didn't work at first. The reason was of course all
> > the {}s and []s in the code. So after going through the code and
> > replacing everything with &lbrc;&rbrc; and &lsqb;&rsqb; I had a
> > thought, wouldn't it be nice if I had a template directive which
> > would just skip all this crap?
> >
> > So, what would everyone think of another directive for templates:
> > [NOEVAL] (or [CODE], or [LITERAL], or [WHATEVER]). Anything contained
> > within this directive would be left alone by all the other processing
> > steps.
> >
> > Of course, as I write this I got to thinking about how exactly such a
> > directive would work, and came to the conclusion that it would be very
> > hard to do. The closest I could figure would be to go through the
> > section of text enclosed by the [NOEVAL] directive and replace the {}s
> > and []s with their & versions. Then when filltemplate got around to
> > the end, it would switch them back.
> >
> > Of course that method has problems if you actually want to have the &
> > versions of {}[] in the [NOEVAL]'d text.
> >
> > Comments anyone? For example: "Stop being such a baby and just do the
> > replacements yourself!"
> >

dean
2003-12-15, 13:45
I have no problem with this at all. We'll need to move over all the
existing skins...

Volunteers?

On Dec 14, 2003, at 10:00 PM, Dan Sully wrote:

> * Robert Moser II <rlmoser (AT) earthlink (DOT) net> shaped the electrons to
> say...
>
>> I've been hacking away at my Moser skin and incorporated a little
>> javascript, which didn't work at first. The reason was of course all
>> the {}s and []s in the code. So after going through the code and
>> replacing everything with &lbrc;&rbrc; and &lsqb;&rsqb; I had a
>> thought,
>> wouldn't it be nice if I had a template directive which would just
>> skip all this crap?
>
> [snip template requests]
>
> I think I may have brought this up a while ago, and yes it's a lot of
> work (and I'd volunteer if I had any free time), but I think that
> moving to a standarized Perl/CPAN templating system would benefit the
> project greatly.
>
> Template Toolkit - http://www.template-toolkit.org/ is my prefered
> solution, and already has a syntax very like what the SlimServer
> already has. I'm not wanting to get into template system wars here.
>
> In my professional opinion, TT is the cleanest, and most extensible
> solution out there, and is implemented in pure perl (there is a XS
> Stash component that can be used for extra speed, but it's optional)
>
> I've used it in a number of other projects, you can see some examples
> at:
>
> http://electricrain.com/cvs/jukebox/
> (started a conversion of netjuke to modperl)
>
> http://electricrain.com/daniel/software/invites/
>
> http://electricrain.com/cvs/invites/lib/ElectricRain/Invites/Control/
> http://electricrain.com/cvs/invites/templates/rotk/
>
> Other information can be found at:
>
> http://perl.apache.org/docs/tutorials/tmpl/comparison/comparison.html
>
> Some of these are Apache/mod_perl specific, some aren't, like
> TT.
>
> One very nice feature of TT is it's ability to deal with objects &
> methods such as:
>
> if ($foo) {
> $obj->method();
> }
>
> turns into:
>
> [% IF foo %]
> [% obj.method %]
> [% END %]
>
> or inlined:
>
> [% IF foo; obj.method; END %]
>
> Ok, that's my slight digression. Now back to the work that lets me pay
> rent. :/
>
> -D
> --
> Cynicism is what passes for insight among the mediocre.
>

Robert Moser II
2003-12-15, 22:54
> On Dec 14, 2003, at 10:00 PM, Dan Sully wrote:
>> Template Toolkit - http://www.template-toolkit.org/ is my prefered
>> solution, and already has a syntax very like what the SlimServer
>> already has. I'm not wanting to get into template system wars here.

to which dean blackketter blurted out:

> I have no problem with this at all. We'll need to move over all the
> existing skins...
>
> Volunteers?

I've been looking at it, and it seems very powerful.
For minimal disturbance we should probably try to bend it into
a drop-in replacement for our home-brew template system.

Once we've had more of a chance to explore the possibilities, we could
rework the whole HTTP interface to fully leverage this tool. Off hand,
I'm thinking of making some custom Slim specific Template::Plugins which
would expose all the information to the templates.

Something like:
[% USE Library %]
<table>
[% FOREACH genre = Library.genres %]
<tr><td><a href="browseid3.html?song=&artist=&album=&genre=
[% genre.name %]&player=[% player.id %]">[% genre.name %]</a><td>
<td><a href="status.html?p0=playlist&p1=addalbum&p2=
[% genre.name %]&p3=&p4=&player=[% player.id %]" target="status">
</td></tr>
[% END %]
</table>

naturally an actual template would be much more involved.

>> One very nice feature of TT is it's ability to deal with objects &
>> methods such as:
>>
>> if ($foo) {
>> $obj->method();
>> }
>>
>> turns into:
>>
>> [% IF foo %]
>> [% obj.method %]
>> [% END %]
>>
>> or inlined:
>>
>> [% IF foo; obj.method; END %]
>>

or using side-effect style:
[% obj.method IF foo %]