Module: ViewComponent::PreviewActions

Extended by:
ActiveSupport::Concern
Included in:
ViewComponentsController
Defined in:
app/controllers/concerns/view_component/preview_actions.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



19
20
21
22
23
# File 'app/controllers/concerns/view_component/preview_actions.rb', line 19

def index
  @previews = ViewComponent::Preview.all
  @page_title = "Component Previews"
  render "view_components/index", **determine_layout
end

#previewsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/concerns/view_component/preview_actions.rb', line 25

def previews
  if params[:path] == @preview.preview_name
    @page_title = "Component Previews for #{@preview.preview_name}"
    render "view_components/previews", **determine_layout
  else
    prepend_application_view_paths
    prepend_preview_examples_view_path
    @example_name = File.basename(params[:path])
    @render_args = @preview.render_args(@example_name, params: params.permit!)
    layout = determine_layout(@render_args[:layout], prepend_views: false)[:layout]
    locals = @render_args[:locals]
    opts = {}
    opts[:layout] = layout if layout.present? || layout == false
    opts[:locals] = locals if locals.present?
    render "view_components/preview", opts # rubocop:disable GitHub/RailsControllerRenderLiteral
  end
end