class TableHelp::AttributesTableFor
Attributes
context[R]
options[R]
resource[R]
rows[R]
Public Class Methods
new(resource, context, options = {})
click to toggle source
# File lib/table_help/attributes_table_for.rb, line 6 def initialize(resource, context, options = {}) @resource = resource @context = context @options = default_options.merge(options) @rows = [] end
Public Instance Methods
row(name = nil, method_name = nil, &block)
click to toggle source
# File lib/table_help/attributes_table_for.rb, line 13 def row(name = nil, method_name = nil, &block) rows << [ Formatter.format_attribute_name(name, resource), Strategy.new(name, block_given? ? block : method_name), ] end
to_html()
click to toggle source
# File lib/table_help/attributes_table_for.rb, line 20 def to_html return if resource.nil? tag.table(tbody, options) end
Private Instance Methods
default_options()
click to toggle source
# File lib/table_help/attributes_table_for.rb, line 40 def default_options TableHelp.config.default_options[:attributes_table_for] || {} end
tbody()
click to toggle source
# File lib/table_help/attributes_table_for.rb, line 27 def tbody tag.tbody do rows.each do |attr_name, strategy| concat( tag.tr do concat tag.th(attr_name) concat tag.td(Formatter.format_value(strategy.name, strategy.to_value(resource, context)), class: "col-#{strategy.name}") end, ) end end end