Wednesday, November 17, 2010

Sass and Haml with Django

After working with shpaml, I'd also like to have a better way of writing css.

Easy.
sudo apt-get install ruby libhaml-ruby

I also tried using HAML, but I prefer shpaml. Compare:

%h1 {{ object.question }}

{% if error_message %}
%p
%strong {{ error_message }}
{% endif %}

%form{:action => "/polls/{{ object.id }}/vote/", :method => "post"}
{% csrf_token %}
{% for choice in object.choice_set.all %}
%input{:id => "choice{{ forloop.counter }}", :name => "choice", :type => "radio", :value => "{{ choice.id }}"}/
%label{:for => "choice{{ forloop.counter }}"} {{ choice.choice }}
%br/
{% endfor %}
%input{:type => "submit", :value => "Vote"}/

h1 | {{ object.question }}

{% if error_message %}
p
strong | {{ error_message }}
{% endif %}

form action="/polls/{{ object.id }}/vote/" method="post"
{% csrf_token %}
{% for choice in object.choice_set.all %}
> input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}"
label for="choice{{ forloop.counter }}" | {{ choice.choice }}
> br
{% endfor %}
> input type="submit" value="Vote"


Also, sass has the nifty --watch option, which automatically updates your css files when necessary. HAML does not have this feature currently. Shpaml does not need this; it is automatically run when necessary.

No comments:

Post a Comment