Module: Snaptable::Constructor::Renderer
- Included in:
- BaseTable
- Defined in:
- lib/snaptable/constructor/renderer.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #column_names ⇒ Object
- #format_if_date(attr_value) ⇒ Object
- #present(buttons: nil) ⇒ Object
- #respond ⇒ Object
- #values(element) ⇒ Object
Instance Method Details
#attributes ⇒ Object
16 17 18 |
# File 'lib/snaptable/constructor/renderer.rb', line 16 def attributes model.attribute_names end |
#column_names ⇒ Object
20 21 22 23 24 |
# File 'lib/snaptable/constructor/renderer.rb', line 20 def column_names attributes.map do |a| (a.is_a?(Hash) ? a.keys[0] : a).to_s end end |
#format_if_date(attr_value) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/snaptable/constructor/renderer.rb', line 37 def format_if_date(attr_value) if attr_value.is_a?(Date) || attr_value.is_a?(Time) || attr_value.is_a?(DateTime) attr_value.strftime("%d.%m.%y %H:%M") else attr_value end.to_s end |
#present(buttons: nil) ⇒ Object
5 6 7 |
# File 'lib/snaptable/constructor/renderer.rb', line 5 def present(buttons: nil) render_to_string('/snaptable/base', layout: false, locals: { presenter: self, buttons: }).html_safe end |
#respond ⇒ Object
9 10 11 12 13 14 |
# File 'lib/snaptable/constructor/renderer.rb', line 9 def respond respond_to do |format| format.html format.js { render '/snaptable/sort' } end end |
#values(element) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/snaptable/constructor/renderer.rb', line 26 def values(element) attributes.map do |attribute| attr_value = if attribute.is_a?(Symbol) || attribute.is_a?(String) element.send(attribute) else element.send(*attribute.keys).send(*attribute.values) end format_if_date(attr_value) end end |