forked from cldwalker/hirb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cldwalker#5: added vertical table helper thanks to @chrononaut
- Loading branch information
Showing
5 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Hirb::Helpers::VerticalTable < Hirb::Helpers::Table | ||
|
||
# Renders a vertical table using the same options as Hirb::Helpers::Table.render except for :field_lengths, | ||
# :vertical and :max_width which aren't used. | ||
def self.render(rows, options={}) | ||
new(rows, options).render | ||
end | ||
|
||
#:stopdoc: | ||
def setup_field_lengths | ||
@field_lengths = default_field_lengths | ||
end | ||
|
||
def render_header; []; end | ||
def render_footer; []; end | ||
|
||
def render_rows | ||
i = 0 | ||
longest_header = @headers.values.sort_by {|e| e.length}.last.length | ||
stars = "*" * [(longest_header + (longest_header / 2)), 3].max | ||
@rows.map do |row| | ||
row = "#{stars} #{i+1}. row #{stars}\n" + | ||
@fields.map {|f| | ||
"#{@headers[f].rjust(longest_header)}: #{row[f]}" | ||
}.join("\n") | ||
i+= 1 | ||
row | ||
end | ||
#:startdoc: | ||
end | ||
end |
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