Skip to content

Instantly share code, notes, and snippets.

@lukewendling
Created April 9, 2009 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukewendling/92548 to your computer and use it in GitHub Desktop.
Save lukewendling/92548 to your computer and use it in GitHub Desktop.
add a blueprintcss-based 'to_html' method to Ruby's Array
class Array
# wrap elements in blueprintcss-oriented div tags
# ex. results.to_blueprint_html('span', 2, 10, 4, 8)
def to_blueprint_html(css_class, *args)
raise ArgumentError, "args count doesn't match number of elements" if args.size != self.size
output = []
each_with_index do |item, index|
output << "<div class='#{css_class}-#{args[index]}'>#{item}</div>"
end
output.last.gsub!(/'>/, " last'>") # last element should have 'last' class assigned
output.join("\n")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment