launchpad-dev team mailing list archive
-
launchpad-dev team
-
Mailing list archive
-
Message #08155
Rendering templates either server or client-side
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
I've just given Launchpad the ability to render a given template either
server-side or client-side. I've done this because the
CustomBugListings feature means we'll want to render bug listings on the
client and server sides, and we have a new design for them.
Here's a screenshot of the current work:
http://people.canonical.com/~abentley/mustache-listings.png
I've used the Mustache templating language for this. The Python
implementation is called "Pystache", and the JavaScript implementation
is called "mustache.js".
In either language, the inputs are a string and a JSON-compatible
mapping (a dict in Python, an object in JavaScript). In Javascript, you
render a template like so: "Mustache.to_html(template, data)". In
Python, it's "pystache.render(template, data)".
For the bug listings, I bundle it as a variable (LP.mustache_listings),
so that the exact same template text is used on both sides. This
satisfies DRY, and helps ensure the output will look the same wherever
it's rendered. I bundle the data in the IJSONRequestCache (LP.cache).
This means that we're also able to retrieve the data without the web
page, by appending "++model++" to the page's url path.
As we move forward with client-side rendering, I'm sure we'll
standardize this further, but I think we're off to a good start.
Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk6YphEACgkQ0F+nu1YWqI1duACeN5E+QH6kJIVHW6DxhRM+DEFN
S1sAn2zBIx/2ssH13pycEyhB+7NXOicb
=iPTJ
-----END PGP SIGNATURE-----
Follow ups