class Renderer::Renderer::ColumnsFromBlock
Attributes
columns[RW]
filters[RW]
klass[RW]
table_data[RW]
Public Class Methods
new(klass, table_data_object)
click to toggle source
# File lib/tabulatr/renderer/columns_from_block.rb, line 28 def initialize(klass, table_data_object) @klass = klass @table_data = table_data_object @columns ||= [] @filters ||= [] end
process(klass, table_data_object = nil) { |i| ... }
click to toggle source
# File lib/tabulatr/renderer/columns_from_block.rb, line 79 def self.process(klass, table_data_object = nil, &block) i = self.new(klass, table_data_object) yield(i) i end
Public Instance Methods
action(opts={}, &block)
click to toggle source
# File lib/tabulatr/renderer/columns_from_block.rb, line 57 def action(opts={}, &block) @columns << Action.from(klass: klass, col_options: Tabulatr::ParamsBuilder.new(opts.merge(filter: false, sortable: false)), &block) end
association(table_name, name, opts={}, &block)
click to toggle source
# File lib/tabulatr/renderer/columns_from_block.rb, line 43 def association(table_name, name, opts={}, &block) if table_data @columns << fetch_column_from_table_data(table_name, name, opts, &block) else assoc_klass = klass.reflect_on_association(table_name.to_sym) @columns << Association.from(klass: assoc_klass.try(:klass), name: name, table_name: table_name, col_options: Tabulatr::ParamsBuilder.new(opts), &block) end end
checkbox(opts={})
click to toggle source
# File lib/tabulatr/renderer/columns_from_block.rb, line 53 def checkbox(opts={}) @columns << Checkbox.from(klass: klass, col_options: Tabulatr::ParamsBuilder.new(opts.merge(filter: false, sortable: false))) end
column(name, opts={}, &block)
click to toggle source
# File lib/tabulatr/renderer/columns_from_block.rb, line 35 def column(name, opts={}, &block) if table_data @columns << fetch_column_from_table_data(klass.table_name.to_sym, name, opts, &block) else @columns << Column.from(klass: klass, table_name: klass.table_name.to_sym, name: name, col_options: Tabulatr::ParamsBuilder.new(opts), &block) end end
filter(name, partial: nil, &block)
click to toggle source
# File lib/tabulatr/renderer/columns_from_block.rb, line 70 def filter(name, partial: nil, &block) if table_data found_filter = fetch_filter_from_table_data(name) @filters << found_filter if found_filter.present? else @filters << Tabulatr::Renderer::Filter.new(name, partial: partial, &block) end end
Private Instance Methods
fetch_column_from_table_data(table_name, name, opts={})
click to toggle source
# File lib/tabulatr/renderer/columns_from_block.rb, line 87 def fetch_column_from_table_data table_name, name, opts={}, &block column = table_data.table_columns.find{|tc| tc.table_name == table_name && tc.name == name} column.col_options.update(opts) column.output = block if block_given? column end
fetch_filter_from_table_data(name)
click to toggle source
# File lib/tabulatr/renderer/columns_from_block.rb, line 94 def fetch_filter_from_table_data name table_data.filters.find{|f| f.name.to_sym == name.to_sym} end