mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Use the configured charset, if any, in MustacheViewResolver
Closes gh-2670
This commit is contained in:
parent
2cf23e08a0
commit
dd748eda19
@ -108,6 +108,7 @@ public class MustacheAutoConfiguration {
|
||||
resolver.setCache(this.mustache.isCache());
|
||||
resolver.setViewNames(this.mustache.getViewNames());
|
||||
resolver.setContentType(this.mustache.getContentType());
|
||||
resolver.setCharset(this.mustache.getCharset());
|
||||
resolver.setCompiler(mustacheCompiler);
|
||||
resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 10);
|
||||
return resolver;
|
||||
|
@ -34,12 +34,15 @@ import com.samskivert.mustache.Template;
|
||||
* Spring MVC {@link ViewResolver} for Mustache.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
* @since 1.2.2
|
||||
*/
|
||||
public class MustacheViewResolver extends UrlBasedViewResolver {
|
||||
|
||||
private Compiler compiler = Mustache.compiler();
|
||||
|
||||
private String charset;
|
||||
|
||||
public MustacheViewResolver() {
|
||||
setViewClass(MustacheView.class);
|
||||
}
|
||||
@ -51,6 +54,13 @@ public class MustacheViewResolver extends UrlBasedViewResolver {
|
||||
this.compiler = compiler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param charset the charset to set
|
||||
*/
|
||||
public void setCharset(String charset) {
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View loadView(String viewName, Locale locale) throws Exception {
|
||||
Resource resource = resolveResource(viewName, locale);
|
||||
@ -64,7 +74,9 @@ public class MustacheViewResolver extends UrlBasedViewResolver {
|
||||
}
|
||||
|
||||
private Template createTemplate(Resource resource) throws IOException {
|
||||
return this.compiler.compile(new InputStreamReader(resource.getInputStream()));
|
||||
return this.charset == null ? this.compiler.compile(new InputStreamReader(
|
||||
resource.getInputStream())) : this.compiler
|
||||
.compile(new InputStreamReader(resource.getInputStream(), this.charset));
|
||||
}
|
||||
|
||||
private Resource resolveResource(String viewName, Locale locale) {
|
||||
|
Loading…
Reference in New Issue
Block a user