Module: Snaptable::Constructor::Renderer
- Included in:
- BaseTable
- Defined in:
- lib/snaptable/constructor/renderer.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #column_names ⇒ Object
- #enums ⇒ Object
- #format(attribute, 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 |
#enums ⇒ Object
47 48 49 |
# File 'lib/snaptable/constructor/renderer.rb', line 47 def enums model.defined_enums.keys end |
#format(attribute, attr_value) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/snaptable/constructor/renderer.rb', line 37 def format(attribute, attr_value) if attr_value.is_a?(Date) || attr_value.is_a?(Time) || attr_value.is_a?(DateTime) l attr_value, format: :snaptable elsif attribute.to_s.in? enums t "#{model.model_name.singular}.#{attribute.to_s.pluralize}.#{attr_value}" 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(attribute, attr_value) end end |