Class: Lookbook::PreviewsController

Inherits:
ApplicationController show all
Includes:
TargetableConcern, WithPreviewControllerConcern
Defined in:
app/controllers/lookbook/previews_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WithPreviewControllerConcern

#preview_controller

Methods included from TargetableConcern

#inspector_data, #lookup_entities, #path_segments, #set_display_options, #set_params, #set_title

Methods inherited from ApplicationController

#not_found

Class Method Details

.controller_pathObject



10
11
12
# File 'app/controllers/lookbook/previews_controller.rb', line 10

def self.controller_path
  "lookbook/previews"
end

Instance Method Details

#indexObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/lookbook/previews_controller.rb', line 14

def index
  respond_to do |format|
    format.json do
      render(
        json: Lookbook.previews.map do |preview|
          {
            name: preview.name,
            scenarios: preview.scenarios.map { |scenario|
              case scenario
              when Lookbook::ScenarioEntity
                scenario_json(scenario)
              when Lookbook::ScenarioGroupEntity
                {
                  name: scenario.name,
                  examples: scenario.scenarios.map { |s| scenario_json(s) }
                }
              end
            }
          }
        end
      )
    end
  end
end

#showObject



39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/lookbook/previews_controller.rb', line 39

def show
  raise_not_found("Preview not found") unless @target

  @preview_html = preview_controller.process(
    :render_in_layout_to_string,
    "lookbook/previews/group",
    inspector_data,
    layout: @preview.layout,
    append_html: (iframe_content_scripts if embedded?)
  )
end