use of org.summerb.stringtemplate.api.StringTemplate in project summerb by skarpushin.
the class ArticleRendererImpl method renderArticle.
@Override
public RenderedArticle renderArticle(String key, Locale locale) {
Preconditions.checkArgument(StringUtils.hasText(key));
Preconditions.checkArgument(locale != null);
try {
Article article = articleService.findArticleByKeyAndLocale(key, locale);
if (article == null) {
throw new RuntimeException("Article not found: " + key + ", locale: " + locale);
}
RenderedArticle renderedArticle = buildRenderedArticleTemplate(article);
ArticleRenderingContext articleRenderingContext = new ArticleRenderingContext(locale, renderedArticle, articleService, attachmentService, articleAbsoluteUrlBuilder);
StringTemplate annotationTemplate = stringTemplateCompiler.compile(article.getAnnotation());
renderedArticle.setAnnotation(annotationTemplate.applyTo(articleRenderingContext));
StringTemplate contentTemplate = stringTemplateCompiler.compile(article.getContent());
renderedArticle.setContent(contentTemplate.applyTo(articleRenderingContext));
return renderedArticle;
} catch (Throwable t) {
throw new RuntimeException("Failed to render article", t);
}
}
use of org.summerb.stringtemplate.api.StringTemplate in project summerb by skarpushin.
the class StringTemplateCompilerSpElImplTest method testCompile.
/**
* Run the StringTemplate compile(String) method test
*/
@Test
public void testCompile() {
String template = "Hello ${name}! I hope you are fine. Now you have ${amount} money!";
StringTemplate stringTemplate = fixture.compile(template);
String result = stringTemplate.applyTo(new DomainObjectExample("Bob", 1234));
assertEquals("Hello Bob! I hope you are fine. Now you have 1234 money!", result);
}
Aggregations