Sha256: 096ea73f4ae66e15685b144b27e9773533308ab97e19aa1aaaa58db971ec2d36

Contents?: true

Size: 676 Bytes

Versions: 2

Compression:

Stored size: 676 Bytes

Contents

class Rafters::ComponentRenderer
  def initialize(controller)
    @controller = controller

    Rafters.view_paths.each do |view_path|
      @controller.prepend_view_path(view_path)
    end
  end

  def render(component)
    component.controller = @controller

    store(component)

    @controller.view_context.content_tag(:div, class: "component #{component.name.dasherize}", id: component.identifier) do
      @controller.view_context.render(file: "/#{component.template_name}", locals: component.attributes)
    end
  end

  private

  def store(component)
    @controller.rendered_components ||= {}
    @controller.rendered_components.merge!(component.as_json)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rafters-1.2.0 lib/rafters/component_renderer.rb
rafters-1.1.0 lib/rafters/component_renderer.rb