Skip to content

Commit

Permalink
Add column formatters to html report and fixup when col_data doesn't …
Browse files Browse the repository at this point in the history
…respond to @DaTa
  • Loading branch information
elskwid committed May 22, 2009
1 parent 03b69c3 commit 237e4d3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
31 changes: 26 additions & 5 deletions lib/munger/render/html.rb
Expand Up @@ -5,8 +5,8 @@
require 'builder'
end

module Munger #:nodoc:
module Render #:nodoc:
module Munger
module Render
class Html

attr_reader :report, :classes
Expand Down Expand Up @@ -50,7 +50,7 @@ def render

x.tr(row_attrib) do
if row[:meta][:group_header]
header = row[:meta][:group_value].to_s
header = @report.column_title(row[:meta][:group_name]) + ' : ' + row[:meta][:group_value].to_s
x.th(:colspan => @report.columns.size) { x << header }
else
@report.columns.each do |column|
Expand All @@ -63,7 +63,28 @@ def render
end
end

x.td(cell_attrib) { x << row[:data][column].to_s }
# x.td(cell_attrib) { x << row[:data][column].to_s }
# TODO: Clean this up, I don't like it but it's working
# output the cell
# x.td(cell_attrib) { x << row[:data][column].to_s }
x.td(cell_attrib) do
formatter,*args = *@report.column_formatter(column)
col_data = row[:data] #[column]
if formatter && col_data[column]
formatted = if formatter.class == Proc
data = col_data.respond_to?(:data) ? col_data.data : col_data
formatter.call(data)
elsif col_data[column].respond_to? formatter
col_data[column].send(formatter, *args)
elsif
col_data[column].to_s
end
else
formatted = col_data[column].to_s
end
x << formatted.to_s
end

end
end
end
Expand All @@ -86,4 +107,4 @@ def valid?

end
end
end
end
7 changes: 4 additions & 3 deletions lib/munger/render/sortable_html.rb
@@ -1,6 +1,6 @@
require 'builder'
module Munger #:nodoc:
module Render #:nodoc:
module Munger
module Render
# Render a table that lets the user sort the columns
class SortableHtml

Expand Down Expand Up @@ -87,7 +87,8 @@ def render
col_data = row[:data] #[column]
if formatter && col_data[column]
formatted = if formatter.class == Proc
formatter.call(col_data.data)
data = col_data.respond_to?(:data) ? col_data.data : col_data
formatter.call(data)
elsif col_data[column].respond_to? formatter
col_data[column].send(formatter, *args)
elsif
Expand Down

0 comments on commit 237e4d3

Please sign in to comment.