class Admino::Table::Presenter
Attributes
collection_klass[R]
query[R]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/admino/table/presenter.rb, line 32 def initialize(*args) context = args.pop collection = args.shift @collection_klass = args.shift if !@collection_klass && !collection.empty? @collection_klass = collection.first.class end @query = args.shift super(collection, context) end
tag_helper(name, tag, options = {})
click to toggle source
# File lib/admino/table/presenter.rb, line 11 def self.tag_helper(name, tag, options = {}) options_method = :"#{name}_html_options" define_method :"#{name}_tag" do |*args, &block| options = args.extract_options! if respond_to?(options_method, true) default_options = send(options_method, *args) html_options = Showcase::Helpers::HtmlOptions.new(default_options) html_options.merge_attrs!(options) options = html_options.to_h end h.content_tag(tag, options, &block) end end
Public Instance Methods
to_html(options = {}, &block)
click to toggle source
# File lib/admino/table/presenter.rb, line 47 def to_html(options = {}, &block) if @collection_klass.nil? raise ArgumentError, 'collection is empty and no explicit class is specified' end table_tag(options) do thead_tag do thead_tr_tag do th_tags(&block) end end << tbody_tag do tbody_tr_tags(&block) end end end
Private Instance Methods
base_tbody_tr_html_options(resource, index)
click to toggle source
# File lib/admino/table/presenter.rb, line 104 def base_tbody_tr_html_options(resource, index) options = { class: zebra_css_classes[index % zebra_css_classes.size] } if resource.respond_to?(:dom_id) options[:id] = resource.dom_id end options end
collection()
click to toggle source
# File lib/admino/table/presenter.rb, line 92 def collection object end
head_row(collection_klass, query, view_context)
click to toggle source
# File lib/admino/table/presenter.rb, line 96 def head_row(collection_klass, query, view_context) HeadRow.new(collection_klass, query, view_context) end
resource_row(resource, view_context)
click to toggle source
# File lib/admino/table/presenter.rb, line 100 def resource_row(resource, view_context) ResourceRow.new(resource, view_context) end
zebra_css_classes()
click to toggle source
# File lib/admino/table/presenter.rb, line 116 def zebra_css_classes %w(is-even is-odd) end