So, Haml is *not* good at taking ugly code and making it pretty. Its good at
making you make sure you do good stuff.
def text_field_with_label(f, name, label_override = nil, options = {})
  haml_tag :p do
    puts f.label(name, label_override)
    puts f.text_field(name, options)
  end
end

then, you can do...

- text_field_with_label(f, :name)
- text_field_with_label(f, :address)
- text_field_with_label(f, :country)
.... etc....

making it even more dry, i'd probably do this.

def field_sets(f, *names)
  names.each do |data|
    name, label_override = *data
    puts text_field_with_label(f, name, label_override)
  end
end

- field_sets(f, :name, :address, :country, [:uri, "URI"], :postal_code)

Also, let's say we kept this simple and a little WET. What is so wrong with
doubling the lines.
Its less characters than the erb! So what if its on a new line?

Fin.

-hampton.

On Sun, Mar 15, 2009 at 6:07 PM, gdelfino <[email protected]> wrote:

>
> Hello all, I started using HAML today. I want to convert this 9 lines
> chunk of .html.erb into HAML
>
> <p><%= f.label :name           %><%= f.text_field :name           %></
> p>
> <p><%= f.label :address        %><%= f.text_field :address        %></
> p>
> <p><%= f.label :country        %><%= f.text_field :country        %></
> p>
> <p><%= f.label :contact        %><%= f.text_field :contact        %></
> p>
> <p><%= f.label :email          %><%= f.text_field :email          %></
> p>
> <p><%= f.label :uri, "URI"     %><%= f.text_field :uri            %></
> p>
> <p><%= f.label :phone          %><%= f.text_field :phone          %></
> p>
> <p><%= f.label :fax            %><%= f.text_field :fax            %></
> p>
> <p><%= f.label :purchase_order %><%= f.text_field :purchase_order %></
> p>
>
> I wish that this could be represented as:
>
> %p= f.label :name          ; f.text_field :name
> %p= f.label :address       ; f.text_field :address
> %p= f.label :country       ; f.text_field :country
> %p= f.label :contact       ; f.text_field :contact
> %p= f.label :email         ; f.text_field :email
> %p= f.label :uri, "URI"    ; f.text_field :uri
> %p= f.label :phone         ; f.text_field :phone
> %p= f.label :fax           ; f.text_field :fax
> %p= f.label :purchase_order; f.text_field :purchase_order
>
> But unfortunately that does not work. It looks like the semicolon is
> not supported. Therefore, if I am to preserve the number od lines and
> columns alignment, I am forced to do this:
>
> %p== #{f.label :name}           #{f.text_field :name}
> %p== #{f.label :address}        #{f.text_field :address}
> %p== #{f.label :country}        #{f.text_field :country}
> %p== #{f.label :contact}        #{f.text_field :contact}
> %p== #{f.label :email}          #{f.text_field :email}
> %p== #{f.label :uri, "URI"}     #{f.text_field :uri}
> %p== #{f.label :phone}          #{f.text_field :phone}
> %p== #{f.label :fax}            #{f.text_field :fax}
> %p== #{f.label :purchase_order} #{f.text_field :purchase_order}
>
> And if I want to get rid of all those extra braces, the I have to
> triple the number of lines:
>
>  %p
>    = f.label :name
>    = f.text_field :name
>  %p
>    = f.label :address
>    = f.text_field :address
>  %p
>    = f.label :country
>    = f.text_field :country
>  %p
>    = f.label :contact
>    = f.text_field :contact
>  %p
>    = f.label :email
>    = f.text_field :email
>  %p
>    = f.label :uri, "URI"
>    = f.text_field :uri
>  %p
>    = f.label :phone
>    = f.text_field :phone
>  %p
>    = f.label :fax
>    = f.text_field :fax
>  %p
>    = f.label :purchase_order
>    = f.text_field :purchase_order
>
> So, in summary, I think that HAML is great but if I could use the
> semicolon (or something similar)  it would be better.
>
> Regards,
>
> Gustavo Delfino
> Caracas, Venezuela.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to