Class: MightyGrid::GridRenderer
- Inherits:
-
Object
- Object
- MightyGrid::GridRenderer
- Defined in:
- lib/mighty_grid/grid_renderer.rb
Instance Attribute Summary collapse
-
#blank_slate_handler ⇒ Object
readonly
Returns the value of attribute blank_slate_handler.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#row_attributes_handler ⇒ Object
readonly
Returns the value of attribute row_attributes_handler.
-
#th_columns ⇒ Object
readonly
Returns the value of attribute th_columns.
Instance Method Summary collapse
- #actions(opts = {}) ⇒ Object
- #blank_slate(html_or_opts = nil, &block) ⇒ Object
- #column(attr_or_options = {}, options = nil, &block) ⇒ Object
-
#initialize(grid, view) ⇒ GridRenderer
constructor
A new instance of GridRenderer.
- #row_attributes(&block) ⇒ Object
- #total_columns ⇒ Object
Constructor Details
#initialize(grid, view) ⇒ GridRenderer
Returns a new instance of GridRenderer.
5 6 7 8 9 10 11 |
# File 'lib/mighty_grid/grid_renderer.rb', line 5 def initialize(grid, view) @grid = grid @columns = [] @th_columns = [] @blank_slate_handler = nil @row_attributes_handler = proc {} end |
Instance Attribute Details
#blank_slate_handler ⇒ Object (readonly)
Returns the value of attribute blank_slate_handler.
3 4 5 |
# File 'lib/mighty_grid/grid_renderer.rb', line 3 def blank_slate_handler @blank_slate_handler end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
3 4 5 |
# File 'lib/mighty_grid/grid_renderer.rb', line 3 def columns @columns end |
#row_attributes_handler ⇒ Object (readonly)
Returns the value of attribute row_attributes_handler.
3 4 5 |
# File 'lib/mighty_grid/grid_renderer.rb', line 3 def row_attributes_handler @row_attributes_handler end |
#th_columns ⇒ Object (readonly)
Returns the value of attribute th_columns.
3 4 5 |
# File 'lib/mighty_grid/grid_renderer.rb', line 3 def th_columns @th_columns end |
Instance Method Details
#actions(opts = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mighty_grid/grid_renderer.rb', line 36 def actions(opts = {}) = { partial: 'mighty_grid/actions', only: [:show, :edit, :destroy], html: {}, th_html: {}, title: I18n.t('mighty_grid.actions', default: 'Actions') } opts.assert_valid_keys(.keys) .merge!(opts) @columns << MightyGrid::Column.new() { |object| @grid.controller.render_to_string(partial: [:partial], locals: { actions: [:only], object: object }) } end |
#blank_slate(html_or_opts = nil, &block) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/mighty_grid/grid_renderer.rb', line 55 def blank_slate(html_or_opts = nil, &block) if (html_or_opts.is_a?(Hash) && html_or_opts.key?(:partial) || html_or_opts.is_a?(String)) && !block_given? @blank_slate_handler = html_or_opts elsif html_or_opts.nil? && block_given? @blank_slate_handler = block else fail MightyGrid::Exceptions::ArgumentError.new("blank_slate accepts only a string, a block, or :partial => 'path_to_partial' ") end end |
#column(attr_or_options = {}, options = nil, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mighty_grid/grid_renderer.rb', line 13 def column( = {}, = nil, &block) if .is_a?(Hash) = .symbolize_keys else attribute = .to_sym = {} unless .is_a?(Hash) end if attribute.present? = { ordering: true, attribute: attribute, title: @grid.klass.human_attribute_name(attribute) }.merge!() end if block_given? @columns << MightyGrid::Column.new(, &block) else @columns << MightyGrid::Column.new() end end |
#row_attributes(&block) ⇒ Object
51 52 53 |
# File 'lib/mighty_grid/grid_renderer.rb', line 51 def row_attributes(&block) @row_attributes_handler = block if block_given? end |
#total_columns ⇒ Object
65 66 67 |
# File 'lib/mighty_grid/grid_renderer.rb', line 65 def total_columns @columns.count end |