Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ViewComponent/view_component
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 57986c7040ed3def26dd402b18f33757fc73a8a6
Choose a base ref
..
head repository: ViewComponent/view_component
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 362f7f3c016c538fcd3ad9db0b26e2fdccfd691a
Choose a head ref
Showing with 12 additions and 2 deletions.
  1. +12 −2 lib/view_component/preview.rb
14 changes: 12 additions & 2 deletions lib/view_component/preview.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require "active_support/core_ext/object/blank"
require "active_support/descendants_tracker"

module ViewComponent # :nodoc:
@@ -49,8 +50,17 @@ def all
# Returns the arguments for rendering of the component in its layout
def render_args(example, params: {})
example_params_names = instance_method(example).parameters.map(&:last)
provided_params = params.slice(*example_params_names).to_h.symbolize_keys
result = new(params).public_send(example, **provided_params) || {}

result =
if example_params_names.blank?
new(params).public_send(example)
else
Deprecation.deprecation_warning("Preview variant arguments are deprecated, user params instead")
provided_params = params.slice(*example_params_names).to_h.symbolize_keys
new(params).public_send(example, **provided_params)
end

result ||= {}
result[:template] = preview_example_template_path(example) if result[:template].nil?
@layout = nil unless defined?(@layout)
result.merge(layout: @layout)