views:

3752

answers:

6

I happened to stumble across HAML, an interesting and beautiful way to mark up contents and write templates for HTML.

Since I use Python and Django for my web developing need, I would like to see if there is a Python implementation of HAML (or some similar concepts -- need not be exactly identical) that can be used to replace the Django template engine.

+12  A: 

I'd check out GHRML, Haml for Genshi. The author admits that it's basically Haml for Python and that most of the syntax is the same (and that it works in Django). Here's some GHRML just to show you how close they are:

%html
  %head
    %title Hello World
    %style{'type': 'text/css'}
      body { font-family: sans-serif; }
    %script{'type': 'text/javascript', 'src': 'foo.js'}

  %body
    #header
      %h1 Hello World
    %ul.navigation
      %li[for item in navigation]
        %a{'href': item.href} $item.caption

    #contents
      Hello World!
Chris Bunch
That link returns 404. Project isn't abandoned is it?
Jethro Larson
Ditto. The page returns error for me too.
jpartogi
Borken link, can this be updated?
arbales
+3  A: 

This doesn't actually answer your question, but the CSS component of HAML, SASS, can be used freely with any framework. I'm using it right now with Django.

Sudhir Jonathan
+17  A: 

You might be interested in SHPAML:

http://shpaml.webfactional.com/

I am actively maintaining it. It is a simple preprocessor, so it is not tied to any other tools like Genshi. I happen to use with Django, so there is a little bit of Django support, but it should not interfere with most other use cases.

Steve Howell
+2  A: 

I'm not sure what the status is of the GHRML bit as I only recently was looking into it. Can't find a repo for it, original developer doesn't have time for it anymore and maintenance was picked up by someone else with an interest in the project. Any extra info on this would be helpful.

Unfortunately, as these things go, I started writing my own HAML style processor ;)

http://dasacc22.wordpress.com/2010/05/03/python-implementation-of-haml/

It's in no way fit for production use at the moment (its literally a 4 day old infant now but like 60+hours crammed in those 4 days) but anyone interested may check it out here. It has a range of features already implemented that make it useful as a toy, and as I clean up the codebase over the next week, I hope to see it replace all my custom XSLT/xpath extensions and templates I have.

Daniel Skinner
A: 

i'm looking for the same. I haven't tried it, but found this:

http://github.com/jessemiller/HamlPy

Roger
+1  A: 

I just made this http://github.com/fitoria/django-haml it's still in very early stage but it works.

Fitoria