Rocket powered rollerskates templating with HTML::Zoom & Catalyst
March 20, 2010 § 1 Comment
Matt Trout has produced yet more Perl magic with a new templating system – HTML::Zoom. I’d accuse him of committing a cardinal sin, but I guess we can let him off seeing as it’s badass.
A templating engine isn’t much use unless we’ve got something to drive it – and what’s a more natural choice than Catalyst? As always, Catalyst makes gluing things together trivial – so I’ve adopted some prior art from t0m and released Catalyst::View::HTML::Zoom. Now, this is version 0.001 so it wouldn’t be complete without a big fat blinking disclaimer: we might have done this wrong. I chatted about it briefly in #catalyst before starting work, but I still could have got it wrong! So the API could change and everything might blow up in your face… but that’s the fun, right?
Anyway, here’s a brief look at how we’ve got it structured at the moment (shamelessly plagiarized from my own CPAN synopsis):
package MyApp::View::HTML; use Moose; extends 'Catalyst::View::HTML::Zoom'; package MyApp::Controller::Wobble; use Moose; BEGIN { extends 'Catalyst::Controller' } sub dance : Local { my ($self, $c) = @_; $c->stash( shaking => 'hips' ); } package MyApp::View::HTML::Controller; use Moose; sub dance { my ($self, $stash) = @_; $_->select('#shake')->replace_content($stash->{shaking}); } #root/wobble/dance <p>Shake those <span id="shake" />!</p> /wobble/dance => "<p>Shake those <span id="shake">hips!</span></p>";
The key class here is MyApp::View::HTML::Wobble which does the HTML::Zoom substitutions. $_ is locally aliased to the HTML::Zoom object for convenience and the first parameter is the stash object.
Happy hacking – let’s see where this ends up!
[…] I’ve added acidcycles.wordpress.com to my reader. Not only is he talking about Catalyst and templating engines such as HTML::Zoom but he also mentioned building an Emacs site with Catalyst which I will be following with interest […]