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:
Sebastien Deleuze
2015-09-09 18:05:04 +02:00
parent ff02ad47e0
commit f3b7e9ff2d
7 changed files with 46 additions and 17 deletions

View File

@@ -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] == '@'

View File

@@ -1,5 +1,5 @@
from string import Template
def render(template, model):
def render(template, model, url):
s = Template(template)
return s.substitute(model)

View File

@@ -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);
}