Created
October 25, 2010 14:12
-
-
Save shawn42/645012 to your computer and use it in GitHub Desktop.
rails2.3.x lib/action_view/reloadable_template.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionView #:nodoc: | |
class ReloadableTemplate | |
... | |
def register_template_from_file(template_full_file_path) | |
if !@paths[relative_path = relative_path_for_template_file(template_full_file_path)] && File.file?(template_full_file_path) | |
register_template(ReloadableTemplate.new(relative_path, self)) | |
end | |
end | |
def register_template(template) | |
template.accessible_paths.each do |path| | |
# These paths | |
@paths[path] = template | |
end | |
end | |
# load all templates from the directory of the requested template | |
def load_all_templates_from_dir(dir) | |
# hit disk only once per template-dir/request | |
@disk_cache[dir] ||= template_files_from_dir(dir).each {|template_file| register_template_from_file(template_file)} | |
end | |
# get all the template filenames from the dir | |
def template_files_from_dir(dir) | |
Dir.glob(File.join(dir, '*')) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment