Module: Trailblazer::Rails::Controller::Cell::Render

Included in:
Trailblazer::Rails::Controller::Cell
Defined in:
lib/trailblazer/rails/cell.rb

Instance Method Summary collapse

Instance Method Details

#cell(constant, model, options = {}) ⇒ Object



18
19
20
21
22
# File 'lib/trailblazer/rails/cell.rb', line 18

def cell(constant, model, options={})
  cell_options = options.reverse_merge(options_for_cell(model, options))

  super(constant, model, cell_options)
end

#options_for_cell(_model, _options) ⇒ Object

Override this to customize what options are passed into the cell constructor. E.g. ‘Song::Cell::Layout`



26
27
28
# File 'lib/trailblazer/rails/cell.rb', line 26

def options_for_cell(_model, _options)
  {}
end

#render(cell = nil, options = {}, &block) ⇒ Object



3
4
5
6
7
# File 'lib/trailblazer/rails/cell.rb', line 3

def render(cell = nil, options = {}, *, &block)
  return super unless cell.kind_of?(::Cell::ViewModel)

  render_cell(cell, options)
end

#render_cell(cell, options) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/trailblazer/rails/cell.rb', line 9

def render_cell(cell, options)
  options = options.reverse_merge(layout: true)

  # render the cell.
  content = cell.()

  render({html: content}.merge(options))
end