Re: is there a templating system that....
On 8/15/05, Matisse Enzer <[EMAIL PROTECTED]> wrote: > Just a data point: > I'm the maintainer of Text::TagTemplate and will soon release a version > that lets you set the regexes that define the start and end of a tag. FWIW, I have just uploaded TipJar::Template::fill to CPAN. It is an abstraction around the s/// operator, that creates fill subroutines in the caller's package, that substitute data into templates. It defaults to using [square_brackets] but takes "regex" as an argument, so it could be configured to read simple petal templates or templates from any other system as long as variable substitution is all you want to do. The hash from which the data is read to substitute in is configurable with a "hashref" argument and defaults to a hash with the same name as the subroutine, which defaults to "fill." Please direct feedback on it to me off-list and I will modify the documentation accordingly, for instace including a list of regexes to make it handle simple replacement templates from all the systems Perrin Harkins lists in his comparison article. -- David L Nicol The original republican: http://cronos.advenge.com/pc/Honest_Abe
Re: is there a templating system that....
%Template_vars = qw ( misattribution microsoft correction macromedia mailinglist modperl@perl.apache.org product dreamweaver ); $Template_vars{retractor} = 'David L. Nicol'; $TEMPLATE = <
Re: is there a templating system that....
On 15 Aug 2005, at 23:02, David Nicol wrote: (getting tired of this thread) It's also now firmly off topic of the mod_perl list! Dave // Having spent most of today explaining the principle of doing \\ the least possible computation at run time...
Re: is there a templating system that....
On Mon, 2005-08-15 at 17:02 -0500, David Nicol wrote: > How do you get, for instance, netscape composer, to generate a "span" tag? I don't think people use Netscape Composer for real websites. I sometimes use it for writing documentation, but that's about it. > Do the industrial GUI HTML tools all provide span tags? I think DreamWeaver does. It's not a MSFT tool though. Most of the good HTML coders will use either DreamWeaver or a text editor. - Perrin
Re: is there a templating system that....
On 8/15/05, Perrin Harkins <[EMAIL PROTECTED]> wrote: > On Mon, 2005-08-15 at 15:48 -0500, David Nicol wrote: >> Tell the designer to make the variable substitution names red, >> and specify in your template system configuration > > target_regex => qr{\s*([^<]+?)\s*}; > You won't get far with that before you need to use a variable in a place > where the font tags would violate XHTML. Petal is a much more complete > solution. > > - Perrin How do you get, for instance, netscape composer, to generate a "span" tag? Do the industrial GUI HTML tools all provide span tags? I'm totally ignorant here, as I do all my HTML editing in vi, but most of the people I know who claim to be HTML designers use some microsoft tool that gets taught in HTML design classes in vo-tech. Electroshock or something like that. Dreamweaver, that's it. There was a little video of Dreamweaver, the song, in a "hits of the 70s" advertisement on television last night. (getting tired of this thread) -- David L Nicol Do you really not know the difference between underscore and dash or are you just being difficult?
Re: is there a templating system that....
On Mon, 2005-08-15 at 17:18 -0400, Jonathan Vanasco wrote: > Yeah, I never mentioned that... although it was mostly because I > assumed that most templating languages would provide for that. It's actually an unusual thing to want. Valid XHTML templates are not guaranteed to look correct in a browser or to generate valid XHTML output. (That would be XSLT.) Also, people who want to support a wide variety of browsers can't use strict XHTML, according to my local web standards expert. - Perrin
Re: is there a templating system that....
On Aug 15, 2005, at 4:45 PM, Perrin Harkins wrote: Since Petal (and HTML_Tree, but that's a dead project) are the only ones that do this at all, I'd say most people are doing just fine without templates that are valid XML. I don't remember you mentioning this requirement earlier. If you had, I would have told you Petal was your only option. Yeah, I never mentioned that... although it was mostly because I assumed that most templating languages would provide for that. I think looking at everyone's suggestions and talking with everyone pushed me more towards Petal too. HTML::Template does provide for it in a roundabout way - using comments, and the new version of Text::Tagtemplate handles it well. Neither are 'viewable' templates. On Aug 15, 2005, at 4:48 PM, David Nicol wrote: By having validatable templates, he can reduce his interactions with the designers. That's pretty much dead on. Ironically, right now I'll be doing the bulk of the html design and I wish I could reduce my own interactions with myself, but I don't know if that's possible. Looking into the future I want to be able to compartmentalize responsibility. And blame. On Aug 15, 2005, at 4:14 PM, David Nicol wrote: I'm seriously considering publishing a Template::Substitution::KISS or I'm a firm believer in KISS
Re: is there a templating system that....
On Mon, 2005-08-15 at 15:48 -0500, David Nicol wrote: > If the target regex was set to something like > > use hypothetical_substituting_template_system > template_vars_hashref => \(our %TemplateVars), > target_regex => qr{\s*([^<]+?)\s*}; > > for example, the designer would be able to specify template names in by > coloring the text red, without viewing any source code. You won't get far with that before you need to use a variable in a place where the font tags would violate XHTML. Petal is a much more complete solution. - Perrin
Re: is there a templating system that....
On 8/15/05, David Hodgkinson <[EMAIL PROTECTED]> wrote: > > HTML::Template got ruled out because the only way to get templates > > to render as xhtml valid is to use info as comments > > Huh? you want to validate templates? A template is just that. What > it renders to should be validated! By having validatable templates, he can reduce his interactions with the designers. If the target regex was set to something like use hypothetical_substituting_template_system template_vars_hashref => \(our %TemplateVars), target_regex => qr{\s*([^<]+?)\s*}; for example, the designer would be able to specify template names in by coloring the text red, without viewing any source code. -- David L Nicol Do you really not know the difference between underscore and dash or are you just being difficult?
Re: is there a templating system that....
On Mon, 2005-08-15 at 16:39 -0400, Jonathan Vanasco wrote: > What the template renders to better damn well be valid -- but if I > use a templating system that allows for invalid templates, then it > becomes my job to restructure them to be valid in addition to doing > the logic and substitution. Thats a mess. Since Petal (and HTML_Tree, but that's a dead project) are the only ones that do this at all, I'd say most people are doing just fine without templates that are valid XML. I don't remember you mentioning this requirement earlier. If you had, I would have told you Petal was your only option. - Perrin
Re: is there a templating system that....
Yep. Validate templates. What the template renders to better damn well be valid -- but if I use a templating system that allows for invalid templates, then it becomes my job to restructure them to be valid in addition to doing the logic and substitution. Thats a mess. I want designers that I work with to make valid templates that I just swap stuff in and out of. I run everything that I get through xmllint, and if its good I use it, if not, they fix it -- not me. On Aug 15, 2005, at 4:36 PM, David Hodgkinson wrote: Huh? you want to validate templates? A template is just that. What it renders to should be validated!
Re: is there a templating system that....
On 15 Aug 2005, at 06:06, jonathan vanasco wrote: HTML::Template got ruled out because the only way to get templates to render as xhtml valid is to use info as comments Huh? you want to validate templates? A template is just that. What it renders to should be validated!
Re: is there a templating system that....
On Mon, 15 Aug 2005, David Nicol wrote: > > I'm seriously considering publishing a Template::Substitution::KISS or > something like that in a futile attempt to piss higher than Uri Guttman. Just a data point: I'm the maintainer of Text::TagTemplate and will soon release a version that lets you set the regexes that define the start and end of a tag. I'm happy to send an alpha version to anyone who asks. -M
Re: is there a templating system that....
On 8/15/05, jonathan vanasco <[EMAIL PROTECTED]> wrote: > Petal templates do look nice, because > Hola, Mundo! > is valid xhtml AND lets you have mockup text that is then replaced > > Unfortunately, petal supports all the smart features of tal like if/ > loops (stuff I didn't want in there), but its ok. i'll deal. Hmm. So if you were doing substituting with $template_copy =~ s {} {$template_var_hashref->{$1}}g; would that do everything you need? I'm seriously considering publishing a Template::Substitution::KISS or something like that in a futile attempt to piss higher than Uri Guttman. With the substitution target regex configurable, it could be used against arbitrary variable identification syntaces. -- David L Nicol Do you really not know the difference between underscore and dash or are you just being difficult?
Re: is there a templating system that....
I messed around with Templating systems all weekend, and picked a winner Petal I wanted to go as simple as possible, and with the help of the list narrowed it down to: HTML::Tree HTML::Template Text::TagTemplate Petal HTML tree did exactly what I wanted it to, except I remembered as much as I know tree structures, working with Nevow's Stan formatting I learned to hate them HTML::Template got ruled out because the only way to get templates to render as xhtml valid is to use info as comments ie: isn't valid, but works is valid, but doesn't work is valid and works, but looks cluttered to me Text::TagTemplate almost worked right: <#TAG NAME=VALUE> works, isn't valid <#TAG NAME=VALUE/> doesn't work, is valid <#TAG NAME=VALUE /> works, is valid (notice the space before the close of the tag) I didn't want to worry about remembering the space. The author sent me a copy of the next version that he will release which, with a new feature, will support what I want... ... But then i realized that the templates work and are valid, but don't look nice Petal templates do look nice, because Hola, Mundo! is valid xhtml AND lets you have mockup text that is then replaced Unfortunately, petal supports all the smart features of tal like if/ loops (stuff I didn't want in there), but its ok. i'll deal. Thanks to all.
Re: is there a templating system that....
Jonathan Vanasco wrote: > can someone suggest to me a templating [...] You should read Perrin's "Choosing a Templating System", http://perl.apache.org/docs/tutorials/tmpl/comparison/comparison.html /Kim
Re: is there a templating system that....
On 8/12/05, Jonathan Vanasco <[EMAIL PROTECTED]> wrote: > working across the spectrum from design only to code only and in > between , I realized what works and is efficient for me and the people > I collaborate with -- and that is them making little pretty things and > not being able to have any control whatsoever of the logic in there. The documentation for PHP's "Smarty" templating system includes some very nice prose discussing the justification and rationalization for templating systems in general. Why would PHP need a templating system when PHP is itself a templating system? At first it seems like the starbucks in the restroom of the starbucks -- but the practice of PHP grew to the point where separating logic and presentation became required.
Re: is there a templating system that....
'all I want' is pretty much the idea. Really a lowest-common-denominator type thing. I started out as a designer, then moved onto 'design tech' mediating the arguments between the cto and the creative director. two years ago my cto went on sabbatical to work on python and twistedmatrix. i had to take up all the backend server slack and became defacto code-bitch. working across the spectrum from design only to code only and in between , I realized what works and is efficient for me and the people I collaborate with -- and that is them making little pretty things and not being able to have any control whatsoever of the logic in there. Because when they can use it, they try to. And they get ideas. And that only creates problems for me to fix. The system/framework that I am set up is VERY specific to a workflow and process that I (unfortunately) have to interact with. I've tried too many languages and frameworks to list - none of the fit just right with our process. So I'm building my own - but instead of building something giant and wonderful from scratch as many people do, I'm trying to subclass and utilize as many existing things as possible, and just tie in things that work well for specific functions into a framework that works specifically for my needs. ( Which uses modules to break a site into two structured hierarchies that mirror one another - one for code, the other for templates. The main site object uses a dispatch table to invoke the necessary elements to create the requested page beneath it, and each object traverse upwards to get templating information for their object type if none is specifically provided. Its nothing new, but its all tailored to a specific work ethic / work style that I've been forced to get used to. If I had 4 people under me, or 1/5 the work to do, I would LOVE to do the smart thing / right thing -- and I would have used mason, or template toolkit -- or built something more intelligent. But I don't, and believe it or not, this is saving me time. On Aug 12, 2005, at 5:42 PM, David Nicol wrote: On 8/12/05, Perrin Harkins <[EMAIL PROTECTED]> wrote: On Fri, 2005-08-12 at 15:45 -0500, David Nicol wrote: my $output = $TemplateCache{$template_name}; $output =~ s/\[(\w+)\]/$InsertableVariables{$1}/g; print $output; The second it gets more complex than that, stop and use one from CPAN. Agreed. But that seems to be all Vanasco wants. You can make your templates directory appear like a hash with DirDB, and call yourself done. DirDB is light on the memory as the templates get stored in the OS' file system cache, from which they are efficiently slurped as needed, and the unused ones don't take up any swap space.
Re: is there a templating system that....
> On 8/12/05, Perrin Harkins <[EMAIL PROTECTED]> wrote: > > On Fri, 2005-08-12 at 15:45 -0500, David Nicol wrote: > > > my $output = $TemplateCache{$template_name}; > > > $output =~ s/\[(\w+)\]/$InsertableVariables{$1}/g; > > > print $output; > > > > The second it gets more complex than that, stop and use one from CPAN. Uri Guttman posted something that might do the job here: http://london.pm.org/pipermail/london.pm/Week-of-Mon-20050808/032837.html d.
Re: is there a templating system that....
On 8/12/05, Perrin Harkins <[EMAIL PROTECTED]> wrote: > On Fri, 2005-08-12 at 15:45 -0500, David Nicol wrote: > > my $output = $TemplateCache{$template_name}; > > $output =~ s/\[(\w+)\]/$InsertableVariables{$1}/g; > > print $output; > > The second it gets more complex than that, stop and use one from CPAN. Agreed. But that seems to be all Vanasco wants. You can make your templates directory appear like a hash with DirDB, and call yourself done. DirDB is light on the memory as the templates get stored in the OS' file system cache, from which they are efficiently slurped as needed, and the unused ones don't take up any swap space.
Re: is there a templating system that....
On Aug 12, 2005, at 4:45 PM, David Nicol wrote: Just pick a naming convention and run what you get back from the designers through the substitution operator. I like square brackets around the variable names, since that convention has some history. my $output = $TemplateCache{$template_name}; $output =~ s/\[(\w+)\]/$InsertableVariables{$1}/g; print $output; If all you want is variable substitution, just do variable substitution. I have both of those right now. BUT I'll be working with a lot of user-submitted data. I can invalidate / rewrite user data that could mess up my lame templating/substitution scheme right now. But then I have to commit to not changing any of my templating schemes from this point forward. Let me rephrase: if i'm relying on regex, its possible that someone will enter in text that one of my regexs match. i can put in safeguards against that now, but then I pretty much lock myself into this scheme - something i don't want to do, because this is a quick hack to get a project up and running, and if things get bigger I would probably need a more robust/serious solution that my safeguards have created a nightmare to maintain. So... I thought of doing something like an HTML tree, as I could then treat templates based on nodes in the dom tree... On Aug 12, 2005, at 4:47 PM, Perrin Harkins wrote: SSI under mod_perl does everything that Text::TagTemplate does. I can't begin to explain what I have in place right now - and while I'm sure SSI in mod_perl would be a good solution to a similar problem, everything that I've read about it makes it seem wholly incompatible with the current status of the project. I think I would have to redo almost the entire project to handle things under SSI, and I would only have to write about 200lines to integrate Text::TagTempate or HTML::Tree
Re: is there a templating system that....
On Fri, 2005-08-12 at 15:45 -0500, David Nicol wrote: > my $output = $TemplateCache{$template_name}; > $output =~ s/\[(\w+)\]/$InsertableVariables{$1}/g; > print $output; The second it gets more complex than that, stop and use one from CPAN. > SSI sounds like PHP. PHP is a full-fledged programming language. SSI is a venerable system for doing simple variable substitutions and includes in web pages, and you already have it. With apache 2, you can use it as a filter after your perl handler. Here's an intro: http://www.onlamp.com/pub/a/apache/2005/07/07/apache_xssi.html - Perrin
Re: is there a templating system that....
On 8/12/05, Jonathan Vanasco <[EMAIL PROTECTED]> wrote: > I want all of my templates in the apache process - they're going to be > reused constantly and if they need to be changed i have no problem > doing a graceful restart. my $TemplateCache; BEGIN{ opendir TD, "./templates.d"; for(readdir TD){ -f "./templates.d/$_" or next; $TemplateCache{$_} = slurp "./templates.d/$_"; # there are several slurpers on cpan }; }; I appear to be well on the way to describing yet another templating engine :)
Re: is there a templating system that....
On Fri, 2005-08-12 at 16:45 -0400, Jonathan Vanasco wrote: > In terms of memory, I was thinking more along the lines of how much > memory the HTML::Template and Text::TagTemplate modules take up > themselves. > > I want all of my templates in the apache process - they're going to be > reused constantly and if they need to be changed i have no problem > doing a graceful restart. The templates will take up much more memory than the modules. > There's a 40k difference between the two .tar.gz distributions. I > don't know what that will turn into when run - i'm sure 80% of either > of those is POD documentation. A 20k difference on my current setup > should get me 2 more apache children though - which is a bit of a plus. That is not a good enough reason to choose one over the other, in my opinion. RAM is cheaper than your developer time. > I don't want to develop anything to handle this simple thing either... > but this is just one part of something more complex that I'm pretty > sure SSI will not work with. SSI under mod_perl does everything that Text::TagTemplate does. - Perrin
Re: is there a templating system that....
In terms of memory, I was thinking more along the lines of how much memory the HTML::Template and Text::TagTemplate modules take up themselves. I want all of my templates in the apache process - they're going to be reused constantly and if they need to be changed i have no problem doing a graceful restart. There's a 40k difference between the two .tar.gz distributions. I don't know what that will turn into when run - i'm sure 80% of either of those is POD documentation. A 20k difference on my current setup should get me 2 more apache children though - which is a bit of a plus. I don't want to develop anything to handle this simple thing either... but this is just one part of something more complex that I'm pretty sure SSI will not work with. Thanks for all of your pointers though - as always they're incredibly valuable. On Aug 12, 2005, at 4:16 PM, Perrin Harkins wrote: On Fri, 2005-08-12 at 16:07 -0400, Jonathan Vanasco wrote: This looks useful as well. I think i might bench HTML::Template and Text::TagTemplate against one another for memory usage. HTML::Template can store the parsed templates on disk outside of the apache process. Check the section on caching options. If/else and loops are already 'too much' -- I essentially just want variable substitution. I wouldn't want to try to develop anything without the ability to do includes, loops, and boolean IFs, but you can try. SSI really is a viable solution for this, and doesn't store anything in memory. - Perrin
Re: is there a templating system that....
On 8/12/05, Jonathan Vanasco <[EMAIL PROTECTED]> wrote: > > If/else and loops are already 'too much' -- I essentially just want > variable substitution. I want designers to be able to work on a page > and not need to know anything about the code/logic. Names go here, > dates go here, etc. I have a bunch of custom mod_perl stuff that > handles everything right now. I just want to split the code out of the > handler routines. Just pick a naming convention and run what you get back from the designers through the substitution operator. I like square brackets around the variable names, since that convention has some history. my $output = $TemplateCache{$template_name}; $output =~ s/\[(\w+)\]/$InsertableVariables{$1}/g; print $output; If all you want is variable substitution, just do variable substitution. If you trust your page designers, have them use dollar-signs instead of square brackets and things get even easier, with the insertables as perl variables in your scope: $output = eval << "EOE"; <<"__END_OF_TEMPLATE" $TemplateCache{$template_name} __END_OF_TEMPLATE EOE It is not possible to define an abstraction around these tools that isn't more trouble than its worth, which is why there is no "Really::Lightweight::Templating::Engine::That::Just::Does::Variable::Substitution" on CPAN, although it might be appropriate in Acme::. I have defined subroutines such as sub print_template($$){ my ($template, $hashref) = @_; ref $hashref or croak "usage: print_template($template, $hashref); $template =~ s/\[(\w+)\]/$hashref->{$1}/g; print $template; }; and used them repeatedly within perl-driven logic, to print table lines defined with a template, for instance. You have to parse the repeated parts out of what your page designer gives you somehow, but I expect you're going to have to massage your designer's output even if you use a templating engine with its own control flow. SSI sounds like PHP.
Re: is there a templating system that....
Jonathan Vanasco <[EMAIL PROTECTED]> writes: [...] > If/else and loops are already 'too much' -- I essentially just want > variable substitution. I want designers to be able to work on a page > and not need to know anything about the code/logic. Names go here, > dates go here, etc. I have a bunch of custom mod_perl stuff that > handles everything right now. I just want to split the code out of the > handler routines. I use CGI::FastTemplate, though my copy is by now so heavily modified as to be unrecognizable. That's about as simple as you can get. Scott.
Re: is there a templating system that....
On Fri, 2005-08-12 at 16:07 -0400, Jonathan Vanasco wrote: > This looks useful as well. I think i might bench HTML::Template and > Text::TagTemplate against one another for memory usage. HTML::Template can store the parsed templates on disk outside of the apache process. Check the section on caching options. > If/else and loops are already 'too much' -- I essentially just want > variable substitution. I wouldn't want to try to develop anything without the ability to do includes, loops, and boolean IFs, but you can try. SSI really is a viable solution for this, and doesn't store anything in memory. - Perrin
Re: is there a templating system that....
This looks useful as well. I think i might bench HTML::Template and Text::TagTemplate against one another for memory usage. (i'm sure speed is comparable and barely noticeable. the more apache forks i can get the better though) If/else and loops are already 'too much' -- I essentially just want variable substitution. I want designers to be able to work on a page and not need to know anything about the code/logic. Names go here, dates go here, etc. I have a bunch of custom mod_perl stuff that handles everything right now. I just want to split the code out of the handler routines. On Aug 12, 2005, at 3:50 PM, Perrin Harkins wrote: On Fri, 2005-08-12 at 14:30 -0400, Jonathan Vanasco wrote: can someone suggest to me a templating system that does not have a mini-language or is 'executed' - or if it is, it is with low overhead -- i don't want to compile more into the mod_perl process than necessary You basically just described HTML::Template. The language in it is minimal (IF/ELSE, loops) and you can't really do useful templating with less than this. You could also look at just using SSI (or Apache::SSI). Under mod_perl, SSI allows you to grab the results of Perl subs from within the page. - Perrin
Re: is there a templating system that....
On Fri, 2005-08-12 at 14:30 -0400, Jonathan Vanasco wrote: > can someone suggest to me a templating system that does not have a > mini-language or is 'executed' - or if it is, it is with low overhead > -- i don't want to compile more into the mod_perl process than > necessary You basically just described HTML::Template. The language in it is minimal (IF/ELSE, loops) and you can't really do useful templating with less than this. You could also look at just using SSI (or Apache::SSI). Under mod_perl, SSI allows you to grab the results of Perl subs from within the page. - Perrin
Re: is there a templating system that....
That is pretty much EXACTLY what I was looking for. Thanks! I really wanted to shy away from using anything TAL oriented, and mason/template toolkit are great - but require too much overhead (as i'm not making a mason/tt app, requiring them for rendering is just silly). OT: i know some people here have to use javascript occasionally. my friend bob just released a javascript library at http://mochikit.com (mit/artistic license). if you have to do anything with javascript, i'd suggest taking a look at it. he claims it makes javascript suck less, which I think it pretty much does -- the library pretty much makes javascript behave like python. On Aug 12, 2005, at 2:35 PM, Steve Duran wrote: Have you tried Text::TagTemplate?
RE: is there a templating system that....
Have you tried Text::TagTemplate? -Original Message- From: Jonathan Vanasco [mailto:[EMAIL PROTECTED] Sent: Friday, August 12, 2005 12:31 PM To: mod_perl List Subject: is there a templating system that can someone suggest to me a templating system that does not have a mini-language or is 'executed' - or if it is, it is with low overhead -- i don't want to compile more into the mod_perl process than necessary i don't have a need for any of the mini-language features -- i think i mostly need to only do the equivalent of find/replace (ie regex text into a slot) -- i just don't want to write a bunch of code that handles how to escape user-submitted info. I've been thinking of using html::tree for the templates, and putting data in divs that get specifically altered (i think that would probably be a bit faster than using PETAL, which is my 2nd in line option) I was hoping that someone here might be able to point me in another direction.
is there a templating system that....
can someone suggest to me a templating system that does not have a mini-language or is 'executed' - or if it is, it is with low overhead -- i don't want to compile more into the mod_perl process than necessary i don't have a need for any of the mini-language features -- i think i mostly need to only do the equivalent of find/replace (ie regex text into a slot) -- i just don't want to write a bunch of code that handles how to escape user-submitted info. I've been thinking of using html::tree for the templates, and putting data in divs that get specifically altered (i think that would probably be a bit faster than using PETAL, which is my 2nd in line option) I was hoping that someone here might be able to point me in another direction.