in reply to HTATR II: HTML table generation via DWIM tree rewriting

No offense, but i'd rather just learn a mini-language like Template:
package Simple::Class; use strict; use warnings; use Class::MethodMaker new_hash_init => 'new', get_set => [qw(age name weight)], ; sub load_data { return [ map { Simple::Class->new({ name => $_, age => int(rand(50))+20, weight => int(rand(150))+20, }) } qw(bob bill brian babette bobo bix) ]; } package main; use strict; use warnings; use Data::Dumper; use Template; my $template = Template->new; $template->process(\*DATA,{people => Simple::Class::load_data}) || die $template->error; __DATA__ [% colors = ['white','gray'] %] <table> <tr><th>name</th><th>age</th><th>weight</th></tr> [% FOREACH person = people %] [% PROCESS row person = person %] [% END %] </table> [% BLOCK row %] [% color = colors.shift %] <tr> <td bgcolor="[% color %]">[% person.name %]</td> <td bgcolor="[% color %]">[% person.age %]</td> <td bgcolor="[% color %]">[% person.weight %]</td> </tr> [% colors.push(color) %] [% END %]
I will agree that i like your template better when it comes to alternating colors. I probably should have handled the color picking inside the Perl code and not the template, but this is a trivial move. As it stands, i am really starting to like the Template mini-language.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Different Web Shops Need Different Tools
by princepawn (Parson) on Oct 30, 2003 at 15:36 UTC
    Whether you choose a mini-language over something like Seamstress just depends on who is available to do what. In the second and third companies I worked at, we had some top-flight graphic designers who were also very good at HTML, but they knew nothing about programming.

    They build full pages and handle all elements of consistent look and feel with their HTML tool, usually Dreamweaver, but sometimes Frontpage.

    Now for other shops, Mason and Template are perfect. I don't know what type of shop this might be. I would like to hear about such shops. I think the web designers at etoys got used to Template somehow.

      On my way to work this morning (a good 30 minute commute), i pondered your idea some more. I see what you are doing now and i think it's a pretty cool idea. I guess i had to bang out a reply before i could fully grasp what was going on. However, i wonder if you could utilize XML::Twig instead of rolling your own "rewiter"?

      UPDATE:
      Correction, you aren't rolling your own, you are using HTML::TreeBuilder instead. Sorry about that. :)

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
        i wonder if you could utilize XML::Twig instead of rolling your own "rewiter"?
        Twig is another one of those things I stared at and played with for awhile. I never quite understood his approach to grokking XML.

        TreeBuilder does parsing of rogue HTML quite well and the TreeBuilder API has most everything that I want for /(?i:ht|x)ml/

        DBSchema::Sample

Re: Re: HTATR II: HTML table generation via DWIM tree rewriting
by cbraga (Pilgrim) on Oct 30, 2003 at 16:54 UTC
    I suppose colours are best handled with CSS.

    ESC[78;89;13p ESC[110;121;13p

      I agree:
      [% classes = ['odd','even'] %] [% BLOCK row %] [% class = classes.shift %] <tr> <td class="[% class %]">[% person.name %]</td> <td class="[% class %]">[% person.age %]</td> <td class="[% class %]">[% person.weight %]</td> </tr> [% classes.push(class) %] [% END %]
      But you, the programmer, still have to manage which class to use for which row.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)