Method: EJS.evaluate
- Defined in:
- lib/ejs.rb
.evaluate(template, locals = {}, options = {}) ⇒ Object
Evaluates an EJS template with the given local variables and compiler options. You will need the ExecJS (github.com/sstephenson/execjs/) library and a JavaScript runtime available.
EJS.evaluate("Hello <%= name %>", name: "world")
# => "Hello world"
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ejs.rb', line 70 def evaluate(template, locals = {}, = {}) require "execjs" context = ExecJS.compile(<<-JS) #{escape_function} var template = #{compile(template, )} var evaluate = function(locals) { return template(locals, escape); } JS context.call("evaluate", locals) end |