Sha256: 4f1fbd4e29f66aa30293882b0c4e1b0a829b132e2c13bd1bf2847d7bfda6b34c

Contents?: true

Size: 723 Bytes

Versions: 5

Compression:

Stored size: 723 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, template_name = nil)
    component.controller = @controller

    template_name = (template_name || component.template_name)

    store(component)

    @controller.view_context.content_tag(:div, class: "component", id: component.identifier) do
      @controller.view_context.render(file: "/#{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

5 entries across 5 versions & 1 rubygems

Version Path
rafters-0.2.0 lib/rafters/component_renderer.rb
rafters-0.1.3 lib/rafters/component_renderer.rb
rafters-0.1.2 lib/rafters/component_renderer.rb
rafters-0.1.1 lib/rafters/component_renderer.rb
rafters-0.1.0 lib/rafters/component_renderer.rb