Burps
I’ve been thinking a lot about Burger recently. I’ve not been working on it at all, though. Anyway, I’m not happy about the templates. They are too simple. I would want to be able to do more sophisticated things. And I’ve been toying with the idea to make templates work a little like JSP pages. I call this “burps” – burger pages.
As an example, consider the following burp:
<% @initialize criterion = "CountCriterion.new(10)" %> <br />
<HTML> <br />
... <br />
<% page.entries.each do |entry| %> <br />
<H2><%= entry.title %></H2> <br />
<DIV CLASS="blogbody"> <br />
<%= entry.body %> <br />
</DIV> <br />
<% end %> <br />
... <br />
</HTML> <br />
This would be read and “compiled” into a PageTemplate object, which would have a CountCriterion initialized to accept 10 blog entries and a write method that looks like this:
def write(writer) <br />
writer.write("<HTML>") <br />
writer.write("...") <br />
page.entries.each do |entry| <br />
writer.write("<H2>#{entry.title}</H2>") <br />
writer.write("<DIV CLASS="blogbody">") <br /> writer.write("{#entry.body}") <br />
writer.write("</DIV>") <br />
end <br />
writer.write("...") <br />
writer.write("</HTML>") <br />
end
This would let you do anything you can do in Ruby on each page of your weblog. I’m thinking of qualifying the criterion with a key, so that you can have different criteria for each page. Say you’ll want five random blog entries in a sidebar, then you would have one CountCriterion for the key “main”, for your regular n latest bloggings, and a RandomCriterion (credit to Malte for the idea) for the key “random”. And in your burp, you would be able to do a page.entries("random").each and enumerate the random entries in your sidebar. Or something like that.
I’m also thinking (again after discussions with Malte) about having something resembling the WOResourceManager in WebObjects, so that you can get relative URL’s in your HTML pages, and absolute URL’s in your RSS feed (for images and such). This could also be used to retrieve static HTML segments, like my book list to the right. Currently, it’s duplicated in the template for my about page (which demonstrates the RandomCriterion, in case you’ve missed it).