Skip to content

Commit

Permalink
always load all previews
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhawksley committed May 25, 2022
1 parent 7cda925 commit 20e5e4a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
16 changes: 3 additions & 13 deletions lib/view_component/preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,11 @@ def render_with_template(template: nil, locals: {})
alias_method :render_component, :render

class << self
def load_all(force: false)
if descendants.empty? || force
Array(preview_paths).each do |preview_path|
Dir["#{preview_path}/**/*_preview.rb"].sort.each { |file| require_dependency file }
end
end
end

def load_all!
load_all(force: true)
end

# Returns all component preview classes.
def all
load_all!
Array(preview_paths).each do |preview_path|
Dir["#{preview_path}/**/*_preview.rb"].sort.each { |file| require_dependency file }
end

descendants
end
Expand Down
2 changes: 0 additions & 2 deletions lib/view_component/render_preview_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ module RenderPreviewHelper
# @param preview [String] The name of the preview to be rendered.
# @return [Nokogiri::HTML]
def render_preview(name)
ViewComponent::Preview.load_all!

begin
preview_klass = self.class.name.gsub("Test", "Preview")
preview_klass = preview_klass.constantize
Expand Down

0 comments on commit 20e5e4a

Please sign in to comment.