app/controllers/lookbook/previews_controller.rb in lookbook-2.0.0.beta.0 vs app/controllers/lookbook/previews_controller.rb in lookbook-2.0.0.beta.1
- old
+ new
@@ -3,10 +3,12 @@
include TargetableConcern
include WithPreviewControllerConcern
layout false
+ before_action :permit_framing, only: [:show]
+
def self.controller_path
"lookbook/previews"
end
def index
@@ -15,14 +17,19 @@
render(
json: Lookbook.previews.map do |preview|
{
name: preview.name,
scenarios: preview.scenarios.map { |scenario|
- {
- inspect_path: scenario.url_path,
- name: scenario.name
- }
+ 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
@@ -43,8 +50,22 @@
error: prettify_error(exception)
end
else
show_404
end
+ end
+
+ private
+
+ def scenario_json(scenario)
+ {
+ name: scenario.name,
+ inspect_path: scenario.url_path,
+ preview_path: scenario.preview_path
+ }
+ end
+
+ def permit_framing
+ headers["X-Frame-Options"] = "SAMEORIGIN" if headers["X-Frame-Options"] == "DENY"
end
end
end