app/controllers/lookbook/app_controller.rb in lookbook-0.4.4 vs app/controllers/lookbook/app_controller.rb in lookbook-0.4.5
- old
+ new
@@ -6,11 +6,11 @@
protect_from_forgery with: :exception
prepend_view_path File.expand_path("../../views/lookbook", __dir__)
layout "layouts/app"
- helper Lookbook::Engine.helpers
+ helper Lookbook::ApplicationHelper
before_action :find_preview, only: [:preview, :show]
before_action :find_example, only: [:preview, :show]
before_action :assign_nav, only: [:index, :show]
before_action :initialize_inspector, only: [:show]
@@ -103,10 +103,19 @@
preview_controller.process(:previews)
end
end
def set_params(example = nil)
+ if example.present? && enabled?(:params)
+ # cast known params to type
+ example.params.each do |param|
+ if preview_controller.params.key?(param[:name])
+ preview_controller.params[param[:name]] = Lookbook::Params.cast(preview_controller.params[param[:name]], param[:type])
+ end
+ end
+ end
+ # set display params
example_params = example.nil? ? @preview.display_params : example.display_params
preview_controller.params.merge!({
lookbook: {
display: example_params
}
@@ -137,10 +146,19 @@
items: @notes,
disabled: @notes.none?
}
}
}
+ if enabled?(:params)
+ @inspector[:panes][:params] = {
+ label: "Params",
+ template: "params",
+ hotkey: "p",
+ items: @source.many? ? [] : @example.params,
+ disabled: @source.many? || @example.params.none?
+ }
+ end
end
def assign_nav
@nav = Collection.new
previews.reject { |p| p.hidden? }.each do |preview|
@@ -171,8 +189,12 @@
controller_class.class_eval { include Lookbook::PreviewController }
controller = controller_class.new
controller.request = request
controller.response = response
@preview_controller ||= controller
+ end
+
+ def enabled?(feature)
+ Lookbook::Features.enabled?(feature)
end
end
end