This is something I cooked up today, because of a project I've been working on.

I'm always having to struggle a little bit to get my helpers
generating decent xhtml. Helpers are the next big thing that we have
to figure out as a community. That is, to answer the question, how can
I build really compelling views with some nice programatic logic that
is modularized into the helpers.

Well, here is a step foreward. Its something like content_tag, except
mixes in some Haml magic.

I wanted to have this in my view.

- info_table do
  - row :price do
    Price (in CAN dollars)
  - row :name do
    Name of the product

The reason I'm using blocks is because I really wanted to be able to
easily drop in programmatic things (like hidden fields, javascript
bits, and etc) into the page without having to concern myself with
doing it repeatedly. I don't know if this makes sense, but each row
would actually automatically generate the form elements needed for
that row. The block area just serves as a label-generator.

Let's see how we'd implement this with open_tag

def info_table(&block)
  open_tag :table, &block
end

def row(named, &block)
  open_tag :tr do
    open_tag :td do
      block.call
    end
    open_tag :td do
      push_text form.text_field(named)
      open_tag :div, :class => "errors" do
        error_messages_on :project, named
      end
    end
  end
end

So much automatic goodness built right in! And its not even ugly!

Thoughts?

-hampton.

PS: open_tag most likely has a bevy of bugs, so please.... report
away! I wrote it in 5 minutes.

--~--~---------~--~----~------------~-------~--~----~
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