Class Amrita::TemplateManager
|
|
Singleton
# File lib/amrita/template.rb, line 567
def TemplateManager::[](path)
TemplateManager.instance.get_template(path)
end
# File lib/amrita/template.rb, line 571
def TemplateManager::set_cache_dir(path)
TemplateManager.instance.set_cache_dir(path)
end
# File lib/amrita/template.rb, line 587
def initialize
@mem_cache = MemoryCache.new
set_cache_dir(ENV["AmritaCacheDir"].untaint) # be careful whether this directory is safe
end
CAUTION: be careful to prevent users to edit the cache file. It's
YOUR resposibility to protect the cache files from crackers. Don't
use TemplateFileWithCache::set_cache_dir if you don't understand
this.
# File lib/amrita/template.rb, line 579
def set_cache_dir(path)
if path
@file_cache = FileCache.new(path)
else
@file_cache = nil
end
end
# File lib/amrita/template.rb, line 592
def get_template(path)
ret = nil
if TemplateManager::const_defined? :Templates # if output of amcc was loaded
ret = Templates[path]
end
ret = @mem_cache.get_template(path) unless ret
ret = @file_cache.get_template(path) if @file_cache and not ret
unless ret
ret = TemplateFile.new(path)
ret.auto_save = true
end
ret
end
# File lib/amrita/template.rb, line 607
def clear_mem_cache
@mem_cache.clear
end
# File lib/amrita/template.rb, line 611
def save_template(template)
if template.path
@mem_cache.save_template(template.path, template)
@file_cache.save_template(template.path, template) if @file_cache
end
end