class Grapple::BaseTableBuilder
Attributes
columns[R]
An Array of columns @return [Array<Hash>]
namespace[R]
@return [String] namespace for the grapple table
params[R]
Request parameters
records[R]
An Array, ActiveRecord::Collection or Enumerable of records to be displayed in the table @return [Enumerable]
template[R]
@return [ActionView::Base]
Public Class Methods
configure(helper_name, *options)
click to toggle source
Update settings for a helper @param helper_name [Symbol]
The name of the helper
@param options [Hash]
Settings to update for the component
# File lib/grapple/base_table_builder.rb, line 26 def self.configure(helper_name, *options) settings = options[0] || {} method = :"settings_for_#{helper_name}" if self.respond_to?(method) self.send(method).each do |key, value| settings[key] = value unless settings.has_key?(key) end end define_singleton_method(method) { settings } end
helper(name, klass, settings = {})
click to toggle source
Create a helper @param name [Symbol]
The name of the helper
@param klass [Grapple::Components::BaseComponent]
The component class
@param settings [Hash]
Settings for the component
# File lib/grapple/base_table_builder.rb, line 11 def self.helper(name, klass, settings = {}) class_eval <<-RUBY_EVAL def #{name}(*arguments, &block) invoke_helper(:"#{name}", *arguments, &block) end RUBY_EVAL define_singleton_method(:"class_for_#{name}") { klass } define_singleton_method(:"settings_for_#{name}") { settings } end
new(template, columns, records, params = {}, *options)
click to toggle source
# File lib/grapple/base_table_builder.rb, line 54 def initialize(template, columns, records, params = {}, *options) @template = template @columns = columns @records = records @options = default_options.merge(options[0] || {}) @namespace = @options[:namespace] @params = params @params = @params[@namespace] || {} if @namespace @helper_instances = {} end
Public Instance Methods
after_table()
click to toggle source
HTML to insert after the </table> tag
# File lib/grapple/base_table_builder.rb, line 77 def after_table '' end
before_table()
click to toggle source
HTML to insert before the <table> tag
# File lib/grapple/base_table_builder.rb, line 72 def before_table '' end
container(inner_html)
click to toggle source
# File lib/grapple/base_table_builder.rb, line 81 def container(inner_html) inner_html end
default_options()
click to toggle source
Default options for the component @return [Hash]
# File lib/grapple/base_table_builder.rb, line 67 def default_options { } end
Protected Instance Methods
invoke_helper(name, *arguments, &block)
click to toggle source
# File lib/grapple/base_table_builder.rb, line 87 def invoke_helper(name, *arguments, &block) unless @helper_instances.has_key?(name) klass = self.class.send(:"class_for_#{name}") settings = self.class.send(:"settings_for_#{name}") @helper_instances[name] = klass.new(@columns, @records, @template, @params, self, settings) end @helper_instances[name].send(:render, *arguments, &block) end