Class: Trestle::Table::Row::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/table/row.rb

Instance Method Summary collapse

Constructor Details

#initialize(row, table:, template:) ⇒ Renderer

Returns a new instance of Renderer.



16
17
18
# File 'lib/trestle/table/row.rb', line 16

def initialize(row, table:, template:)
  @row, @table, @template = row, table, template
end

Instance Method Details

#columnsObject



20
21
22
23
24
# File 'lib/trestle/table/row.rb', line 20

def columns
  @table.columns.map { |column|
    column.renderer(table: @table, template: @template)
  }.select(&:render?)
end

#options(instance) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/trestle/table/row.rb', line 32

def options(instance)
  options = Trestle::Options.new

  if @table.admin && @table.autolink? && @table.admin.actions.include?(:show)
    options.merge!(data: { url: admin_url_for(instance) })
    options.merge!(data: { behavior: "dialog" }) if @table.admin.form.dialog?
  end

  options.merge!(@row.options)
  options.merge!(@template.instance_exec(instance, &@row.block)) if @row.block

  options
end

#render(instance) ⇒ Object



26
27
28
29
30
# File 'lib/trestle/table/row.rb', line 26

def render(instance)
  @template.(:tr, options(instance)) do
    @template.safe_join(columns.map { |column| column.render(instance) }, "\n")
  end
end