Template::Plugin::Haml caveats
Including 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.
08:00 AM, 29 Jul 2010 by Mark Aufflick Permalink | Comments (0)
Using Haml with Catalyst
Thanks 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:
packageHello::View::Haml; usestrict; usewarnings; usebase'Catalyst::View::TT'; useTemplate::Plugin::Haml; __PACKAGE__->config( TEMPLATE_EXTENSION => '.haml', render_die => 1, ); subrender { 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} } ifref$argsne'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:
subfoo: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:
<body>
<p>This is haml inside TT rendering your variables: bar</p>
</body>
04:35 AM, 29 Jul 2010 by Mark Aufflick Permalink | Comments (0)
Cauliflower, Potato and Carrot Puree
Our 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
for a carrot and parsnip puree and came up with the following:
- 200g potato
- 100g carrot
- 2 small onions
- 600g cauliflower
- 1-2 garlic cloves
- 2 cups stock (I used chicken, but I think vegetable would be better)
Loosely chop all the ingredients. Melt some butter and olive oil in a pan. Saute carrott and potato, seasoning lightly. Add onion and garlic, then cauliflower. Cook for a while then partially cover with stock and vigorously simmer with the pan loosely covered (e.g. with a wok lid). When vegies are becoming soft, remove lid and continue cooking until almost all the liquid has evaporated. Puree until smooth in a blender.
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.
07:27 AM, 26 Jul 2010 by Mark Aufflick Permalink | 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
- Exposure: 1/160
- Aperture: f22.0
- ISO speed: 100
- Exposure program: Aperture-priority AE
- Exposure compensation: -2
- Flash: Off, Did not fire
- File: _MG_3822.jpg
02:57 AM, 25 Jul 2010 by Mark Aufflick Permalink | Comments (0)
Sun at last
We 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
- Exposure: 1/125
- Aperture: f22.0
- ISO speed: 100
- Exposure program: Aperture-priority AE
- Exposure compensation: 0
- Flash: Off, Did not fire
- File: _MG_3811.jpg
02:54 AM, 25 Jul 2010 by Mark Aufflick Permalink | Comments (0)
Archive
| July 2010 | ||||||
| S | M | T | W | T | F | S |
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
March 2012
February 2012
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 Categories
software (40)..cocoa (21)
..heads up 'tunes (5)
..ruby (6)
..lisp (4)
..perl (4)
..openacs (1)
mac (21)
embedded (2)
..microprocessor (2)
..avr (1)
electronics (3)
design (1)
photography (26)
..black and white (6)
..A day in Sydney (18)
..The Daily Shoot (6)
food (2)
Book Review (2)
Notifications
Request notifications








