# File lib/amrita/ams.rb, line 96def AmsTemplate::[](path)
ret = @@template_cache[path]
unless ret
@@template_cache[path] = ret = AmsTemplate.new(path)
end
ret
end
Public Instance methods
load_ams_template()
# File lib/amrita/ams.rb, line 11def load_ams_template
File.open(@path) do |f|
@template_text = f.read
end
typ, script = nil, nilcase @template_text
when RScript1
typ, script = $1, $2
@template_text.gsub!( RScript1, "")
when RScript2
typ, script = "eval", $1
@template_text.gsub!( RScript2, "")
else# do nothingend
@ams_type = typ
case @ams_type
when"eval"
script = script.untaint
@data = eval(script, TOPLEVEL_BINDING)
when"module"
script = script.untaint
cls = Class.new
cls.module_eval script
obj = cls.new
obj.extend ExpandByMember
@data = obj
when"yaml"
require "yaml"
@data = YAML::load script
whennil
@data = Hash.new(true)
else
raise "unknown script type #{typ}"
endend
load_template()
# File lib/amrita/ams.rb, line 49def load_template
@template = get_parser_class.parse_text(@template_text) do |e|
if @parser_filter
@parser_filter.call(e)
else
e
endendend
setup_context()
# File lib/amrita/ams.rb, line 60def setup_context
context = superif @ams_type == "yaml"
context.hash_key_is_string = true
context.expand_attr = trueend
context
end
expand(stream)
# File lib/amrita/ams.rb, line 69def expand(stream)
load_ams_template
if need_update?
setup_template
end
context = setup_context
formatter = setup_formatter(stream)
do_expand(@data, context, formatter)
end
cache_path()
# File lib/amrita/ams.rb, line 80def cache_path
if @@cache_dir
@@cache_dir + "/" + File::basename(@path) + ".amrita"elsenilendend
cache_valid?()
# File lib/amrita/ams.rb, line 88def cache_valid?
if @@cache_dir and FileTest::readable?(cache_path)
File::stat(@path).mtime <= File::stat(cache_path).mtime
elsefalseendend