def scan
path_resolver = PathResolver.new
backend = @backend
engine = @engine
@template_dirs.each do |template_dir|
next unless ::File.directory?(template_dir = (path_resolver.system_path template_dir, nil))
file_pattern = '*'
if engine
file_pattern = %(*.#{engine})
if ::File.directory?(engine_dir = (::File.join template_dir, engine))
template_dir = engine_dir
end
end
if ::File.directory?(backend_dir = (::File.join template_dir, backend))
template_dir = backend_dir
end
pattern = ::File.join template_dir, file_pattern
if (scan_cache = @caches[:scans])
template_cache = @caches[:templates]
unless (templates = scan_cache[pattern])
templates = (scan_cache[pattern] = (scan_dir template_dir, pattern, template_cache))
end
templates.each do |name, template|
@templates[name] = template_cache[template.file] = template
end
else
@templates.update scan_dir(template_dir, pattern, @caches[:templates])
end
nil
end
end