Package com.google.sitebricks

Examples of com.google.sitebricks.Template


    TemplateRegistry registry = new SimpleTemplateRegistry();

    for (RegisteredTemplate template : templates) {
      String templateName = template.getName();
      Class<?> pageClass = template.getPageClass();
      Template loadedTemplate = loader.load(pageClass);

      CompiledTemplate compiledTemplate;
      compiledTemplate = TemplateCompiler.compileTemplate(loadedTemplate.getText());

      registry.addNamedTemplate(templateName, compiledTemplate);
    }

    return registry;
View Full Code Here


  }

  @Override
  public String render(Object ctx) {
    Class<? extends Object> pageClass = ctx.getClass();
    Template template = templateLoader.load(pageClass);

    CompiledTemplate compiledTemplate = TemplateCompiler.compileTemplate(template.getText());

    Object contents = TemplateRuntime.execute(compiledTemplate, ctx, templateRegistry);

    return contents.toString();
  }
View Full Code Here

  @Test
  public final void readShowIfWidgetTrue() {

    Renderable widget = compiler()
        .compile(Object.class, new Template("<html>@ShowIf(true)<p>hello</p></html>"));

//        .compile("<!doctype html>\n" +
//              "<html><head><meta charset=\"UTF-8\"><title>small test</title></head><body>\n" +
//              "@ShowIf(true)<p>hello</p>" +
//              "\n</body></html>");
View Full Code Here

  }

  @Test(dataProvider = ANNOTATION_EXPRESSIONS)
  public final void readAWidgetWithVariousExpressions(String expression) {   
    Renderable widget = compiler()
        .compile(Object.class, new Template(String.format("<html>@ShowIf(%s)<p>hello</p></html>", expression)));
   
    assert null != widget : " null ";   
    final Respond mockRespond = RespondersForTesting.newRespond();   
    widget.render(new Object(), mockRespond);   
    final String value = mockRespond.toString();   
View Full Code Here

  @Test
  public final void readShowIfWidgetFalse() {

    Renderable widget = compiler()
        .compile(Object.class, new Template("<html>@ShowIf(false)<p>hello</p></html>"));

    assert null != widget : " null ";
    final Respond mockRespond = RespondersForTesting.newRespond();
    widget.render(new Object(), mockRespond);
    final String value = mockRespond.toString();
View Full Code Here

  @Test
  public final void readTextWidgetValues() {

    Renderable widget = compiler()
        .compile(TestBackingType.class, new Template("<html><div class='${clazz}'>hello <a href='/people/${id}'>${name}</a></div></html>"));

    assert null != widget : " null ";
    final Respond mockRespond = RespondersForTesting.newRespond();
    widget.render(new TestBackingType("Dhanji", "content", 12), mockRespond);
    final String value = mockRespond.toString();
View Full Code Here

    TypeConverter converter = new MvelTypeConverter();
    Parsing.setTypeConverter(converter);

    Renderable widget = compiler()
        //new HtmlTemplateCompiler(registry, pageBook, metrics)
            .compile(TestBackingType.class, new Template("<html> <head>" +
                "   @Require <script type='text/javascript' src='my.js'> </script>" +
                "   @Require <script type='text/javascript' src='my.js'> </script>" +
                "</head><body>" +
                "<div class='${clazz}'>hello <a href='/people/${id}'>${name}</a></div>" +
                "</body></html>"));
View Full Code Here

   @Test
   public final void readHtmlWidgetWithError() {
       try{
        Renderable widget = compiler()
                .compile(TestBackingType.class, new Template("<html>\n<div class='${clazz}'>hello</div>\n</html>${qwe}"));
        fail();
       } catch (Exception ex){
           assertEquals(ex.getClass(), TemplateCompileException.class);
           TemplateCompileException te = (TemplateCompileException) ex;
           assertEquals(te.getErrors().size(), 1);
View Full Code Here

    @Test
    public final void readHtmlWidgetWithErrorAndWidget() {
        try{
            Renderable widget = compiler()
                    .compile(TestBackingType.class, new Template("<html>\n<div class='${clazz}'>hello</div>\n\n</html>@ShowIf(true)\n${qwe}"));
            fail();
        } catch (Exception ex){
            assertEquals(ex.getClass(), TemplateCompileException.class);
            TemplateCompileException te = (TemplateCompileException) ex;
            assertEquals(te.getErrors().size(), 1);
View Full Code Here

  @Test
  public final void readHtmlWidget() {

    Renderable widget = compiler()
        .compile(TestBackingType.class, new Template("<html><div class='${clazz}'>hello</div></html>"));

    assert null != widget : " null ";
    final Respond mockRespond = RespondersForTesting.newRespond();
    widget.render(new TestBackingType("Dhanji", "content", 12), mockRespond);
    final String s = mockRespond.toString();
View Full Code Here

TOP

Related Classes of com.google.sitebricks.Template

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.