app/controllers/lookbook/previews_controller.rb in lookbook-1.0.0.beta.2 vs app/controllers/lookbook/previews_controller.rb in lookbook-1.0.0.beta.3
- old
+ new
@@ -115,45 +115,40 @@
end
def inspector_data
return @inspector_data if @inspector_data.present?
- request_data = {
+ context_data = {
preview_params: preview_params,
path: params[:path],
- query_parameters: request.query_parameters,
- original: request
}
- preview_data = {
- relative_path: @preview.full_path.relative_path_from(Rails.root.to_s),
- full_path: @preview.full_path,
- example_label: @example.label,
- params: @example.params,
- }
- [:id, :label, :notes, :lookup_path, :full_path].each do |prop|
- preview_data[prop] = @preview.public_send(prop)
- end
+ example = @example
+ preview = @preview
+ preview.define_singleton_method(:params, proc {
+ example.params
+ })
- examples_data = target_examples.map do |example|
+ examples = target_examples.map do |example|
render_args = @preview.render_args(example.name, params: preview_controller.params)
has_template = render_args[:template] != "view_components/preview"
- example_data = Lookbook::Store.new({
- output: preview_controller.process(:render_example_to_string, @preview, example.name),
- source: has_template ? example.template_source(render_args[:template]) : example.method_source,
- source_lang: has_template ? example.template_lang(render_args[:template]) : example.source_lang,
- })
- [:id, :label, :notes, :lookup_path, :params, :display_params].each do |prop|
- example_data[prop] = example.public_send(prop)
- end
- example_data
+ output = preview_controller.process(:render_example_to_string, @preview, example.name)
+ source = has_template ? example.template_source(render_args[:template]) : example.method_source
+ source_lang = has_template ? example.template_lang(render_args[:template]) : example.lang
+
+ example.define_singleton_method(:output, proc { output })
+ example.define_singleton_method(:source, proc { source })
+ example.define_singleton_method(:source_lang, proc { source_lang })
+ example
end
@inspector_data ||= Lookbook::Store.new({
- request: request_data,
- preview: preview_data,
- examples: examples_data
+ context: context_data,
+ preview: preview,
+ examples: examples,
+ components: preview.components,
+ app: Lookbook
})
end
def panels
return @panels if @panels.present?
@@ -161,11 +156,11 @@
Lookbook.config.inspector_panels.each do |name, config|
config_with_defaults = Lookbook.config.inspector_panel_defaults.merge(config)
callable_data = {
name: name.to_s,
- index_position: (@panels.filter { |p| p.pane == config.pane }.size + 1),
+ index_position: (@panels.select { |p| p.pane == config.pane }.size + 1),
**inspector_data
}
resolved_config = config_with_defaults.transform_values do |value|
value.class == Proc ? value.call(Lookbook::Store.new(callable_data)) : value
@@ -173,18 +168,18 @@
resolved_config[:name] = name.to_s
@panels << Lookbook::Store.new(resolved_config, deep: false)
end
- @panels.filter(&:show).sort_by { |p| [p.position, p.label] }
+ @panels = @panels.select(&:show).sort_by { |p| [p.position, p.label] }
end
def main_panels
- panels.filter { |panel| panel.pane == :main }
+ panels.select { |panel| panel.pane == :main }
end
def drawer_panels
- panels.filter { |panel| panel.pane == :drawer }
+ panels.select { |panel| panel.pane == :drawer }
end
def preview_controller
return @preview_controller if @preview_controller
controller = Lookbook::Engine.preview_controller.new