Java Code Examples for com.github.jknack.handlebars.Handlebars#compileInline()
The following examples show how to use
com.github.jknack.handlebars.Handlebars#compileInline() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HandlebarsScriptEngine.java From sling-samples with Apache License 2.0 | 6 votes |
@Override public Object eval(String script, ScriptContext context) throws ScriptException { final Resource resource = (Resource) context.getBindings(ScriptContext.ENGINE_SCOPE).get(SlingBindings.RESOURCE); final PrintWriter out = (PrintWriter) context.getBindings(ScriptContext.ENGINE_SCOPE).get(SlingBindings.OUT); try { final Handlebars handlebars = setupHandlebars(); final Template template = handlebars.compileInline(script); out.println(template.apply(getData(resource))); } catch(IOException ioe) { final ScriptException up = new ScriptException("IOException in eval"); up.initCause(ioe); throw up; } return null; }
Example 2
Source File: Xsd2JaxbGenerator.java From legstar-core2 with GNU Affero General Public License v3.0 | 5 votes |
private Template loadTemplate(Handlebars handlebars, String resourceName) { try { String text = IOUtils.toString(getClass().getResourceAsStream( resourceName)); return handlebars.compileInline(text); } catch (IOException e) { throw new Xsd2ConverterException(e); } }
Example 3
Source File: Xsd2CobolTypesGenerator.java From legstar-core2 with GNU Affero General Public License v3.0 | 5 votes |
public Xsd2CobolTypesGenerator() { try { String text = IOUtils.toString(getClass().getResourceAsStream( JAVA_CLASS_TEMPLATE_NAME)); Handlebars handlebars = new Handlebars(); hbtJavaClass = handlebars.compileInline(text); modelBuilder = new Xsd2CobolTypesModelBuilder(); } catch (IOException e) { throw new Xsd2ConverterException(e); } }
Example 4
Source File: BasicUsageUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenThereIsNoTemplateFile_ThenCompilesInline() throws IOException { Handlebars handlebars = new Handlebars(); Template template = handlebars.compileInline("Hi {{this}}!"); String templateString = template.apply("Baeldung"); assertThat(templateString).isEqualTo("Hi Baeldung!"); }
Example 5
Source File: BasicUsageUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenParameterMapIsSupplied_thenDisplays() throws IOException { Handlebars handlebars = new Handlebars(); Template template = handlebars.compileInline("Hi {{name}}!"); Map<String, String> parameterMap = new HashMap<>(); parameterMap.put("name", "Baeldung"); String templateString = template.apply(parameterMap); assertThat(templateString).isEqualTo("Hi Baeldung!"); }
Example 6
Source File: BasicUsageUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenParameterObjectIsSupplied_ThenDisplays() throws IOException { Handlebars handlebars = new Handlebars(); Template template = handlebars.compileInline("Hi {{name}}!"); Person person = new Person(); person.setName("Baeldung"); String templateString = template.apply(person); assertThat(templateString).isEqualTo("Hi Baeldung!"); }
Example 7
Source File: BasicUsageUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenMultipleParametersAreSupplied_ThenDisplays() throws IOException { Handlebars handlebars = new Handlebars(); Template template = handlebars.compileInline("Hi {{name}}! This is {{topic}}."); Map<String, String> parameterMap = new HashMap<>(); parameterMap.put("name", "Baeldung"); parameterMap.put("topic", "Handlebars"); String templateString = template.apply(parameterMap); assertThat(templateString).isEqualTo("Hi Baeldung! This is Handlebars."); }