Re: RFC: Template::YetAnother
I've said it before... :) http://mathforum.org/epigone/modperl/zhixswahar/v04210105b76eecf6c2be@%5b192.168.1.3%5d Rob On Sat, Nov 16, 2002 at 10:33:44PM +0100, Thomas Klausner wrote: Hi! On Sat, Nov 16, 2002 at 03:31:39PM -0500, Perrin Harkins wrote: I also posted this on perlmonks: http://www.perlmonks.org/index.pl?node_id=213300 Ovid on Perlmonks already said some of the things I would have said about needing a presentation language. For a templating system to be useful, it has to be able to deal with loops and conditionals. Your system pushes those into the Perl code, splitting the presentation control into multiple places. This fails one of my major goals: the template coders should be able to change the presentation without help from a Perl coder. What if they decide they don't want to loop through the links, but rather just print a message saying there are some? What if they only want to show the first two? What if they want to display a list with commas between the elements where they didn't use a separator before? A mature templating system can handle all of these issues without changing the main Perl module code. That's a very good point I didn't really think about. I was thinking of templates as DUMB frontends that should just display data. Period. Thinking of them as tools that handle presentation logic (as Ovid pointed out) seems to make more sense. It does pay of to write RFCs before starting to code... Because IMO, the main reason for using templates is to seperate code from markup. It sounds to me like you want one of the HTML attribute ones, like Petal or HTML::Seamstress. What was wrong with those? One problem I see with HTML::Seamstress is that it uses the HTML attributes 'class' and 'id' for templating info. But those attributes are used by CSS and JavaScript and might conflict somehow. I do not know if you can change the behaviour of HTML::Seamstress to use other attributes, though. But this stopped my from looking further. And I didn't look at Petal. For now. There is one module, CGI::FastTemplate, that does seperate code from markup completly. But the way different templates are strung together seems rather comlicated to me. It's not complicated, but it is somewhat confusing the first time you look at it. I don't find your approach much easier though. Well, I found mine easier :-) (But I guess this is the reason for the Template Flood on CPAN - everbody finds his own solution easier...) Isn't your fill method just doing a sort of multi-level join here? All of the data is passed in already, so there is no reason to delay evaluation of the templates. The main reason for doing this was to simplify testing. I planned to just test the plain data structures, that should be free of HTML at this time (before the fill). This (testing) was in fact the reason I started thinking about this proposal in the first place. More importantly, your use of AUTOLOAD to treat method calls as file names looks neat, but is not a good approach. It's limiting (all templates in one directory!) and has potential security issues with namespace clashes. These are all just the same method call with a single argument changed, so why not write them that way? I planned to handle those namespace and filename issues. .. force you to use them. They are flexible modules. I think you should look at them more closely before you go off on your own. That's what I'll do. Thanks for the excellent feedback. -- #!/usr/bin/perlhttp://domm.zsi.at for(ref(bless[],just'another'perl'hacker)){s-:+-$-gprint$_.$/}
Re: RFC: Template::YetAnother
Thomas Klausner [EMAIL PROTECTED] writes: Yes, this is a RFC for Yet Another Templating System. I know that there are a lot of those around. But this own might be different/interesting (at least I think/hope so...) (...) One note: while talking about templating systems for generating HTML, it can be inspiring to take a look at the Zope Page Templates (yes, I know, this is the python/zope world, not perl...). They found the nice idea of injecting loops/ifs etc into HTML in the way which does not spoil HTML markup. Their introduction is on http://www.zope.org/Documentation/Articles/ZPT1 and reference is in http://www.zope.org/Documentation/Books/ZopeBook/current/AppendixC.stx Here are some examples (copied from the introduction) title tal:content=here/titlePage Title/title The URL is span tal:replace=request/URLURL/span. table border=1 width=100% tr th#/ththId/ththMeta-Type/ththTitle/th /tr tr tal:repeat=item container/objectValues td tal:content=repeat/item/number#/td td tal:content=item/idId/td td tal:content=item/meta_typeMeta-Type/td td tal:content=item/titleTitle/td /tr /table -- ( Marcin Kasperski | Osoba jest omegalizacj ewolucji uniwersalnej na ) ( http://www.mk.w.pl | okrelonym odcinku etapowym (Teilhard de Chardin) ) () ( Wygeneruj dokumentacj: http://www.mk.w.pl/narzedzia/narzedzia_gendoc )
Re: RFC: Template::YetAnother
Hi! On Sat, Nov 16, 2002 at 10:43:44AM +0100, Marcin Kasperski wrote: One note: while talking about templating systems for generating HTML, it can be inspiring to take a look at the Zope Page Templates (yes, I know, this is the python/zope world, not perl...). They found the nice idea of injecting loops/ifs etc into HTML in the way which does not spoil HTML markup. There is a simmilar Perl implementation of this called HTML_Tree http://homepage.mac.com/pauljlucas/software/html_tree/ A module based on HTML_Tree is on CPAN under the name of HTML-Seamstress: http://search.cpan.org/author/TBONE/HTML-Seamstress-1.17/Seamstress.pm -- #!/usr/bin/perlhttp://domm.zsi.at for(ref(bless[],just'another'perl'hacker)){s-:+-$-gprint$_.$/}
Re: RFC: Template::YetAnother
Hi! On Fri, Nov 15, 2002 at 07:05:49PM -0800, Josh Chamas wrote: Don't do it. If you want a stripped down version of .. evolution of these things. The perl template user community is already fractured enough, I expected that canonical answer to all Template Proposals :-) better to hop onto a project, hack it to your satisfaction ( with the blessing of the maintainers ) to get the configs/subclasses you need for your requirements. I will take a closer look if my ideas could be implemented by subclassing/extending Template Toolkit or CGI::FastTemplate. But do you think that the concept sounds reasonable in the first place? -- #!/usr/bin/perlhttp://domm.zsi.at for(ref(bless[],just'another'perl'hacker)){s-:+-$-gprint$_.$/}
Re: RFC: Template::YetAnother
Thomas Klausner wrote: Hi! On Sat, Nov 16, 2002 at 10:43:44AM +0100, Marcin Kasperski wrote: One note: while talking about templating systems for generating HTML, it can be inspiring to take a look at the Zope Page Templates (yes, I know, this is the python/zope world, not perl...). They found the nice idea of injecting loops/ifs etc into HTML in the way which does not spoil HTML markup. There is a simmilar Perl implementation of this called HTML_Tree http://homepage.mac.com/pauljlucas/software/html_tree/ A module based on HTML_Tree is on CPAN under the name of HTML-Seamstress: http://search.cpan.org/author/TBONE/HTML-Seamstress-1.17/Seamstress.pm There is also an implementation that copies the Zope style pretty closely called Petal: http://search.cpan.org/author/JHIVER/Petal-0.77/lib/Petal.pm - Perrin
Re: RFC: Template::YetAnother
Thomas Klausner wrote: Yes, this is a RFC for Yet Another Templating System. I know that there are a lot of those around. But this own might be different/interesting (at least I think/hope so...) I also posted this on perlmonks: http://www.perlmonks.org/index.pl?node_id=213300 Ovid on Perlmonks already said some of the things I would have said about needing a presentation language. For a templating system to be useful, it has to be able to deal with loops and conditionals. Your system pushes those into the Perl code, splitting the presentation control into multiple places. This fails one of my major goals: the template coders should be able to change the presentation without help from a Perl coder. What if they decide they don't want to loop through the links, but rather just print a message saying there are some? What if they only want to show the first two? What if they want to display a list with commas between the elements where they didn't use a separator before? A mature templating system can handle all of these issues without changing the main Perl module code. Because IMO, the main reason for using templates is to seperate code from markup. It sounds to me like you want one of the HTML attribute ones, like Petal or HTML::Seamstress. What was wrong with those? There is one module, CGI::FastTemplate, that does seperate code from markup completly. But the way different templates are strung together seems rather comlicated to me. It's not complicated, but it is somewhat confusing the first time you look at it. I don't find your approach much easier though. # generate a new template handler my $th=Template::YetAnother-new ({ namespace='acme', template_dir='/projects/acme/templates/', }); # build up a data structure $data={ title=$th-title('this is the title'), breadcrumb=[ $th-link({url='/index.html',text='Home'}), $th-separator_breadcrumb, $th-link({url='/acme/index.html',text='Acme'}), $th-separator_breadcrumb, $th-link({url='/acme/bleach.html',text='Bleach'}), ], content=[ $th-element({heading='SYNOPSIS',value='blabla'}), $th-element({heading='DESCRIPTION',value='foo bar'}), ], lastmod=scalar localtime, }; # fill template print print $th-fill({data=$data}); Isn't your fill method just doing a sort of multi-level join here? All of the data is passed in already, so there is no reason to delay evaluation of the templates. More importantly, your use of AUTOLOAD to treat method calls as file names looks neat, but is not a good approach. It's limiting (all templates in one directory!) and has potential security issues with namespace clashes. These are all just the same method call with a single argument changed, so why not write them that way? Here's the same thing written with Template Toolkit. You could use HTML::Template, CGI::FastTemplate, Text::Template, etc. here with minor changes: my $th = Template-new({INCLUDE_PATH = '/projects/acme/templates/'); $th-process-('title.tmpl', {title = 'this is the title'}); $th-process-('link.tmpl', {url = '/index.html', text = 'Home'}); $th-process-('separator.tmpl'); $th-process-('link.tmpl', {url = '/index.html', text = 'Home'}); $th-process-('separator.tmpl'); $th-process-('link.tmpl', {url = '/acme/index.html', text = 'Acme'}); $th-process-('separator.tmpl'); ... And so on. Text::Template allows Perl code to be put in the template, and HTML::Template/TT allow loops and conditionals, but no one is going to force you to use them. They are flexible modules. I think you should look at them more closely before you go off on your own. - Perrin
Re: RFC: Template::YetAnother
Hi! On Sat, Nov 16, 2002 at 03:31:39PM -0500, Perrin Harkins wrote: I also posted this on perlmonks: http://www.perlmonks.org/index.pl?node_id=213300 Ovid on Perlmonks already said some of the things I would have said about needing a presentation language. For a templating system to be useful, it has to be able to deal with loops and conditionals. Your system pushes those into the Perl code, splitting the presentation control into multiple places. This fails one of my major goals: the template coders should be able to change the presentation without help from a Perl coder. What if they decide they don't want to loop through the links, but rather just print a message saying there are some? What if they only want to show the first two? What if they want to display a list with commas between the elements where they didn't use a separator before? A mature templating system can handle all of these issues without changing the main Perl module code. That's a very good point I didn't really think about. I was thinking of templates as DUMB frontends that should just display data. Period. Thinking of them as tools that handle presentation logic (as Ovid pointed out) seems to make more sense. It does pay of to write RFCs before starting to code... Because IMO, the main reason for using templates is to seperate code from markup. It sounds to me like you want one of the HTML attribute ones, like Petal or HTML::Seamstress. What was wrong with those? One problem I see with HTML::Seamstress is that it uses the HTML attributes 'class' and 'id' for templating info. But those attributes are used by CSS and JavaScript and might conflict somehow. I do not know if you can change the behaviour of HTML::Seamstress to use other attributes, though. But this stopped my from looking further. And I didn't look at Petal. For now. There is one module, CGI::FastTemplate, that does seperate code from markup completly. But the way different templates are strung together seems rather comlicated to me. It's not complicated, but it is somewhat confusing the first time you look at it. I don't find your approach much easier though. Well, I found mine easier :-) (But I guess this is the reason for the Template Flood on CPAN - everbody finds his own solution easier...) Isn't your fill method just doing a sort of multi-level join here? All of the data is passed in already, so there is no reason to delay evaluation of the templates. The main reason for doing this was to simplify testing. I planned to just test the plain data structures, that should be free of HTML at this time (before the fill). This (testing) was in fact the reason I started thinking about this proposal in the first place. More importantly, your use of AUTOLOAD to treat method calls as file names looks neat, but is not a good approach. It's limiting (all templates in one directory!) and has potential security issues with namespace clashes. These are all just the same method call with a single argument changed, so why not write them that way? I planned to handle those namespace and filename issues. .. force you to use them. They are flexible modules. I think you should look at them more closely before you go off on your own. That's what I'll do. Thanks for the excellent feedback. -- #!/usr/bin/perlhttp://domm.zsi.at for(ref(bless[],just'another'perl'hacker)){s-:+-$-gprint$_.$/}
Re: RFC: Template::YetAnother
Thomas Klausner wrote: Hi! Yes, this is a RFC for Yet Another Templating System. I know that there are a lot of those around. But this own might be different/interesting (at least I think/hope so...) I also posted this on perlmonks: http://www.perlmonks.org/index.pl?node_id=213300 So, here it is, in POD format: Don't do it. If you want a stripped down version of an existing templatting language, then that's great. Work with the authors of exising frameworks like Template Toolkit or HTML::Template that *were designed* as pure template frameworks ( as opposed to the app frameworks like Embperl, ASP, AxKit, Mason) I'm sure you can get the authors to accept patches to disable features that you don't want, you might even be able to create a subclass of such a template module that sets these for the end user, so if they just use Template:JustVarsPlease, and Template::JustVarsPlease is a subclass of Template or HTML::Template, then you have your solution. Those template solutions that are too much for you got that way because their users wanted needed more. That is the natural evolution of these things. The perl template user community is already fractured enough, better to hop onto a project, hack it to your satisfaction ( with the blessing of the maintainers ) to get the configs/subclasses you need for your requirements. That's what I would do anyway. :) Regards, Josh Josh Chamas, Founder phone:925-552-0128 Chamas Enterprises Inc.http://www.chamas.com NodeWorks Link Checkinghttp://www.nodeworks.com