Template::Plugin::Haml caveatsIncluding other templates is tricky. Either you have to indent the included template as if it was pasted inline (eg. with a bunch of spaces in front of every line instead of the first level being column zero) or you have to format the include appropriately. For example, let's say you have a content variable which was made by rendering some templates, you'd like to do something like:
%html
%body
#content
[% content %]
You want the embedded content to be location neutral, ie. start at column zero. Something like:
#myDiv
%ul
%li foo
Except this will be rendered AFTER the closing html tag since the combined haml will look like:
%html
%body
#content
#myDiv
%ul
%li foo
I'm going to try to think of some better way to resolve this, but for now I'm using the Template::Toolkit built in indent filter like so:
%html
%body
#content
[% content | indent(' ') %]
The only downside (apart from the pain of keeping it in sync) is that you end up with the rendered html having some funky indentation after the newlines are stripped, but I can live with that. You can use a number instead of a string as an argument to indent, and it will pad by that many spaces which may turn out to be easier to keep in sync. I'll let you know if I have any flashes of genius and will also contact the Template::Plugin::Haml and Text::Haml authors. 10:00 PM, 29 Jul 2010 by Mark Aufflick Permalink | Short Link | Comments (0) Using Haml with CatalystThanks to Viacheslav Tykhanovskyi's Text::Haml, we can now enjoy the good clean fun of Haml markup in Perl. Much Perl web templating is done with Template::Toolkit, and using Haml within TT is also now possible thanks to Template::Plugin::Haml by Caleb Cushing. The trouble is, you need to wrap every template in some boilerplate: [%- USE Haml ; FILTER haml -%] ... [%- END -%] So I hacked up a quick solution to using .haml templates directly in Catalyst. First, create a MyApp::View::Haml class: package Hello::View::Haml; use strict; use warnings; use base 'Catalyst::View::TT'; use Template::Plugin::Haml; __PACKAGE__->config( TEMPLATE_EXTENSION => '.haml', render_die => 1, ); sub render { my ($self, $c, $template, $args) = @_; $c->log->debug(qq{Rendering Haml/TT template "$template"}) if $c && $c->debug; # args may be passed in or be in the stash $args = { %{ $c->stash} } if ref $args ne 'HASH'; # let the master haml template know which template to render $args->{haml_template} = $template; # do the normal TT render return $self->SUPER::render($c, 'haml_master.tt', $args); } 1; Then you need a haml_master.tt template: [%- USE Haml ; PROCESS $haml_template | haml -%] And finally set your config to use the Haml view by default: default_view => 'Haml' Et voila - .haml template rendering albeit with only TT style variable interpolation. Getting haml interpolation working might need some change to how the stash is passed to the Text::Haml module. A controller method might look like this: sub foo :Global { my ($self, $c) = @_; $c->stash(foo => 'bar'); $c->stash(template => 'foo.haml'); } And foo.haml: !!! HTML %body %p This is haml inside TT rendering your variables: [% foo %] Becomes rendered as:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<body> <p>This is haml inside TT rendering your variables: bar</p> </body> 06:35 PM, 29 Jul 2010 by Mark Aufflick Permalink | Short Link | Comments (0) Cauliflower, Potato and Carrot PureeOur weekly fruit and veg delivery from Doorstep Organics arrived today which meant we had to use up some older produce with todays dinner. We had a fair amount of cauliflower and some carrots so I decided to make a puree. I started with an idea from New Larousse Gastronomique
I served it with some delicious organic sausages and steamed broccoli. This would be enough for at least six, or you can refrigerate and use over a few days. 09:27 PM, 26 Jul 2010 by Mark Aufflick Permalink | Short Link | Comments (0) Where'd everybody go?Our neighbour has a great deciduous tree that attracts loads of birds in summer. Some birds seem not to mind when all the leaves disappear (into our yard) Series home: http://mark.aufflick.com/a-day-in-sydney Taken with Canon EOS 400D DIGITAL and EF24-85mm f/3.5-4.5 USM on 2010:07:25 15:28:15
04:57 PM, 25 Jul 2010 by Mark Aufflick Permalink | Short Link | Comments (0) Sun at lastWe haven't had too much sun this winter in Sydney, so it's always a welcome friend Series home: http://mark.aufflick.com/a-day-in-sydney Taken with Canon EOS 400D DIGITAL and EF24-85mm f/3.5-4.5 USM on 2010:07:25 15:25:50
04:54 PM, 25 Jul 2010 by Mark Aufflick Permalink | Short Link | Comments (0) |
Archive
November 2011 October 2011 April 2011 March 2011 January 2011 November 2010 October 2010 September 2010 August 2010 July 2010 June 2010 May 2010 April 2010 March 2010 February 2010 January 2010 October 2009 September 2009 August 2009 July 2009 June 2009 May 2009 April 2009 February 2009 January 2009 December 2008 November 2008 October 2008 September 2008 August 2008 July 2008 June 2008 May 2008 March 2008 February 2008 January 2008 December 2007 November 2007 October 2007 September 2007 August 2007 July 2007 June 2007 May 2007 April 2007 March 2007 February 2007 January 2007 December 2006 November 2006 October 2006 September 2006 August 2006 July 2006 June 2006 May 2006 April 2006 March 2006 February 2006 January 2006 December 2005 November 2005 October 2005 September 2005 August 2005 July 2005 June 2005 May 2005 April 2005 March 2005 February 2005 January 2005 December 2004 November 2004 October 2004 September 2004 August 2004 July 2004 June 2004 May 2004 April 2004 March 2004 February 2004 January 2004 December 2003 November 2003 October 2003 September 2003 August 2003 Blog Categoriessoftware (39)..cocoa (21) ..heads up 'tunes (5) ..ruby (6) ..lisp (3) ..perl (4) ..openacs (1) mac (20) embedded (2) ..microprocessor (2) ..avr (1) electronics (3) design (1) photography (25) ..black and white (6) ..A day in Sydney (18) ..The Daily Shoot (6) food (2) Book Review (2) Notifications Request notifications
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||










Request notifications