Sha256: 27a46212c08f996bd8e722beca63c248489672b170933bec0074f2b5fdeef549

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

module Snaptable
  module Constructor    
    module Renderer

      def present(buttons: nil)
        render_to_string('/snaptable/base', layout: false, locals: { presenter: self, buttons: buttons}).html_safe
      end

      def respond
        respond_to do |format|
          format.html
          format.js { render '/snaptable/sort' }
        end
      end

      def attributes
        model.attribute_names
      end

      def column_names
        attributes.map do |a|
          (a.is_a?(Hash) ? a.keys[0] : a).to_s
        end
      end

      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

      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

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
snaptable-0.6.4 lib/snaptable/constructor/renderer.rb
snaptable-0.6.3 lib/snaptable/constructor/renderer.rb
snaptable-0.6.1 lib/snaptable/constructor/renderer.rb
snaptable-0.6.0 lib/snaptable/constructor/renderer.rb
snaptable-0.5.1 lib/snaptable/constructor/renderer.rb
snaptable-0.5.0 lib/snaptable/constructor/renderer.rb