views:

450

answers:

3

Ok, so I really love HAML. Particularly, I love the integration with RedCloth and BlueCloth, so I can use Markdown and Textile intermixed with my HAML.

I also love Python and Django.

So, I would like to use HAML with Django. Now, I already understand that there are some attempts at cloning HAML-like syntax in Python (SHPAML and others). I've tried these, and while they aren't bad, I've found that I really just want the real HAML. Partially for its syntax, but also for things like RedCloth and BlueCloth.

So, my question is, how to make HAML and Django work together?

One solution, I think, would be to create HAML templates, and then compile them into HTML using the command line tool every time they're updated.

Quesiton 1: Will I run into any problems here?

I also wonder if there's a way to get Python and Ruby to play together a little more. One idea I had was actually forking out Ruby processes. This is probably a bad idea, but anyone have any thoughts about this?

Question 2: What about using Python to call the real Ruby HAML?

Finally, if anyone knows of a Python implementation of HAML that is complete, and that supports either Textile or Markdown, as well as plaintext passthru, then let me know.

Question 3: Is there a full translation of HAML to Python including Markdown or Textile support?

Thanks!

+4  A: 

Question 1: static HTML files should work finely (unless you plan to use HAML's ruby evaluation feature to dynamically content). I use a similar way on a php website with SASS stylesheets. Just make sure you start HAML in directory watch mode before starting to hack ;)

Question 2: while forking a ruby process to create HTML code is possible, but I don't recommend it you, because initializing a ruby interpreter, and loading required files takes a lot of cpu times, so you better stick with static files. If you need the ruby evaluation feature to include runtime created data into the document, you'd better have a look at eventmachine, and make it a server (so your Django application can connect to it, and request HTML generation, without forking a new interpreter each time).

Question 3: maybe this is the hardest. There's GHRML which is abandoned; SPHAML which only implements a small subset of HAML, DAML which is currently very experimental, but already supports most of HAML and also calling python code, but lacks Markdown or Textile support. But apparently there's no alternative (yet) to Ruby HAML that supports all the required features.

DirtY iCE
A: 

While this could end up being more trouble than it is worth, it is PROBABLY possible to leverage the Java or .NET platform and still run your Django application in Jython or IronPython (with some minor adjustments I'm sure) and also be able to leverage Ruby's HAML gem via jRuby or IronRuby.

I'm sure there will be some quirks in getting this to work, but I'm sure it would be possible.

Again, this is probably a lot more trouble than it's worth (considering that you'd have to move your application to a completely new platform), but it would be a pretty fun project to work on.

Matthew J Morrison
A: 

Try: http://github.com/fitoria/django-haml

Fitoria