lib/lookbook/preview.rb in lookbook-0.7.2.beta.4 vs lib/lookbook/preview.rb in lookbook-0.7.2.beta.5
- old
+ new
@@ -94,13 +94,19 @@
def exists?(path)
!!find(path)
end
+ def clear_cache
+ @previews = nil
+ end
+
def all
load_previews if preview_files.size > ViewComponent::Preview.descendants.size
+ return @previews if @previews.present?
+
previews = ViewComponent::Preview.descendants.map do |p|
new(p)
rescue
Rails.logger.error "[lookbook] error instantiating preview\n#{exception.full_message}"
end
@@ -110,10 +116,10 @@
Rails.logger.error "[lookbook] preview error\n#{error.full_message}\n"
end
end
sorted_previews = previews.compact.sort_by { |preview| [preview.position, preview.label] }
- PreviewCollection.new(sorted_previews)
+ @previews ||= PreviewCollection.new(sorted_previews)
end
def errors
@errors ||= []
end