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.
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#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.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Instance Method Summary collapse
- #actions(options = {}, &block) ⇒ Object
- #caption(*args, &block) ⇒ Object
- #column(name, options = {}, &block) ⇒ Object
- #empty(*args, &block) ⇒ Object
- #filter(name, options = {}) ⇒ Object
- #filter_range(name, options = {}) ⇒ Object
-
#initialize(template, rows, options, data) ⇒ Table
constructor
A new instance of Table.
- #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 19 |
# File 'lib/tableficate/table.rb', line 5 def initialize(template, rows, , data) @template = template @rows = rows @as = .delete(:as) || rows.table_name @theme = .delete(:theme) || '' @show_sorts = .delete(:show_sorts) || false @attrs = @columns = [] @filters = [] @current_sort = data[:current_sort] @field_map = data[:field_map] || {} 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 |
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
3 4 5 |
# File 'lib/tableficate/table.rb', line 3 def attrs @attrs 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 |
#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 |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
3 4 5 |
# File 'lib/tableficate/table.rb', line 3 def theme @theme end |
Instance Method Details
#actions(options = {}, &block) ⇒ Object
41 42 43 |
# File 'lib/tableficate/table.rb', line 41 def actions( = {}, &block) @columns.push(ActionColumn.new(self, , &block)) end |
#caption(*args, &block) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/tableficate/table.rb', line 29 def (*args, &block) if args.empty? and not block_given? @caption else @caption = Caption.new(*args, &block) end end |
#column(name, options = {}, &block) ⇒ Object
37 38 39 |
# File 'lib/tableficate/table.rb', line 37 def column(name, = {}, &block) @columns.push(Column.new(self, name, .reverse_merge(show_sort: @show_sorts), &block)) end |
#empty(*args, &block) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/tableficate/table.rb', line 21 def empty(*args, &block) if args.empty? and not block_given? @empty else @empty = Empty.new(self, *args, &block) end end |
#filter(name, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tableficate/table.rb', line 49 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) || find_as(name, .has_key?(:collection)) 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
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/tableficate/table.rb', line 79 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) || find_as(name, .has_key?(:collection)) raise Filter::UnknownInputType if as_map[as].nil? [:type] = as.to_s @filters.push(as_map[as].new(self, name, )) end |
#show_sort? ⇒ Boolean
45 46 47 |
# File 'lib/tableficate/table.rb', line 45 def show_sort? self.columns.any?{|column| column.show_sort?} end |