可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
回答1:
You might be interested in SHPAML:
http://shpaml.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 it with Django, so there is a little bit of Django support, but it should not interfere with most other use cases.
回答2:
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!
回答3:
i'm looking for the same. I haven't tried it, but found this:
http://github.com/jessemiller/HamlPy
回答4:
You may be interested in Plim. It's a mature python port of Slim.
回答5:
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.
回答6:
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.
回答7:
My project, PyHAML, is a Mako preprocessor that gives you very HAML-like syntax. Some of the Ruby doesn't translate very well to Python, so there are some differences, but the spirit is the same.
回答8:
I ran across jade doing some node.js work and when returning to Django was looking for something similar. I found Pyjade and while it's nearly exactly what I'm looking for it handles errors and debugging rather poorly within Django.
回答9:
I just made this http://github.com/fitoria/django-haml it's still in very early stage but it works.
回答10:
Daniel Skinner's project (mentioned above) seems to have been renamed to DMSL. It seems very powerful, emulates HAML but allows you to use python functions, lambdas, comprehensions etc in it's syntax: https://github.com/dasacc22/dmsl