Created
April 9, 2009 16:05
-
-
Save lukewendling/92548 to your computer and use it in GitHub Desktop.
add a blueprintcss-based 'to_html' method to Ruby's Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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