Class: ActiveGrid::Grid
- Inherits:
-
Object
- Object
- ActiveGrid::Grid
- Defined in:
- app/lib/active_grid/grid.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#partial ⇒ Object
readonly
Returns the value of attribute partial.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #body ⇒ Object
- #column(name, options = {}, &block) ⇒ Object
- #filters ⇒ Object
- #header ⇒ Object
-
#initialize(view, name, scope, partial, options = {}) ⇒ Grid
constructor
A new instance of Grid.
- #mode(value = nil, &block) ⇒ Object
- #models ⇒ Object
- #tag_options ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(view, name, scope, partial, options = {}) ⇒ Grid
Returns a new instance of Grid.
6 7 8 9 10 11 12 |
# File 'app/lib/active_grid/grid.rb', line 6 def initialize(view, name, scope, partial, = {}) @columns = [] @view, @name, @scope, @partial, @options = view, name, scope, partial, self.view._activegrid = self self.view.render(partial) end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
4 5 6 |
# File 'app/lib/active_grid/grid.rb', line 4 def block @block end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
3 4 5 |
# File 'app/lib/active_grid/grid.rb', line 3 def columns @columns end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'app/lib/active_grid/grid.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'app/lib/active_grid/grid.rb', line 3 def @options end |
#partial ⇒ Object (readonly)
Returns the value of attribute partial.
3 4 5 |
# File 'app/lib/active_grid/grid.rb', line 3 def partial @partial end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
3 4 5 |
# File 'app/lib/active_grid/grid.rb', line 3 def scope @scope end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
3 4 5 |
# File 'app/lib/active_grid/grid.rb', line 3 def view @view end |
Instance Method Details
#body ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/lib/active_grid/grid.rb', line 26 def body mode :body do models.map do |model| view.content_tag(:tr, view.capture(self, model, &block)) end.reduce(:<<) end end |
#column(name, options = {}, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/lib/active_grid/grid.rb', line 34 def column(name, = {}, &block) column = Column.new(view, name, , &block) case mode when :header columns << column view.content_tag(:th, column.header, column.) when :filter view.content_tag(:th, column.filter) when :body view.content_tag(:td, column.value) end end |
#filters ⇒ Object
20 21 22 23 24 |
# File 'app/lib/active_grid/grid.rb', line 20 def filters mode :filter do view.content_tag(:tr, view.capture(self, nil, &block)) end end |
#header ⇒ Object
14 15 16 17 18 |
# File 'app/lib/active_grid/grid.rb', line 14 def header mode :header do view.content_tag(:tr, view.capture(self, nil, &block)) end end |
#mode(value = nil, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/lib/active_grid/grid.rb', line 48 def mode(value = nil, &block) if value begin old_mode, @mode = @mode, value yield ensure @mode = old_mode end else @mode end end |
#models ⇒ Object
61 62 63 64 65 66 67 |
# File 'app/lib/active_grid/grid.rb', line 61 def models if paginate = [:paginate] scope.limit(paginate) else scope end end |
#tag_options ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/lib/active_grid/grid.rb', line 69 def = {} ["id"] = "#{name}_grid" ["class"] = "activegrid" ["data-activegrid"] = true ["data-activegrid-name"] = name if [:paginate] ["data-activegrid-pages"] = (scope.count / [:paginate].to_f).ceil ["data-activegrid-paginate"] = [:paginate] end end |
#to_html ⇒ Object
84 85 86 87 88 |
# File 'app/lib/active_grid/grid.rb', line 84 def to_html view.content_tag(:table, ) do view.content_tag(:thead, header << filters) << view.content_tag(:tbody, body) end end |