slim-template/slim — pull request #336 by raxoft (2013-01-21 22:40:13+00:00)
Title: Smart text mode for Slim

Hello.

I have been using Haml for several years, and while I love it for being so much easier to write than HTML or other tag based markups, there were two major things which always annoyed me. One was the need for using the appropriate () or {} syntax around attributes, the other was the need for using verbatim HTML if one wanted a link followed directly by a dot or comma or similar.

Finally I recently discovered Slim. However, while it brilliantly solves the attribute issues, when it comes to typing text and mixing it with simple markup such as links, with no offense, it leaves a lot to be desired. To get the whitespace right around links requires annoying switching between | and ' appropriately, which is far from convenient. Of course, I know the "Haml sucks for content" mantra, but simple text mixed with links is just so common that it deserves to be addressed better than that.

Therefore, I began thinking what could be done to improve this. I have converted quite a few of my existing Haml templates to Slim, and I have realized that I can almost always tell text from tags because it often starts with an uppercase letter. This is where smart text was born.

Once I had an idea of distinguishing text from the tags, the rest was easy. In addition to the implicit text detection I have added the explicit > line indicator. Then it was all about controlling the whitespace with preserved newlines, and suppressing them at appropriate points. The automatic escaping with HTML entity preserving is just an extra toping. I also got to fix few things like tab expansion along the road.

All in all, it is all present in this smart_text branch. Please check the updated Readme and tests and let me know what you think. While I am aware that some people might need uppercase tag names or fully unicode tag names and won't be able to use the implicit recognition, I hope that this is still something which might please most of Slim users out there. It definitely addresses my needs for typing both markup and text equally easily, and I hope that you will find it useful as well.

Thanks,

Patrik Rak

P.S. Of course, I am willing to rebase it against whatever commit you desire, and discuss whatever concerns you might have.