Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

85 lines (69 sloc) 1.905 kB
module TableCloth
class Presenter
attr_reader :view_context, :table_definition, :objects,
:table
def initialize(objects, table, view)
@objects = objects
@table_definition = table
@view_context = view
@table = table_definition.new(objects, view)
end
def render_table
raise NoMethodError, "You must override the .render method"
end
def render_header
raise NoMethodError, "You must override the .header method"
end
def render_rows
raise NoMethodError, "You must override the .rows method"
end
def columns
@columns ||= table.class.columns.map do |name, options|
column = options[:class].new(name, options[:options])
if ColumnJury.new(column, table).available?
column
else
nil
end
end.compact
end
def column_names
@column_names ||= columns.each_with_object([]) do |column, names|
names << column.human_name(view_context)
end
end
def row_values(object)
columns.each_with_object([]) do |column, values|
values << column.value(object, view_context, table)
end
end
def rows
objects.each_with_object([]) do |object, row|
row << row_values(object)
end
end
def wrapper_tag(type, value=nil, options={}, &block)
options = tag_options(type, options)
content = if block_given?
v.content_tag(type, options, &block)
else
v.content_tag(type, value, options)
end
end
private
def tag_options(type, options={})
options = options.dup
if TableCloth.config.respond_to?(type)
options.merge!(table.config.config_for(type))
options.merge!(TableCloth.config.config_for(type))
end
options
end
def v
view_context
end
def params
v.params
end
end
end
Jump to Line
Something went wrong with that request. Please try again.