Update and improve script templating documentation

Issue: SPR-16447
This commit is contained in:
sdeleuze
2018-01-31 17:24:35 +01:00
parent b77032c36e
commit b6c78452b2
4 changed files with 70 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,9 @@ import java.util.function.Function;
import org.springframework.context.ApplicationContext;
/**
* Context passed to {@link ScriptTemplateView} render function.
* Context passed to {@link ScriptTemplateView} render function in order to make
* the application context, the locale, the template loader and the url available on
* scripting side.
*
* @author Sebastien Deleuze
* @since 5.0
@@ -38,6 +40,15 @@ public class RenderingContext {
private final String url;
/**
* Create a new {@code RenderingContext}.
*
* @param applicationContext the application context
* @param locale the locale of the rendered template
* @param templateLoader a function that takes a template path as input and returns
* the template content as a String
* @param url the URL of the rendered template
*/
public RenderingContext(ApplicationContext applicationContext, Locale locale,
Function<String, String> templateLoader, String url) {
@@ -48,18 +59,31 @@ public class RenderingContext {
}
/**
* Return the application context.
*/
public ApplicationContext getApplicationContext() {
return this.applicationContext;
}
/**
* Return the locale of the rendered template.
*/
public Locale getLocale() {
return this.locale;
}
/**
* Return a function that takes a template path as input and returns the template
* content as a String.
*/
public Function<String, String> getTemplateLoader() {
return this.templateLoader;
}
/**
* Return the URL of the rendered template.
*/
public String getUrl() {
return this.url;
}