Live data from Hacker News

HTML and CSS Preprocessors

learn.shayhowe.com

1–10 of 18 posts

Re: HTML and CSS Preprocessors

#2
I love this series.

Can anyone give an example of when HAML would be used in the 'real world'? I can't imagine it filling a niche that isn't covered by any of the other templating languages: what would seem most ideal is a combination of say, Jinja and HAML.

Re: HTML and CSS Preprocessors

#3
post #2

I love this series. Can anyone give an example of when HAML would be used in the 'real world'? I can't imagine it filling a niche that isn't covered by any of the other templating languages: what would seem most ideal is a combination of say, Jinja and HAML.

I know a lot of ruby on rails developers who use HAML for their template framework instead of ERB. Some people prefer HAML's use of indentation instead of using tags to enclose everything.

I like it in my projects mostly for how clean and easy it is to read. It takes a little bit to get used to initially but it is worth it.

Re: HTML and CSS Preprocessors

#4
post #2

I love this series. Can anyone give an example of when HAML would be used in the 'real world'? I can't imagine it filling a niche that isn't covered by any of the other templating languages: what would seem most ideal is a combination of say, Jinja and HAML.

You might be interested in shpaml-jinja[0]. It extends the shpaml[1] syntax to provide jinja commands.

[0]: https://github.com/p/shpaml-jinja [1]: http://shpaml.webfactional.com/examples

Re: HTML and CSS Preprocessors

#6
post #3
post #2

I love this series. Can anyone give an example of when HAML would be used in the 'real world'? I can't imagine it filling a niche that isn't covered by any of the other templating languages: what would seem most ideal is a combination of say, Jinja and HAML.

I know a lot of ruby on rails developers who use HAML for their template framework instead of ERB. Some people prefer HAML's use of indentation instead of using tags to enclose everything. I like it in my projects mostly for how clean and easy it is to read. It takes a little bit to get used to initially but it is worth it.

...and you can combine it with Sass for CSS. Sass gives you features that CSS misses like inheritence which makes your style sheets much more DRY.

BTW, both Haml and Sass go very nicely with Sinatra... ;)

Re: HTML and CSS Preprocessors

#7
post #5

Quick nitpick: HAML is not a pre-processor for HTML, it is a templating language.

Anything that is self-described as an "abstraction markup language" and must be compiled into the language it abstracts is really a pre-processor.

Regardless of intended use cases, i cant think of a better definition.

Re: HTML and CSS Preprocessors

#8
post #2

I love this series. Can anyone give an example of when HAML would be used in the 'real world'? I can't imagine it filling a niche that isn't covered by any of the other templating languages: what would seem most ideal is a combination of say, Jinja and HAML.

I'm finding that it's a lot cleaner to use with Javascript. For example, say you have an array of items and you want to create a fieldset for each item, and add an attribute of "data-id", and "data-category" to each fieldset so you can grab them with jQuery later on.

In HAML all you have to do is this...

- @items.each do |item|

  %fieldset{:data => {:id => item.id, :category => item.category}}
===

In ERB the equivalent would be...

  " data-category="">

  

===

It's a lot cleaner in HAML, especially extrapolated out over larger views.

Re: HTML and CSS Preprocessors

#9
post #2

I love this series. Can anyone give an example of when HAML would be used in the 'real world'? I can't imagine it filling a niche that isn't covered by any of the other templating languages: what would seem most ideal is a combination of say, Jinja and HAML.

My old company used HAML exclusively for all of our RoR view code. In most general cases it makes the coding faster. THere are of course some wonky edge cases in HAML vs code style best practices.

For instance: try making an html element with a long list of attributes and see how it looks. Or worse, run a translate on a block of text while maintaining reasonable line lengths.

Good? Yes. Silver bullet html replacement? Lol.

Re: HTML and CSS Preprocessors

#10
I've never heard of HAML before. From the website, is it literally just "markup should be beautiful"?

I mean, LESS/SASS add real functionality. Even CoffeeScript adds functionality to JavaScript, beyond just changing the syntax. But is there any functional advantage to use HAML? Is it actually worth half a chapter of an "advanced guide to HTML & CSS"?

(Totally my opinion, but it doesn't even look clearer or "more beautiful" to me, but maybe that's just because I'm used to HTML.)

Post reply on HN