Skip to main content

Ralsina.Me — Roberto Alsina's website

BartleBlog change: Mako Templates

Since the very be­gin­ning, Bartle­Blog has been us­ing Cher­ry­Tem­plate for its out­put for­mat­ting need­s. I like it, be­cause it's very sim­ple.

How­ev­er, it had grown rather cum­ber­some.

Specif­i­cal­ly, most pages in a blog are sort of a page tem­plate with a body tem­plate in­side (the main con­tent).

To do that on Cher­ry­Tem­plate, I used a two-­pass ap­proach: gen­er­ate the body, then pass it as pa­ram­e­ter to the page tem­plate.

Which is a pain in some cas­es be­cause you end ba­si­cal­ly hav­ing to do a ren­der­ing func­tion for each kind of page, or some crazy-evil func­tion (what I did).

Ex­plor­ing the dif­fer­ent python tem­plate en­gi­nes, I ran in­to Mako and de­cid­ed to give it a whirl. It looks good.

The ap­proach is a bit dif­fer­en­t, it is much more pow­er­ful, but you can still use it sim­ply if you can.

And the main fea­ture was tem­plate in­her­i­tance. Us­ing that, no more in­ner and out­er tem­plates, baby!

Oh, and per­for­mance is bet­ter:

Cherry

real    31m44.732s
user    21m18.336s
sys     2m7.628s


Mako

real    24m54.472s
user    19m9.508s
sys     1m56.375s

This is for com­plete­ly reren­der­ing the whole 7 years, 574 post­s, 40 stat­ic ar­ti­cles, 14 cat­e­go­ry blog, and there is tons of op­ti­miza­tions to be done.

BTW: this is how you reren­der the whole blog:

from BartleBlog.backend.blog import Blog
Blog().renderFullBlog()
phone number lookup / 2011-12-03 22:21:

this is really interesting viewpoint on the subject i might add

cell phone lookup / 2012-01-17 05:52:


Your blog has the same post as another author but i like your better


Contents © 2000-2024 Roberto Alsina