Module: Workbench::TableHelper
- Defined in:
- app/helpers/workbench/table_helper.rb
Overview
Helpers for table rendering
Instance Method Summary collapse
- #copy_table_to_clipboard(selector, offset = 0, message = 'Copy to clipboard') ⇒ Object
- #fancy_edit_tag(object) ⇒ Object
- 
  
    
      #fancy_metadata_cells_tag(object)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Hidden action links data-attributes: data-show data-edit data-delete. 
- #fancy_options_cells_tag(object) ⇒ Object
- #fancy_pin_tag(object) ⇒ Object
- #fancy_show_tag(object) ⇒ Object
- #fancy_th_tag(group: nil, name: '') ⇒ Object
- 
  
    
      #table_from_csv(csv, id: nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Almost certainly not DRY within TW. 
- #table_from_hash_tag(hash) ⇒ Object
Instance Method Details
#copy_table_to_clipboard(selector, offset = 0, message = 'Copy to clipboard') ⇒ Object
| 49 50 51 | # File 'app/helpers/workbench/table_helper.rb', line 49 def copy_table_to_clipboard(selector, offset = 0, = 'Copy to clipboard' ) content_tag(:button, , data: { 'clipboard-table-selector': selector, offset: }, type: 'button') end | 
#fancy_edit_tag(object) ⇒ Object
| 39 40 41 | # File 'app/helpers/workbench/table_helper.rb', line 39 def fancy_edit_tag(object) content_tag(:td, edit_object_link(object), class: 'table-options', data: {edit: true}) end | 
#fancy_metadata_cells_tag(object) ⇒ Object
Hidden action links data-attributes:
data-show
data-edit
data-delete
This is very important, it must be set to make work the options for the context menu. Use the class “.table-options” to hide those options on the table
| 19 20 21 22 23 | # File 'app/helpers/workbench/table_helper.rb', line 19 def (object) content_tag(:td, object_tag(object.updater)) + content_tag(:td, object_time_since_update_tag(object)) + (object) end | 
#fancy_options_cells_tag(object) ⇒ Object
| 25 26 27 28 29 30 31 | # File 'app/helpers/workbench/table_helper.rb', line 25 def (object) m = (object) fancy_show_tag(m) + fancy_edit_tag(m) + fancy_pin_tag(m) + content_tag(:td, (link_to 'Destroy', m, method: :delete, data: {confirm: 'Are you sure?'}), class: 'table-options', data: {delete: true}) end | 
#fancy_pin_tag(object) ⇒ Object
| 43 44 45 46 47 | # File 'app/helpers/workbench/table_helper.rb', line 43 def fancy_pin_tag(object) if object.respond_to?(:pinned?) content_tag(:td, pin_item_to_pinboard_link(object, sessions_current_user), class: 'table-options', data: {pin: true}) end end | 
#fancy_show_tag(object) ⇒ Object
| 33 34 35 36 37 | # File 'app/helpers/workbench/table_helper.rb', line 33 def fancy_show_tag(object) defined?(object.annotated_object) ? content_tag(:td, (link_to 'Show', (object.annotated_object)), class: 'table-options', data: {show: true}) : content_tag(:td, (link_to 'Show', object), class: 'table-options', data: {show: true}) end | 
#fancy_th_tag(group: nil, name: '') ⇒ Object
| 4 5 6 7 8 | # File 'app/helpers/workbench/table_helper.rb', line 4 def fancy_th_tag(group: nil, name: '') content_tag(:th, data: {group: group}) do content_tag(:span, name) end end | 
#table_from_csv(csv, id: nil) ⇒ Object
Almost certainly not DRY within TW
| 65 66 67 68 69 70 71 72 73 | # File 'app/helpers/workbench/table_helper.rb', line 65 def table_from_csv(csv, id: nil) return tag.table if csv.nil? s = "<table id=\"#{id}\">" csv.by_row.each do |r| s << tag.tr( r.fields.collect{|a| tag.td(a)}.join.html_safe) end s << '</table>' s.html_safe end | 
#table_from_hash_tag(hash) ⇒ Object
| 53 54 55 56 57 58 59 60 61 62 | # File 'app/helpers/workbench/table_helper.rb', line 53 def table_from_hash_tag(hash) tag.table do hash.collect do |k,v| tag.tr do concat(tag.td(k)) concat(tag.td(tag.strong(v))) end end.join.html_safe end end |