Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: HTML::Seamstress - the Outsider

by Rhandom (Curate)
on Feb 25, 2008 at 19:38 UTC ( [id://670103]=note: print w/replies, xml ) Need Help??


in reply to HTML::Seamstress - the Outsider
in thread RFC - Template::Empty

But again, you are using "your code" in the same vague sense that Rhandom used "code layer" -- both of you speak about it, but provide no examples, either in your replies or link to any document on the web, peer-reviewed or not.


I've given an example in an above reply. To be specific. The code layer is the perl layer. It is written in perl and is either modules or cgi script. The presentation layer is either a template file or a template string (yes template strings are useful too - so you can put your template in a database for instance). The code layer picks which template to display and gathers data that the presentation layer may need. But then it is up to the presentation layer to lay it out.

All of the in house HTML designers I have worked with at any of my jobs have wanted to have the flexibility to manipulate the data so that they page shape could change. I've enjoyed not having to change my perl whenever they've needed to reformat the page.

Just out of curiosity - what do you use when you need to send a templatized css file, or js file, or text email. To me, the XML/HTML DOM template systems seem to be heavy handed at forcing you to have well formed HTML. HTML is just a subset of what you need to deal with in web development. Do you use multiple template systems - or worse do you try to force css/js/email into the same slot as HTML? I've seen people do this and the templates are usually quite ugly. XML is usually the wrong hammer.

my @a=qw(random brilliant braindead); print $a[rand(@a)];

Replies are listed 'Best First'.
Re^2: HTML::Seamstress - the Outsider
by metaperl (Curate) on Feb 25, 2008 at 20:48 UTC
    I've given an example in an above reply. To be specific. The code layer is the perl layer. It is written in perl and is either modules or cgi script. The presentation layer is either a template file or a template string (yes template strings are useful too - so you can put your template in a database for instance). The code layer picks which template to display and gathers data that the presentation layer may need. But then it is up to the presentation layer to lay it out.
    What you call a "code layer" sound like a dispatch mechanism... analogous to the controller if we were doing a webapp... but remember dynamic html generation doesnt need cgi/mod_perl at all. So yes, that would be in Perl. And the presentation layer for me, is also 100% pure Perl. And the "template" is a lifeless HTML file, preferably containing some div, class and id tags but nothing more.

    Do you see anything suspect with the code I posted?

    I have beheld the tarball of 22.1 on ftp.gnu.org with my own eyes. How can you say that there is no God in the Church of Emacs? -- David Kastrup
    [tag://html-seamstress]
    Enforce strict model-view separation in template engines via HTML::Seamstress The car is in the cdr, not the cdr in the car
      Do you see anything suspect with the code I posted?
      Absolutely not! Your code is great. Your separation of model/view/controller is textbook quality. Academically, it is sound.

      It just doesn't look like fun. But that is me. It might be to you. I just like that if I can make the "lifeless HTML file" just a little less lifeless, it can greatly simplify my coding load. I can generate data, pass it along and let it be consumed in optimum fashion. But that is "optimal" to me. EMWV (everyone's mileage will vary).

      my @a=qw(random brilliant braindead); print $a[rand(@a)];
Seamstress uses oop to specialize output format
by metaperl (Curate) on Feb 26, 2008 at 18:12 UTC
    Just out of curiosity - what do you use when you need to send a templatized css file, or js file, or text email.
    Well, that's a good question. I've never had to do those things. Part of your extra extra credit was to create a text version. And here it is:
    package View::bullet::text; use base qw(View::bullet); use Data::Dumper; use HTML::FormatText; my $file = 'html/bullet.html'; sub new { __PACKAGE__->new_from_file($file); } sub render { my $tree = shift; my $model = shift; my $tree = $tree->SUPER::render($model); my $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin = +> 80); my $text = $formatter->format($tree); return $text; } 1;
    I have beheld the tarball of 22.1 on ftp.gnu.org with my own eyes. How can you say that there is no God in the Church of Emacs? -- David Kastrup
    [tag://html,templating,seamstress,oop]
    Enforce strict model-view separation in template engines via HTML::Seamstress The car is in the cdr, not the cdr in the car

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://670103]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-25 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found