creationix / haml-js

Haml ported to server-side Javascript. This is a traditional server-side templating language. Tested with node-js
MIT License
901 stars 110 forks source link

not liking the spacing trimming #19

Closed mikesmullin closed 13 years ago

mikesmullin commented 14 years ago

it seems if i want spacing inbetween any of my tags, i have to explicitly define that, like so:

%p
  Getting started is easy. Watch our
  =' '
  %a(href="#") demo video
  =' '
  to learn more.

This approach is artificially inflating the size of my Haml templates, and reducing readability.

Why can't it assume that items on a new line have a space between them, unless you specify %p>< similar to how Ruby Haml does?

see also: http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#whitespace_removal__and_

creationix commented 14 years ago

Yeah, I've noticed that too. It never was my goal to be an exact haml clone, but it kinda sucks for this particular use case.

Short answer, it's hard, and I've simply had more pressing things to work on.

Long answer I think the ideal solution is better embedding of alternate syntaxes like markdown. I had started on this a while back, but gave up.

I'll gladly accept patches for this. Also you can look at TJs haml.js and jade template compiler. They have different features and generally fit the ruby haml better.

aaronblohowiak commented 13 years ago

In the 0.3.0 branch, I made it so you can add whitespace inside or around your tags. This is the opposite of how Ruby-Haml works, but it a) is backward compatible and b) keeps the default html very slim.

https://github.com/creationix/haml-js/commit/7df30e5a2209317e576d158ca6c3f9ed55b72e4d

Whitespace

By default, Haml.js has no whitespace between tags. In this way, Haml.js is the opposite of Haml in Ruby. You can insert whitespace around or inside tags with > and <, respectively.

Most commonly, you want to have an a or span with whitespace around it:

Download the file
%a(href="/home")> here
now.

Will produce:

Download the file <a href="/home">here</a> now.

You can also combine them if you want to have whitespace around and inside your tag.

%span<> This will have space in and around it.
%span>< This will, too.
%span><= "also works with code".toUpperCase()

Please see test/whitespace.haml for more examples.