25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/knj/erb/include.rb', line 25
def self.import(filename)
ERuby.load_settings if !@settings_loaded
filename = File.expand_path(filename)
pwd = Dir.pwd
Dir.chdir(File.dirname(filename))
fpath = "#{KnjEruby.filepath}/cache/#{filename.gsub("/", "_").gsub(".", "_")}"
pi = Knj::Php.pathinfo(filename)
cachename = fpath + ".cache"
filetime = File.mtime(filename)
cacheexists = File.exists?(cachename)
cachetime = File.mtime(cachename) if File.exists?(cachename)
if !cacheexists or filetime > cachetime
KnjEruby.load_file(File.basename(filename), {:cachename => cachename})
cachetime = File.mtime(cachename)
reload_cache = true
end
if @java_compile
if !@eruby_java_cache[cachename] or reload_cache
@eruby_java_cache[cachename] = File.read(cachename)
end
eval(@eruby_java_cache[cachename])
elsif @inseq_cache
if @inseq_rbc
bytepath = pi["dirname"] + "/" + pi["basename"] + ".rbc"
byteexists = File.exists?(bytepath)
bytetime = File.mtime(bytepath) if File.exists?(bytepath)
if !File.exists?(bytepath) or cachetime > bytetime
res = RubyVM::InstructionSequence.compile_file(filename)
data = Marshal.dump(res.to_a)
File.open(bytepath, "w+") do |fp|
fp.write(data)
end
end
end
if @inseq_rbc
res = Marshal.load(File.read(bytepath))
RubyVM::InstructionSequence.load(res).eval
else
if !@eruby_rbyte[cachename] or reload_cache
@eruby_rbyte[cachename] = RubyVM::InstructionSequence.new(File.read(cachename))
@eruby_rbyte[cachename].eval
else
_buf = ""
@eruby_rbyte[cachename].eval
if _buf
print _buf
end
end
end
else
eruby = KnjEruby.load_file(File.basename(filename), {:cachename => cachename})
print eruby.evaluate
end
Dir.chdir(pwd)
end
|