module Haml::Helpers
def list_of(enum, opts={}, &block)
- Yieldparam: item - An element of `enum`
Other tags:
- Yield: - A block which contains Haml code that goes within list items
Parameters:
-
opts(Enumerable<#to_s,#to_s>) -- Each key/value pair will become an attribute pair for each list item element. -
enum(Enumerable) -- The list of objects to iterate over
def list_of(enum, opts={}, &block) opts_attributes = opts.empty? ? "" : " ".<<(opts.map{|k,v| "#{k}='#{v}'" }.join(" ")) to_return = enum.collect do |i| result = capture_haml(i, &block) if result.count("\n") > 1 result = result.gsub("\n", "\n ") result = "\n #{result.strip}\n" else result = result.strip end %Q!<li#{opts_attributes}>#{result}</li>! end to_return.join("\n") end