Class: Grapple::BaseTableBuilder
- Inherits:
-
Object
- Object
- Grapple::BaseTableBuilder
- Defined in:
- lib/grapple/base_table_builder.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#columns ⇒ Array<Hash>
readonly
An Array of columns.
-
#namespace ⇒ String
readonly
Namespace for the grapple table.
-
#params ⇒ Object
readonly
Request parameters.
-
#records ⇒ Enumerable
readonly
An Array, ActiveRecord::Collection or Enumerable of records to be displayed in the table.
- #template ⇒ ActionView::Base readonly
Class Method Summary collapse
-
.configure(helper_name, *options) ⇒ Object
Update settings for a helper.
-
.helper(name, klass, settings = {}) ⇒ Object
Create a helper.
Instance Method Summary collapse
-
#after_table ⇒ Object
HTML to insert after the </table> tag.
-
#before_table ⇒ Object
HTML to insert before the <table> tag.
- #container(inner_html) ⇒ Object
-
#default_options ⇒ Hash
Default options for the component.
-
#initialize(template, columns, records, params = {}, *options) ⇒ BaseTableBuilder
constructor
A new instance of BaseTableBuilder.
Constructor Details
#initialize(template, columns, records, params = {}, *options) ⇒ BaseTableBuilder
Returns a new instance of BaseTableBuilder.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/grapple/base_table_builder.rb', line 54 def initialize(template, columns, records, params = {}, *) @template = template @columns = columns @records = records = .merge([0] || {}) @namespace = [:namespace] @params = params @params = @params[@namespace] || {} if @namespace @helper_instances = {} end |
Instance Attribute Details
#columns ⇒ Array<Hash> (readonly)
An Array of columns
39 40 41 |
# File 'lib/grapple/base_table_builder.rb', line 39 def columns @columns end |
#namespace ⇒ String (readonly)
Returns namespace for the grapple table.
52 53 54 |
# File 'lib/grapple/base_table_builder.rb', line 52 def namespace @namespace end |
#params ⇒ Object (readonly)
Request parameters
49 50 51 |
# File 'lib/grapple/base_table_builder.rb', line 49 def params @params end |
#records ⇒ Enumerable (readonly)
An Array, ActiveRecord::Collection or Enumerable of records to be displayed in the table
43 44 45 |
# File 'lib/grapple/base_table_builder.rb', line 43 def records @records end |
#template ⇒ ActionView::Base (readonly)
46 47 48 |
# File 'lib/grapple/base_table_builder.rb', line 46 def template @template end |
Class Method Details
.configure(helper_name, *options) ⇒ Object
Update settings for a helper
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/grapple/base_table_builder.rb', line 26 def self.configure(helper_name, *) settings = [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 = {}) ⇒ Object
Create a helper
11 12 13 14 15 16 17 18 19 |
# File 'lib/grapple/base_table_builder.rb', line 11 def self.helper(name, klass, settings = {}) class_eval "def \#{name}(*arguments, &block)\ninvoke_helper(:\"\#{name}\", *arguments, &block)\nend\n" define_singleton_method(:"class_for_#{name}") { klass } define_singleton_method(:"settings_for_#{name}") { settings } end |
Instance Method Details
#after_table ⇒ Object
HTML to insert after the </table> tag
77 78 79 |
# File 'lib/grapple/base_table_builder.rb', line 77 def after_table '' end |
#before_table ⇒ Object
HTML to insert before the <table> tag
72 73 74 |
# File 'lib/grapple/base_table_builder.rb', line 72 def before_table '' end |
#container(inner_html) ⇒ Object
81 82 83 |
# File 'lib/grapple/base_table_builder.rb', line 81 def container(inner_html) inner_html end |
#default_options ⇒ Hash
Default options for the component
67 68 69 |
# File 'lib/grapple/base_table_builder.rb', line 67 def { } end |