Class: Admino::Table::Presenter

Inherits:
Showcase::Presenter
  • Object
show all
Defined in:
lib/admino/table/presenter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Presenter

Returns a new instance of Presenter.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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

Instance Attribute Details

#collection_klassObject (readonly)

Returns the value of attribute collection_klass.



8
9
10
# File 'lib/admino/table/presenter.rb', line 8

def collection_klass
  @collection_klass
end

#queryObject (readonly)

Returns the value of attribute query.



9
10
11
# File 'lib/admino/table/presenter.rb', line 9

def query
  @query
end

Class Method Details

.tag_helper(name, tag, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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.(tag, options, &block)
  end
end

Instance Method Details

#to_html(options = {}, &block) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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