Module: Tableficate::Helper
- Defined in:
- lib/tableficate/helper.rb
Instance Method Summary collapse
- #table_for(rows, options = {}) {|t| ... } ⇒ Object
- #tableficate_check_box_tags(filter, &block) ⇒ Object
- #tableficate_data_tag(row, column) ⇒ Object
- #tableficate_filter_tag(filter) ⇒ Object
- #tableficate_header_tag(column) ⇒ Object
- #tableficate_label_tag(filter) ⇒ Object
- #tableficate_radio_tags(filter, &block) ⇒ Object
- #tableficate_row_tag(row, columns) ⇒ Object
- #tableficate_select_tag(filter) ⇒ Object
- #tableficate_text_field_tag(filter) ⇒ Object
Instance Method Details
#table_for(rows, options = {}) {|t| ... } ⇒ Object
3 4 5 6 7 |
# File 'lib/tableficate/helper.rb', line 3 def table_for(rows, = {}) t = Tableficate::Table.new(self, rows, , rows.tableficate_get_data) yield(t) t.render end |
#tableficate_check_box_tags(filter, &block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/tableficate/helper.rb', line 79 def (filter, &block) field_value = filter.field_value(params[filter.table.as]) collection = Tableficate::Filter::Collection.new(filter.[:collection], selected: filter.field_value(params[filter.table.as])) html = [] if block_given? html = collection.map {|choice| capture(choice, &block)} else collection.each do |choice| html.push( check_box_tag( "#{filter.field_name}[#{choice.value}]", choice.value, choice.checked?, choice..reverse_merge(name: "#{filter.field_name}[]") ), label_tag("#{filter.field_name}[#{choice.value}]", choice.name), '<br/>' ) end end html.join("\n").html_safe end |
#tableficate_data_tag(row, column) ⇒ Object
13 14 15 |
# File 'lib/tableficate/helper.rb', line 13 def tableficate_data_tag(row, column) render partial: Tableficate::Utils::template_path('data', column.table.[:theme]), locals: {row: row, column: column} end |
#tableficate_filter_tag(filter) ⇒ Object
21 22 23 |
# File 'lib/tableficate/helper.rb', line 21 def tableficate_filter_tag(filter) render partial: Tableficate::Utils::template_path(filter.template, filter.table.[:theme]), locals: {filter: filter} end |
#tableficate_header_tag(column) ⇒ Object
9 10 11 |
# File 'lib/tableficate/helper.rb', line 9 def tableficate_header_tag(column) render partial: Tableficate::Utils::template_path('header', column.table.[:theme]), locals: {column: column} end |
#tableficate_label_tag(filter) ⇒ Object
25 26 27 |
# File 'lib/tableficate/helper.rb', line 25 def tableficate_label_tag(filter) label_tag(filter.field_name, filter.label, filter.[:label_options]) end |
#tableficate_radio_tags(filter, &block) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tableficate/helper.rb', line 58 def (filter, &block) field_value = filter.field_value(params[filter.table.as]) collection = Tableficate::Filter::Collection.new(filter.[:collection], selected: filter.field_value(params[filter.table.as])) html = [] if block_given? html = collection.map {|choice| capture(choice, &block)} else collection.each do |choice| html.push( (filter.field_name, choice.value, choice.checked?, choice.), label_tag("#{filter.field_name}[#{choice.value}]", choice.name), '<br/>' ) end end html.join("\n").html_safe end |
#tableficate_row_tag(row, columns) ⇒ Object
17 18 19 |
# File 'lib/tableficate/helper.rb', line 17 def tableficate_row_tag(row, columns) render partial: Tableficate::Utils::template_path('row', columns.first.table.[:theme]), locals: {row: row, columns: columns} end |
#tableficate_select_tag(filter) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tableficate/helper.rb', line 33 def tableficate_select_tag(filter) field_value = filter.field_value(params[filter.table.as]) if field_value.present? and filter.[:collection].is_a?(String) Array.wrap(field_value).each do |fv| if filter.[:collection].match(/<option[^>]*value\s*=/) filter.[:collection].gsub!(/(<option[^>]*value\s*=\s*['"]?#{fv}[^>]*)/, '\1 selected="selected"') else filter.[:collection].gsub!(/>#{fv}</, " selected=\"selected\">#{fv}<") end end elsif not filter.[:collection].is_a?(String) filter.[:collection] = Tableficate::Filter::Collection.new(filter.[:collection], selected: field_value).map {|choice| html_attributes = choice..length > 0 ? ' ' + choice..map {|k, v| %(#{k.to_s}="#{v}")}.join(' ') : '' selected_attribute = choice.selected? ? ' selected="selected"' : '' %(<option value="#{ERB::Util.html_escape(choice.value)}"#{selected_attribute}#{html_attributes}>#{ERB::Util.html_escape(choice.name)}</option>) }.join("\n") end filter.[:collection] = filter.[:collection].html_safe select_tag(filter.field_name, filter..delete(:collection), filter.) end |
#tableficate_text_field_tag(filter) ⇒ Object
29 30 31 |
# File 'lib/tableficate/helper.rb', line 29 def tableficate_text_field_tag(filter) text_field_tag(filter.field_name, filter.field_value(params[filter.table.as]), filter.) end |