>>>>> "M" == Michael Neumann <neumann / s-direktnet.de> writes:
M> Is it possible to use eRuby from Ruby without executing it, only through a method-call.
M> Could it be loaded as module?
I wrote 'Tiny eRuby - ERb'.
ERb is an implementation of eRuby (embedded ruby).
You can include ERb in your script.
o ERb#new(str) convert eRuby -> Ruby.
o ERb#run([binding]) execute script, and print result.
o ERb#result([binding]) execute script, and return result.
o ERb#src converted Ruby script.
You can use it following way.
-- ERb sample script --
require 'erb/erb' # http://www2a.biglobe.ne.jp/~seki/ruby/erb-1.2.tar.gz
class App
def initialize
# eRuby script
script = <<EOS
<DL>
<% hash.each { |k, v| %>
<DT><%= k %> <DD><%= v %>
<% } %>
</DL>
EOS
# eRuby -> ERb
@erb = ERb.new(script)
end
def display(hash)
# eval
@erb.result(binding)
end
def debug
puts @erb.src
end
end
app = App.new
puts "<H1>ENV</H1>"
puts app.display(ENV)
puts "<H1>Seki</H1>"
puts app.display({'given'=>'Masatoshi', 'family'=>'SEKI', 'age'=>29})