Module: ViewSpecs::PreviewActions

Extended by:
ActiveSupport::Concern
Included in:
ViewSpecPreviewsController
Defined in:
app/controllers/concerns/view_specs/preview_actions.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
13
# File 'app/controllers/concerns/view_specs/preview_actions.rb', line 5

def index
  @view_specs = ViewSpec.specs

  layout = self.class._layout || ViewSpec.config.preview_layout
  options = {}
  options[:layout] = layout if layout

  render "view_specs/previews/index", **options
end

#previewObject

Raises:

  • (ActionController::RoutingError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/concerns/view_specs/preview_actions.rb', line 15

def preview
  spec = ViewSpec.specs.find_where(lookup_path: params[:spec])
  raise ActionController::RoutingError, "Spec not found" unless spec

  entry = spec.entries.find_where(short_identifier: params[:entry])
  raise ActionController::RoutingError, "`#{params[:entry]}` not found for spec `#{spec.subject}`" unless entry

  preview = entry.preview(params: view_spec_preview_params)

  options = {}
  layout = entry.determine_layout(self.class._layout) || ViewSpec.config.preview_layout
  (options[:layout] = layout) if layout

  render preview, **options
end