Sha256: 1e1a789b5e91ad50f8a8647b6b679af543471ab83ce4b9b299a0cac5c82a18c2

Contents?: true

Size: 893 Bytes

Versions: 2

Compression:

Stored size: 893 Bytes

Contents

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

      render_cell(cell, options)
    end

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

      # render the cell.
      content = cell.()

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

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

      super(constant, model, cell_options) # From cells-rails gem.
    end

    # Override this to customize what options are passed into the cell constructor.
    # E.g. `{layout: Song::Cell::Layout}`
    def options_for_cell(_model, _options)
      {}
    end
  end

  include Render unless method_defined?(:render_cell) # FIXME: this will be removed soon.
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trailblazer-rails-2.4.4 lib/trailblazer/rails/cell.rb
trailblazer-rails-2.4.3 lib/trailblazer/rails/cell.rb