in reply to Re: The history of a templating engine
in thread The history of a templating engine
Just so there isn't any confusion, I'll hit a few of these points...
For code which should insert something into html I've used three different construct: @~...~@, ^~...~^ and #~...~#, so web designer is able to see: here will be inserted some text. Only difference between them is escaping: @~~@ add html-escaping, ^~~^ add uri-escaping and #~~#
See, this is what I would consider to be a bad design decision. This completely ties the templating system into HTML and with different syntax for different output. What happens if you want to use your template for something other than HTML and need a different type of escaping? What if you want to escape your HTML in different ways?
For example, internally on my site, I have a blogger style syntax processor. So I can type ~some text~ and it'll translate to some text automatically for me. I hate typing HTML all over the place. With your approach, to do something similar, you'd need to add in some sort of new embed syntax, or wrapper up a new function. With my approach, it uses pipes (ala unix) for the same effect - <% "~some text~" | blog %>. Sure, you define a new function, but you don't need new syntax to add new functionality.
Incidentally, I also made all of my template tags user configurable with no speed hit. So if you want to use something else, it's simply changing a value in a config file.
That's all, only 4 special tags!
Basset::Template has 7 special tags. 3 of are unquestionably syntactic sugar (the comment tags, the "big eval" tags, and the debug tags), leaving the return tags, eval tags, and include tags (and the cached include tags, but that's an optimization syntactic sugar). And I'm sure you don't have a problem with sugar, since the 3 different insert styles you have are arguably just sugar as well. :-)
I've used do{}, as Jenda proposed in previous comment.
This was an awesome suggestion (thanks Jenda!) and I have added it to the internal builds. Admittedly, it does prevent the user from typing in <% return $value %>, but I figured that it was a worthwhile modification to get rid of the anonymous subs.
150 lines of code (parser itself is 30 lines), less than 6KB.
Even if I rip out the documentation, examples, sugar, and unique features, i still only get down to 405 lines, so I'll give this one to you.
it's all pure sugar.%% # this is a comment or <% # this is a comment %> or <# this is a comment #>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: The history of a templating engine
by powerman (Friar) on Sep 12, 2006 at 21:59 UTC | |
by Anonymous Monk on Sep 20, 2006 at 07:18 UTC | |
by powerman (Friar) on Sep 20, 2006 at 10:43 UTC | |
Re^3: The history of a templating engine
by ursus (Acolyte) on Jan 03, 2008 at 19:54 UTC |