In a post 2+ years ago[1], Nathan discusses creating a helper to
implemented recursively nested output. I am generating a table of
contents from a strict hierarchy of 'page' nodes. Here's what I have
so far:

  # In some .rb file somewhere
  # page.pages is an array of page items
  module Haml::Helpers
    def li_pages_for( page )
      page.pages.each do |child|
        haml_tag :li do
          haml_concat child.title
          unless child.leaf?
            haml_tag :ul do
              li_pages_for child
            end
          end
        end
      end
    end
  end

  # In my template:
  !!! Strict
  %html
    %head
      ...
    %body
      %ul#toc
        - li_pages_for toc

This is working well. The only oddity is that I'm initializing the
Haml template with :ugly=>true, but the produced HTML—just for this
helper—is being indented and nested nicely. Do helpers using haml_tag
not honor the :ugly setting?

[1]
http://groups.google.com/group/haml/tree/browse_frm/thread/fc0242990afc0420/a270cc3a0245bda7?rnum=1&q=recursive&_done=%2Fgroup%2Fhaml%2Fbrowse_frm%2Fthread%2Ffc0242990afc0420%3Ftvc%3D1%26q%3Drecursive%26#doc_438e3909ca76752d
-- 
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