Class: Tableficate::Table
- Inherits:
-
Object
- Object
- Tableficate::Table
- Defined in:
- lib/tableficate/table.rb
Instance Attribute Summary collapse
-
#as ⇒ Object
readonly
Returns the value of attribute as.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#current_sort ⇒ Object
readonly
Returns the value of attribute current_sort.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #actions(&block) ⇒ Object
- #column(name, options = {}, &block) ⇒ Object
- #filter(name, options = {}) ⇒ Object
- #filter_range(name, options = {}) ⇒ Object
-
#initialize(template, rows, options, data) ⇒ Table
constructor
A new instance of Table.
- #render(options = {}) ⇒ Object
- #show_sort? ⇒ Boolean
Constructor Details
#initialize(template, rows, options, data) ⇒ Table
Returns a new instance of Table.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tableficate/table.rb', line 5 def initialize(template, rows, , data) @template = template @rows = rows @columns = [] @filters = [] @as = [:as] || rows.table_name @options = { show_sorts: false, theme: '' }.merge() @current_sort = data[:current_sort] end |
Instance Attribute Details
#as ⇒ Object (readonly)
Returns the value of attribute as.
3 4 5 |
# File 'lib/tableficate/table.rb', line 3 def as @as end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
3 4 5 |
# File 'lib/tableficate/table.rb', line 3 def columns @columns end |
#current_sort ⇒ Object (readonly)
Returns the value of attribute current_sort.
3 4 5 |
# File 'lib/tableficate/table.rb', line 3 def current_sort @current_sort end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
3 4 5 |
# File 'lib/tableficate/table.rb', line 3 def filters @filters end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/tableficate/table.rb', line 3 def @options end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
3 4 5 |
# File 'lib/tableficate/table.rb', line 3 def rows @rows end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
3 4 5 |
# File 'lib/tableficate/table.rb', line 3 def template @template end |
Instance Method Details
#actions(&block) ⇒ Object
28 29 30 |
# File 'lib/tableficate/table.rb', line 28 def actions(&block) @columns.push(ActionColumn.new(self, &block)) end |
#column(name, options = {}, &block) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/tableficate/table.rb', line 20 def column(name, = {}, &block) .reverse_merge!( show_sort: @options[:show_sorts] ) @columns.push(Column.new(self, name, , &block)) end |
#filter(name, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tableficate/table.rb', line 36 def filter(name, = {}) as_map = { :'datetime-local' => Filter::Input, text: Filter::Input, email: Filter::Input, url: Filter::Input, tel: Filter::Input, number: Filter::Input, range: Filter::Input, date: Filter::Input, month: Filter::Input, week: Filter::Input, time: Filter::Input, datetime: Filter::Input, search: Filter::Input, color: Filter::Input, select: Filter::Select, radio: Filter::Radio, checkbox: Filter::CheckBox } as = .delete(:as) || ([:collection] ? :select : :text) raise Filter::UnknownInputType if as_map[as].nil? [:type] = as.to_s @filters.push(as_map[as].new(self, name, )) end |
#filter_range(name, options = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/tableficate/table.rb', line 66 def filter_range(name, = {}) as_map = { :'datetime-local' => Filter::InputRange, text: Filter::InputRange, email: Filter::InputRange, url: Filter::InputRange, tel: Filter::InputRange, number: Filter::InputRange, range: Filter::InputRange, date: Filter::InputRange, month: Filter::InputRange, week: Filter::InputRange, time: Filter::InputRange, datetime: Filter::InputRange, search: Filter::InputRange, color: Filter::InputRange, select: Filter::SelectRange } as = .delete(:as) || ([:collection] ? :select : :text) raise Filter::UnknownInputType if as_map[as].nil? [:type] = as.to_s @filters.push(as_map[as].new(self, name, )) end |
#render(options = {}) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/tableficate/table.rb', line 94 def render( = {}) .reverse_merge!( partial: Tableficate::Utils::template_path('table', @options[:theme]), locals: {table: self} ) @template.render end |
#show_sort? ⇒ Boolean
32 33 34 |
# File 'lib/tableficate/table.rb', line 32 def show_sort? self.columns.any?{|column| column.show_sort?} end |