Skip to content

Commit

Permalink
feat: Access params ActionMailer::Preview style
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed Jan 10, 2024
1 parent 84210ef commit 57986c7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/view_component/preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class Preview
include ActionView::Helpers::AssetTagHelper
extend ActiveSupport::DescendantsTracker

attr_reader :params

def initialize(params = {})
@params = params
end

def render(component, **args, &block)
{
args: args,
Expand Down Expand Up @@ -44,8 +50,7 @@ def all
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 = provided_params.empty? ? new.public_send(example) : new.public_send(example, **provided_params)
result ||= {}
result = new(params).public_send(example, **provided_params) || {}
result[:template] = preview_example_template_path(example) if result[:template].nil?
@layout = nil unless defined?(@layout)
result.merge(layout: @layout)
Expand Down

0 comments on commit 57986c7

Please sign in to comment.