I've had my go at this helper, and revamped it a little. It's now called just "open," and it indents stuff properly, but aside from that it's the same.
This has also prompted the creation of another helper, called "puts." It works much like the IO method (although it's not the same thing): it outputs some text followed by a newline to the output buffer. Unlike the "concat" helper, though, it properly indents the text - you should use this if you need to output anything tabulated to the Haml buffer and you can't just return it from a helper. - Nathan hampton c wrote: > Just a quick note. > > The output is currently ugly and I don't have time to tweak it much > more. So, if anyone has a patch to implement it correctly, just send > it in and we'll fix it. > > Otherwise, Nathan is a wiz with the Buffer object, so I'm sure he can > fix it in 20 seconds. > > -hampton. > > On Mar 14, 11:59 am, Hampton <[EMAIL PROTECTED]> wrote: > >> 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 -~----------~----~----~----~------~----~------~--~---
