Expose view url to render function in ScriptTemplateView
After this change, with Nashorn it is possible to use either render(template, model) or render(template, model, url). With JRuby or Jython, specifying the 3 parameters is mandatory. Issue: SPR-13453
This commit is contained in:
@@ -3,8 +3,7 @@ require 'ostruct'
|
||||
require 'java'
|
||||
|
||||
# Renders an ERB template against a hashmap of variables.
|
||||
# template should be a Java InputStream
|
||||
def render(template, variables)
|
||||
def render(template, variables, url)
|
||||
context = OpenStruct.new(variables).instance_eval do
|
||||
variables.each do |k, v|
|
||||
instance_variable_set(k, v) if k[0] == '@'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from string import Template
|
||||
|
||||
def render(template, model):
|
||||
def render(template, model, url):
|
||||
s = Template(template)
|
||||
return s.substitute(model)
|
||||
@@ -1,3 +1,7 @@
|
||||
function render(template, model) {
|
||||
return template.replace("{{title}}", model.title).replace("{{body}}", model.body);
|
||||
}
|
||||
}
|
||||
|
||||
function renderWithUrl(template, model, url) {
|
||||
return template.replace("{{title}}", "Check url parameter").replace("{{body}}", url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user