Package juzu.template

Examples of juzu.template.TemplateRenderContext


  @Test
  public void testWriterAccess() throws Exception {
    out = null;
    Writer writer = new StringWriter();
    GroovyTemplateStub template = template("<% " + TemplateRenderingTestCase.class.getName() + ".out = out; %>");
    new TemplateRenderContext(template).render(OutputStream.create(Tools.UTF_8, writer));
    assertNotNull(out);
  }
View Full Code Here


  }

  private void assertLineNumber(int expectedLineNumber, String expectedText, String script) throws IOException, TemplateException {
    GroovyTemplateStub template = template(script);
    try {
      new TemplateRenderContext(template).render(OutputStream.create());
      fail();
    }
    catch (TemplateExecutionException t) {
      assertEquals(expectedText, t.getText());
      assertEquals(expectedLineNumber, (Object)t.getLineNumber());
View Full Code Here

  @Test
  public void testFoo() throws Exception {
    GroovyTemplateStub s = template("a<%=foo%>c");
    s.init();
    StringWriter out = new StringWriter();
    new TemplateRenderContext(s, Collections.<String, Object>singletonMap("foo", "b")).render(OutputStream.create(Tools.UTF_8, out));
    assertEquals("abc", out.toString());
  }
View Full Code Here

  @Test
  public void testCarriageReturn() throws Exception {
    GroovyTemplateStub s = template("a\r\nb");
    s.init();
    StringWriter out = new StringWriter();
    new TemplateRenderContext(s, Collections.<String, Object>emptyMap()).render(OutputStream.create(Tools.UTF_8, out));
    assertEquals("a\nb", out.toString());
  }
View Full Code Here

    return out.toString();
  }

  public void render(String text, Map<String, Object> attributes, Locale locale, Appendable appendable) throws IOException, TemplateExecutionException, TemplateException {
    GroovyTemplateStub template = template(text);
    TemplateRenderContext renderContext = new TemplateRenderContext(template, null, attributes, locale);
    OutputStream adapter = OutputStream.create(Tools.UTF_8, appendable);
    renderContext.render(adapter);
    final AtomicReference<IOException> ios = new AtomicReference<IOException>();
    adapter.close(new Thread.UncaughtExceptionHandler() {
      public void uncaughtException(Thread t, Throwable e) {
        if (e instanceof IOException) {
          ios.set((IOException)e);
View Full Code Here

TOP

Related Classes of juzu.template.TemplateRenderContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.