lib/rabbit/theme/searcher.rb in rabbit-0.6.3 vs lib/rabbit/theme/searcher.rb in rabbit-0.6.4
- old
+ new
@@ -44,17 +44,24 @@
if only_image
collector = "collect_image_theme"
else
collector = "collect_all_theme"
end
+
+ unless only_image
+ entry = SingleFileEntry.new(base_directory, theme_name)
+ return entry if entry.available?
+ end
+
found_entry = nil
__send__(collector) do |entry|
if theme_name == entry.name
found_entry = entry
break
end
end
+
raise LoadError, "can't find theme: #{theme_name}." if found_entry.nil?
found_entry
end
def find_file(target, themes=nil)
@@ -84,28 +91,35 @@
collect_theme(&callback)
themes.sort
end
def collect_theme(&block)
- _collect_theme($LOAD_PATH, &block)
+ _collect_theme(theme_load_path, DirectoryEntry, &block)
end
def collect_image_theme(&block)
- _collect_theme(Config::IMAGE_PATH + $LOAD_PATH,
- "image_dir", :image, &block)
+ _collect_theme(image_load_path, ImageDirectoryEntry, "image_dir", &block)
end
-
- def _collect_theme(path, converter=nil, type=nil, &block)
+
+ def theme_load_path
+ $LOAD_PATH
+ end
+
+ def image_load_path
+ Config::IMAGE_PATH + $LOAD_PATH
+ end
+
+ def _collect_theme(path, entry_class, converter=nil, &block)
converter ||= "theme_dir"
themes = []
theme_name = {}
path.each do |dir|
base_name = __send__(converter, dir)
if File.directory?(base_name)
Dir.foreach(base_name) do |theme|
next if /\A..?\z/ =~ theme
- entry = Entry.new(File.join(File.expand_path(base_name), theme),
- type)
+ file = File.join(File.expand_path(base_name), theme)
+ entry = entry_class.new(file)
if entry.available? and !theme_name.has_key?(theme)
block.call(entry) if block
themes << entry
theme_name[theme] = true
end