Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Push style templating systems

by metaperl (Curate)
on Mar 14, 2008 at 15:10 UTC ( #674225=perlmeditation: print w/ replies, xml ) Need Help??

Push-style templating was defined by Terence Parr has in his seminal article. He also articulated the benefits of push-style templating, as well as defined the requirements for a system to be called as such. If the above paper seems a bit dense, there is now an HTML Template Entanglement survey which simplifies the criteria for a templating system to be push-style. HINT: JSP, Template Toolkit, HTML::Mason, Genshi, Mako, and pure PHP do not qualify as push-style systems. Those packages are an invitation to create Tag Soup, something that is impossible with push-style templating. The goal of this node is to record push-style templating systems, across languages. James Robson recently published an article on perl.com about his module Template::Recall which is similar to HTML::Seamstress.

Perl-based

HTML::Zoom
written by Matt S Trout. similar to Template::Semantic but with more streaming capabilities
HTML::Seamstress
based on HTML::TreeBuilder
Template::Replace
author is aware of push-style templating. Similar to Template::Simple by Uri Guttman.
Nes
by Skriptke
Cindy
by Joachim Zobel (monk name: ElDiabolo)
Template::Semantic
inspired by Template::Refine and very similar to Amrita
Template::Recall
by James Robson.. string-based.
Template Power
Perl port of the PHP package
HTML::Template
by Sam Tregar string-based. Using the optional HTML::Template::Expr raises the entanglement index.
HTML::TagTree
pure perl html generation
Text::Caml
by Viacheslav Tykhanovskyi. Similar to Mustache
Template::Flute
by Stefan Hornburg
HTML::Transmorgify
by David Muir Sharnoff
Text::Haml and Text::Sass
based on the ruby HAML HTML shortcut language and SASS shortcut languages.
CGI::FastTemplate
by Jason Moore.. string-based. The authors Perl module site (linked from his CPAN page) is currently down.
ZM::Template
by Maxim Kashliak
XML::Twig or XML::Rules or even XML::LibXML
if you are into strict xHTML, you might like these
HTML::Chunks
had brief friendly conversation with author

Language-Neutral

Python-based

A good discussion of Python-based solutions occurred recently. And there have been others. One important thing that came out that thread is that my list of templating systems can be found here under "Engines with Annotated Templates".

It should also be noted that the Nagare web framework has updated meld3 with some enhancements.

name comments
Muntjac completely abstracts the client-side templating
Web elements Powerful. Concise.
meld3 based on elementTree
wt clean simple powerful system
Templess based on nanosax
Webstring uses elementTree or lxml underneath
HTMLTemplate HTMLParser
PyMeld internal

Java-based

module comments
XMLC There is an Addison-Wesley text which documents this DOM-based module.
StringTemplate written by Terence Parr. Has Python and C# implementations as well.
JABHTS very well thought-out thesis project
Apache Tapestry A framework whose non-pluggable template system is push-style... I thought push-style was all about separation!

Javascript

  1. Shibari.js
  2. HOE.js
  3. jQuery's Taconite
  4. Plates
  5. Sizlate

Haskell

  1. Heist

Ruby

summary review of ruby template systems
module comments
Amrita
Ruby on Rails Through the AJAX interface, dom style rewrites are possible
KWARTZ

PHP

  • Template Power definitely push-style.. theres also a Perl version
  • Smarty is the earliest PHP push-style approach.
  • Dwoo is an "evolution" of smarty
  • KoolPHP is an AJAX library that definitely is push-style
  • XmlTag is an html generation module for PHP, one of several. The author lists others.

Prolog-based

Prolog Well-Formed Pages by Richard O'Keefe

Comment on Push style templating systems
Re: Push style templating systems
by metaperl (Curate) on Mar 14, 2008 at 18:51 UTC
    From: Oleg Kobchenko <okj@NOSPAM.com> Subject: Re: [Jgeneral] J's first/leading dynamic HTML generation tool +, JHP, is pull-style, object-level and embedded. I am shocked To: General forum <general@jsoftware.com> This business of non-Turing templates have been known in HTML and before that, in GUI in general, by the name of Data Binding. In Internet Explorer http://msdn.microsoft.com/workshop/author/databind/data_binding.asp In Windows Presentation Foundation http://msdn2.microsoft.com/en-us/library/ms752347.aspx Two-way binding in ASP.NET http://msdn.microsoft.com/msdnmag/issues/06/12/ExtendASPNET/ Windows Forms Data Binding http://msdn2.microsoft.com/en-us/library/ef2xyb33.aspx Internet Explorer 4.0-5.0 (1997-98) introduced dynamic two-way hierarchical binding was first introduced, a very powerful feature, especially coupled with hierarchical SQL query. HTML could be bound to XML data islands, which could be fetched from the server without reloading the page (technology that much later became known as AJAX).
      Microsoft has moved their data binding link.
Re: Push style templating systems
by perrin (Chancellor) on Mar 14, 2008 at 23:06 UTC
    "Push" seems like a poor name for this. It doesn't imply anything other than calling the template from perl code, i.e. the same thing I referred to as "pipeline." What makes Template::Recall different is what it lacks: loops and conditionals. I'd refer to it as something like "substitution-only" templating. You could probably count all of the answers to "How can I expand variables in text strings?" while you're at it.

    I also wouldn't lump HTML::Seamstress and XMLC in with Template::Recall and StringTemplate. As you know, the former use an approach based on the HTML/XML document structure, while Template::Recall and CGI::FastTemplate do a much simpler regex-like substitutions.

      I'd refer to it as something like "substitution-only" templating.

      One difference is that Template::Recall works on fragments, and the logic for assembling those fragments into a larger document is in the code, not the template. It's not a big thing, but it's different from other template-as-a-whole-document approaches.

        As others have pointed out though, there's no reason that other tools can't be used that way. I've certainly written TT2 and HTML::Template code that worked on fragments and assembled the results with perl code.

        I don't want to slam Template::Recall and friends. I think minimalist templating (viva sprintf!) has its place and TT2 is overkill for many small jobs. I just want more descriptive terminology.

      I guess if you limit the definition of "pipeline" templating to be just whether a system uses a method call to render the template, then Template::Recall is a pipeline system.

      But I still feel that the term "reverse callback" is appropriate, because Template::Recall uses template fragments, just as the callback method uses code fragments. It's this opposite that makes me think the term works. Here's how my mind assembles the behavior of these two models.

      Callback

      template ... --> code template --> code template ... etc

      Template::Recall

      code ... --> template code --> template code ... etc

      where --> is the callback occurance. The "callback" mechanism is essentially an 'eval' (right?), while the "reverse callback" is basically substitution.

      I picture a pipeline system more like

      code template ... ... ... ... ... --> ...

      where the rendering occurs at one time, e.g. HTML::Template->process() after the the appropriate data structures have been setup.

      I'm largely speaking for Template::Recall here, since it takes its name from "reverse callback". I'm not quite sure that I would call all systems that work on template fragments reverse callback. Or "push", for that matter, although both terms work to some degree. "Pipeline" works too, in the narrow definition above, but doesn't provide much of a distinction.

      P.S. My Interent is spotty for the next two days, so I'll try and respond, if necessary after that.

      A blog among millions.
        What I was trying to get at when I chose the terms callback and pipeline was the difference in how web requests are typically processed. Tools like Embperl, Mason, and Apache::ASP all want to hand off control to a template immediately, which puts the templates in the driver's seat (i.e. it's more like a complete program than a template). The others require you to run some other program and just call the template tool when you want to generate output.

        I wasn't trying to use these terms to separate tools which use in-line code from those that don't. For example, I don't call Text::Template a callback system.

        I don't have a trademark on these terms and you're free to use them as you wish, or ignore them completely. I'm just explaining what I had in mind when I wrote that.

      "Push" seems like a poor name for this.
      Well, what name do you think is best?
      I also wouldn't lump HTML::Seamstress and XMLC in with Template::Recall and StringTemplate. As you know, the former use an approach based on the HTML/XML document structure, while Template::Recall and CGI::FastTemplate do a much simpler regex-like substitutions.
      If you focus on _how_ they do their job, they are different. If you focus on the fact that they achieve what Terence Parr defined throughout his article, then Template::Recall and HTML::Seamstress are very similar.

      And again, with both Recall and Seamstress, you must adhere to a certain discipline while with TT and others you can adhere if you please, but dont have to.

        For me, if somebody really wants to make the artificial distinction between push and pipeline that is fine. The template world is so small and I have spent too much time quibbling about this topic in the past. I think the following two concepts frame the debate in more of the light of what it actually is about:

        Mini-language vs Variable-swapping-only - This is probably what the debate is about. Where really does the display formatting logic belong? Does it belong in the template with the rest of the display information, or does display formatting logic belong outside of the template. Without a mini-language you have to "push" the display formatting from the perl code. With a mini-language the template can "pull" data it needs.

        My chosen template system is better than that "other" template system - It is so easy to be religious about things that are trivial and insignificant, so we let ourselves be. We focus so much on an arbitrary core set of ideas, and we go so far as to treat them as absolutes, that we fail to see the merits of just about anything else. Perhaps we need a name for this system - something such as developer religio-mytopia.

        I apologize that this appears here in your node. I just find my self participating in a many lists (perl and non-perl) lately where developers argue a point as if the entire world's outcome was based upon it (only slight hyperbole here). The world of Perl Templating or even General Templating is so small but we treat it like it is the end-all-be-all. Please use what is best for you. Evangelize it even. But artificial distinctions and false absolutes don't help clear things up.

        This thread didn't start with the explicit intent of pushing Push over Pipeline, but it seems to have the implied intent, and subsequent replies have only strengthened this argument.

        Still ++ for listing the systems that fall into this particular genre.

        my @a=qw(random brilliant braindead); print $a[rand(@a)];
      I did a bit of googling for push-style and it seems that this is XML terminology based on this article.
      Template::Recall and CGI::FastTemplate do a much simpler regex-like substitutions.
      I think you mean StringTemplate, not CGI::FastTemplate... anyway, StringTemplate requires the Antlr parser generator to work, so I dont think it does simple regex substitutions.
        CGI::FastTemplate is a module with a similar approach to Template::Recall. It uses regexes.
      "Push" seems like a poor name for this. It doesn't imply anything other than calling the template from perl code, i.e. the same thing I referred to as "pipeline."
      The trick is to look at it from the capabilities of the template not how the template is called. the definitions of push and pull-style rely on what the template can do, not how the template is called.

      I also wouldn't lump HTML::Seamstress and XMLC in with Template::Recall and StringTemplate.
      From the standpoint of template capabilities given in the definition, you can see why they would be lumped together. However,
Companies using push style templating systems
by metaperl (Curate) on Mar 17, 2008 at 18:25 UTC
    Here are the companies I know where push-style templating is used:
    1. Venda an e-commerce house uses push-style. I know cuz I interviewed with them. A very very nice set of people... and all-expenses paid to London. However, I chose my current job because I could extend my skill set.
    2. Operative is a NYC firm that uses a homegrown push-style system in addition to CGI::Application. I know cuz I interviewed with them 2.
    3. Arbinger probably uses push-style since James Robson works there.
    4. My push-style work at Vendare is probably long-gone... they put foot to my ass more than a year ago... running perl/linux out of town with winders and .NET
    5. There is a company is Washington state that uses XML::LibXML to render HTML so I imagine they qualify as push-style.. I think they are whitepages.com or yellowpages.com --- they require references up front before interviewing, so that was a turn-off for me.
Re: Push style templating systems
by pKai (Priest) on Mar 22, 2008 at 13:55 UTC

    Parr goes beyond push/pull in his article. The article is titled "Enforcing Strict Model-View Separation in Template Engines".

    In his paper he shows that some additions made to "push" are harmless with regard to enforcing model-view separation, i. e. looping and conditionals ("if", but only when you confine to pure boolean testing, no expression evaluation).

    He even mentioned HTML::Template as being clean in this respect.

    So, while HTML::Template implements looping via its LOOP mini-language control, StringTemplate uses template-recursion for that. Both have, of course, the restricted if, mentioned above. But you list only StringTemplate but not HTML::Template. Why?

    Update (2008-03-23 19:25+0000):

    Or put the question the other way round (assuming that Rhandom is right, that the point of your list, at least with the Perl part is "no mini-language"): Why do you endorse/mention/include StringTemplate, though it has a mini-language?

      you list only StringTemplate but not HTML::Template. Why?
      I guess because HTML::Template::Expr raises the entanglement index. But pure HTML::Template is definitely push-style. Added.
      Or put the question the other way round (assuming that Rhandom is right, that the point of your list, at least with the Perl part is "no mini-language")
      When I opened this mode, I stated my purpose. It was to record push-style systems. I don't know why you would figure that Rhandom would know more about my purposes than the ones I stated.
      Why do you endorse/mention/include StringTemplate, though it has a mini-language?
      Because it meets the criteria for strict separation... I'm starting to see that push-style is not what he used as a term. He did use pull-style when referring to tt/mason-esque systems, but he never used to the term pull style to refer to systems like XMLC, etc.
        Actually he does use the term "push strategy" in Definition 8 in Section 7.1

        Thanks for clearing that up, at least somewhat ;-)

        Citing Terence Parr
        The trick is to provide sufficient power in a template engine without providing constructs that allow separation violation.

        It is my understanding that he shows that "push" (his Definition 8) is sufficiently strict to ensure separation. But for the template engine user's convenience you can add things while separation is still enforced.

        He designed StringTemplate accordingly, but StringTemplate isn't pure-push then, isn't it?

Re: Push style templating systems
by metaperl (Curate) on Apr 17, 2009 at 15:05 UTC
Re: Push style templating systems
by metaperl (Curate) on Aug 03, 2009 at 12:17 UTC
    added XML::TWig to the list of push-style templating systems.
Re: Push style templating systems
by metaperl (Curate) on Aug 17, 2009 at 13:30 UTC
    Cindy appears to offer strong separation of code from Perl.

      Actually Cindys web engine Cindy::Apache2 (requires mod_perl) is language independent. It takes XML data that can be produced by an apache request handler (static, php, ...) and moves them into a template.

      How to move the data is specified in a content injection sheet. This has a <source xpath> action <target xpath> syntax to describe data movements.

      This may even qualify as strict separation. I'll check if my module (Cindy, see also http://www.heute-morgen.de/site/10_About.shtml) is actually Parr strict.

        I am not shure if I must consider the content injection sheet part of the view. If so I enforce only the most important Parr rule (Do not modify the model). The others can be violated because I use XPath as my mini language.
Template::Semantic - a new Push style templating system
by metaperl (Curate) on Feb 09, 2010 at 19:32 UTC
Re: Push style templating systems
by metaperl (Curate) on Feb 19, 2010 at 12:23 UTC
Re: Push style templating systems
by metaperl (Curate) on Feb 19, 2010 at 12:36 UTC
Text::Haml a ruby-inspired Push style templating system
by metaperl (Curate) on Mar 10, 2010 at 21:20 UTC
Matt S Trout has authored a Push style templating system!
by metaperl (Curate) on Mar 18, 2010 at 21:37 UTC
    HTML::Zoom has been added to the list. Why did he write it?
    I just wanted a streaming capable seamstress that I didn't hate the API of :)

    How should we refer to him?

    please use 'Matt S Trout' for consistency,that's how I sign -everything- ... it's not a big deal, it's just that it makes iteasier for people to connect cpan MSTROUT and IRC mst

Nes - a new Push style templating system
by metaperl (Curate) on Apr 15, 2010 at 19:09 UTC
      Only 'SELECT' statement. Since the template does not modify the application data.
      
          Nes Model:
      
          .----------------------------------------------.
          |                 | Nes Object |               |
          |                 '------------'               |
          | .-------------------.    .-----------------. |
          | |  template.nhtml   |    |    script.pl    | |
          | |-------------------|    |-----------------| |
          | |        _          |--->|    _       _    | |
          | |        |          |<---|    |       |    | |
          | '--------|----------'    '----|-------|----' |
          '----------|--------------------|-------|------'
                     |                    |       |
                     |                    |       '------------------.
                     |                    |                          |
                     v                    v                          v
          .----------------------.  .-----------------------.  .------------.
          |                      |  |                       |  |            |
          |  Nes Object Library  |  |  My App Perl Library  |  |    CPAN    |
          |                      |  |                       |  |            |
          '----------------------'  '-----------------------'  '------------'
      
          Nes Object:
      
          .------------------------------------------------------------------------------------.
          |                                 | Nes Object |                                     |
          |                                 '------------'                                     |
          | .-----------------------------------.    .---------------------------------------. |
          | |          template.nhtml           |    |              script.pl                | |
          | |-----------------------------------|    |---------------------------------------| |
          | |                                   |--->|                                       | |
          | |    {: Nes 1.0 ('script.pl') :}    |    | Nes::Singleton->new('template.nhtml') | |
          | |                                   |<---|                                       | |
          | '-----------------------------------'    '---------------------------------------' |
          '------------------------------------------------------------------------------------'
      
          Nes Request:
          
          .-------------------------------------------.
          |         GET or POST HTTP Request          |
          |     http://example.com/template.nhtml     |
          '-------------------------------------------'
                              |
                              v
          .-------------------------------------------.
          |        /cgi-bin/nes/dispatch.cgi          |
          '-------------------------------------------'
                              |
                              v
          .-------------------------------------------.
          |              Nes::Singleton               |
          |-------------------------------------------|
          | new {'CFG'} for this dir                  |
          | new {'top_container '} for template.nhtml |
          '-------------------------------------------'
                              |
                              v
          .-------------------------------------------.
          |     Nes::Singleton->{'top_container'}     |
          |-------------------------------------------|
          | new {'register'}                          |
          | new {'query'}                             |
          | new {'cookies'}                           |
          | new {'session'}                           |
          | new {'container'} for template.nhtml      |
          '-------------------------------------------'             
                              |
                              v
          .-------------------------------------------.
          |       Nes::Singleton->{'container'}       | <---.
          |-------------------------------------------|     |
          | get {  NES 1.0 ...  } line                |     |
          | new {'content_obj'} for this content type |     |
          '-------------------------------------------'     |          
                              |                             |
                              v                             |
          .-------------------------------------------.     |
          |             do Perl scripts               |     |
          |-------------------------------------------|     |
          | Nes::Singleton->out()                     |     |
          '-------------------------------------------'     |
                              |                             |
                              v                             |
          .-------------------------------------------.     |
          | Nes::Singleton->{'container'}->interpret  |     |
          '-------------------------------------------'     |
                              |                             |
                              v                       ( interaction )
                   .---------------------.                  |
                   | {  include  }   ?   |---{ yes }--------'
                   '---------------------'                         
                              |
                            { no }
                              |
                              v
          .-------------------------------------------.
          | print HTTP Headers                        |
          | print the out                             |
          '-------------------------------------------'  
Dwoo added to Push style templating systems
by metaperl (Curate) on Apr 22, 2010 at 15:11 UTC
Mustache: a language-neutral Push style templating system
by metaperl (Curate) on Dec 13, 2010 at 18:33 UTC
Text::Caml added to push style templating systems list
by metaperl (Curate) on Feb 10, 2011 at 14:46 UTC
Template::Flute added to Push style templating systems list
by metaperl (Curate) on Mar 15, 2011 at 15:11 UTC
HTML::Transmorgify added to Push style templating systems
by metaperl (Curate) on Mar 25, 2011 at 20:18 UTC
HTML::TagTree added to push-style templating list
by metaperl (Curate) on Aug 01, 2011 at 22:01 UTC
    HTML::TagTree is documented as being able to do flexible HTML templating. The examples show it doing full documents, but the actual interplay of this module with HTML in practical settings is not shown in the docs. Generating HTML de novo is one part of HTML templating - replacing text and deleting text are the others and I dont see how this module handles that.

    Perhaps with the new wave of all design being delegated to CSS, this purely programmatic approach to HTML generation may in fact be workable. What are typically replacements in common HTML templating would simply be generated on the fly with this module. And deletions are a non-issue as only what is needed is generated.

Template Power added to the push-style templating system list
by metaperl (Curate) on Mar 30, 2012 at 14:43 UTC
2 javascript and 1 haskell languaged added to push-style templating systems list
by metaperl (Curate) on Apr 08, 2012 at 12:24 UTC
Template::Replace added to Push style templating systems
by metaperl (Curate) on May 01, 2012 at 13:41 UTC
Re: Push style templating systems
by metaperl (Curate) on Mar 18, 2013 at 14:06 UTC
Muntjac and Web Elements
by metaperl (Curate) on Apr 02, 2013 at 15:25 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://674225]
Approved by Erez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2014-08-27 22:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls