class Erubis::Engine
(abstract) abstract engine class. subclass must include evaluator and converter module.
Public Class Methods
load_file(filename, properties={})
click to toggle source
load file, write cache file, and return engine object. this method create code cache file automatically. cachefile name can be specified with properties, or filname + 'cache' is used as default.
# File lib/erubis/engine.rb, line 48 def self.load_file(filename, properties={}) cachename = properties[:cachename] || (filename + '.cache') properties[:filename] = filename timestamp = File.mtime(filename) if test(?f, cachename) && timestamp == File.mtime(cachename) engine = self.new(nil, properties) engine.src = File.read(cachename) else input = File.open(filename, 'rb') {|f| f.read } engine = self.new(input, properties) tmpname = cachename + rand().to_s[1,8] File.open(tmpname, 'wb') {|f| f.write(engine.src) } File.rename(tmpname, cachename) File.utime(timestamp, timestamp, cachename) end engine.src.untaint # ok? return engine end
new(input=nil, properties={})
click to toggle source
Public Instance Methods
convert!(input)
click to toggle source
convert input string and set it to @src
# File lib/erubis/engine.rb, line 37 def convert!(input) @src = convert(input) end
process(input, context=nil, filename=nil)
click to toggle source
helper method to convert and evaluate input text with context object. context may be Binding, Hash, or Object.
# File lib/erubis/engine.rb, line 72 def process(input, context=nil, filename=nil) code = convert(input) filename ||= '(erubis)' if context.is_a?(Binding) return eval(code, context, filename) else context = Context.new(context) if context.is_a?(Hash) return context.instance_eval(code, filename) end end
process_proc(proc_obj, context=nil, filename=nil)
click to toggle source
helper method evaluate Proc object with contect object. context may be Binding, Hash, or Object.
# File lib/erubis/engine.rb, line 88 def process_proc(proc_obj, context=nil, filename=nil) if context.is_a?(Binding) filename ||= '(erubis)' return eval(proc_obj, context, filename) else context = Context.new(context) if context.is_a?(Hash) return context.instance_eval(&proc_obj) end end