Does anybody know if it’s possible to have Eruby::import return its
output as a string instead of just printing it to stdout? I’d like to
be able to call it like this:
result = Eruby::import (‘inc/rhtml/template.rhtml’)
I suppose I could just backticks or something but I’d rather not take
on the overhead. Anybody managed to do this?
Thanks,
Francis
sera@fhwang.net (Francis Hwang) wrote in message news:7b561b93.0306031044.54ee8c92@posting.google.com…
Does anybody know if it’s possible to have Eruby::import return its
output as a string instead of just printing it to stdout? I’d like to
be able to call it like this:
result = Eruby::import (‘inc/rhtml/template.rhtml’)
I suppose I could just backticks or something but I’d rather not take
on the overhead. Anybody managed to do this?
Thanks,
Francis
Use a class ‘ERuby::Compiler’.
This class has following instance methods:
- compile_file(File)
- compile_string(String)
Example:
···
require 'eruby'
filename = 'hoge.rhtml'
compiler = ERuby::Compiler.new()
src = nil
File.open(filename) do |file|
src = compiler.compile_file(file)
end
print src
--------------------
--------------------
require 'eruby'
filename = 'hoge.rhtml'
file_str = nil
File.open(filename) do |file|
file_str = file.read()
end
compiler = ERuby::Compiler.new()
src = compiler.compile_string(file_str)
print src
--------------------
–
regards
kwatch