lib/lookbook/preview.rb in lookbook-1.0.0.beta.7 vs lib/lookbook/preview.rb in lookbook-1.0.0.beta.8
- old
+ new
@@ -95,24 +95,22 @@
def component
components.first
end
def components
- component_classes = @preview_inspector&.components.any? ? @preview_inspector&.components : [guess_component]
+ component_classes = @preview_inspector&.components&.any? ? @preview_inspector&.components : [guess_component]
component_classes.map do |class_name|
Component.new(class_name.to_s)
end
end
protected
def guess_component
- begin
- name.chomp("Preview").constantize
- rescue
- nil
- end
+ name.chomp("Preview").constantize
+ rescue
+ nil
end
class << self
def find(path)
all.find { |p| p.lookup_path == path }
@@ -154,22 +152,22 @@
@errors ||= []
end
def clear_cache
cache_dir = File.dirname(cache_marker_path)
- FileUtils.mkdir_p(cache_dir) unless File.exists?(cache_dir)
+ FileUtils.mkdir_p(cache_dir) unless File.exist?(cache_dir)
File.write(cache_marker_path, Time.now.to_i)
end
protected
def cache_marker_path
Rails.root.join("tmp/cache/lookbook-previews")
end
def cache_stale?
- return false if !File.exists?(cache_marker_path)
+ return false if !File.exist?(cache_marker_path)
cache_timestamp = File.read(cache_marker_path).to_i
if @last_cache_timestamp.nil? || cache_timestamp > @last_cache_timestamp
@last_cache_timestamp = cache_timestamp
true
else
@@ -177,11 +175,11 @@
end
end
def mark_as_cached
cache_dir = File.dirname(cache_marker_path)
- FileUtils.mkdir_p(cache_dir) unless File.exists?(cache_dir)
+ FileUtils.mkdir_p(cache_dir) unless File.exist?(cache_dir)
File.write(cache_marker_path, Time.now)
end
def load_previews
@errors = []
@@ -194,10 +192,10 @@
file_name: file[:rel_path],
file_path: file[:path])
)
end
end
-
+
def preview_files
files = Array(Lookbook.config.preview_paths).map do |preview_path|
Dir["#{preview_path}/**/*preview.rb"].map do |path|
{
path: path,