Class: AdminSuite::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/admin_suite/renderer.rb

Overview

Base class for panel renderers.

Host apps subclass this in app/admin/renderers/*.rb and reference it from a show panel:

panel :costs, title: "Provider Costs", render: :provider_costs
# => Admin::Renderers::ProviderCostsRenderer

Subclasses implement #render and may use the primitives below rather than hand-building markup, so panels stay visually consistent with the rest of the admin UI.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, view, options = {}) ⇒ Renderer

Returns a new instance of Renderer.

Parameters:

  • record (Object)

    the resource being rendered

  • view (ActionView::Base)

    the calling view/helper context

  • options (Hash) (defaults to: {})

    leftover panel DSL options (e.g. source:, columns:, empty:, language:) forwarded from ShowSectionDefinition#options. Defaults to {} so Task 3's two-arg construction keeps working.



23
24
25
26
27
# File 'lib/admin_suite/renderer.rb', line 23

def initialize(record, view, options = {})
  @record = record
  @view = view
  @options = options || {}
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/admin_suite/renderer.rb', line 16

def options
  @options
end

#recordObject (readonly)

Returns the value of attribute record.



16
17
18
# File 'lib/admin_suite/renderer.rb', line 16

def record
  @record
end

#viewObject (readonly)

Returns the value of attribute view.



16
17
18
# File 'lib/admin_suite/renderer.rb', line 16

def view
  @view
end

Instance Method Details

#renderString

Returns HTML-safe markup for the panel body.

Returns:

  • (String)

    HTML-safe markup for the panel body

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/admin_suite/renderer.rb', line 30

def render
  raise NotImplementedError, "#{self.class.name} must implement #render"
end