Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby HAML with Django?

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!

like image 969
MikeC8 Avatar asked Jun 20 '10 13:06

MikeC8


2 Answers

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; SHPAML which only implements a small subset of HAML, DMSL 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.

like image 195
DirtY iCE Avatar answered Sep 16 '22 11:09

DirtY iCE


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

like image 25
Fitoria Avatar answered Sep 17 '22 11:09

Fitoria