Package com.google.sitebricks

Examples of com.google.sitebricks.Renderable


    assert page.widget().equals(mock);
  }

  @Test
  public final void firePostMethodOnPage() throws IOException {
    Renderable mock = new Renderable() {
      public void render(Object bound, Respond respond) {

      }

      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
View Full Code Here


  @Test(dataProvider = URI_TEMPLATES_AND_MATCHES)
  public final void matchPageByUriTemplate(final String template, final String toMatch) {
    final Respond respond = new MockRespond();

    Renderable mock = new Renderable() {
      public void render(Object bound, Respond respond) {

      }

      public <T extends Renderable> Set<T> collect(Class<T> clazz) {
        return null;
      }
    };

    final PageBook pageBook = new DefaultPageBook(injector);
    pageBook.at(template, MyPage.class);

    PageBook.Page page = pageBook.get(toMatch);
    final MyPage myPage = new MyPage();

    page.apply(mock);
    page.widget().render(myPage, respond);

    assert mock.equals(page.widget());
  }
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;
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;
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();
    assert "<html><div class=\"content\">hello</div></html>"
        .equals(s) : "Did not write expected output, instead: " + s;
  }
View Full Code Here


  @Test
  public final void readHtmlWidgetWithChildren() {

    Renderable widget = compiler()
        .compile(TestBackingType.class, new Template("<!doctype html><html><body><div class='${clazz}'>hello @ShowIf(false)<a href='/hi/${id}'>hideme</a></div></body></html>"));

    assert null != widget : " null ";
    final Respond mockRespond = RespondersForTesting.newRespond();
    widget.render(new TestBackingType("Dhanji", "content", 12), mockRespond);
    final String s = mockRespond.toString();
    assertEquals(s, "<!doctype html><html><body><div class=\"content\">hello </div></body></html>");
  }
View Full Code Here

  }

  @Test
  public final void readEmbedWidgetAndStoreAsPage() {

    Renderable widget = compiler()
        .compile(TestBackingType.class, new Template("<xml><div class='content'>hello @MyFave(should=false)<a href='/hi/${id}'>hideme</a></div></xml>"));

    assert null != widget : " null ";

    //tell pagebook to track this as an embedded widget
    pageBook.embedAs(MyEmbeddedPage.class, MyEmbeddedPage.MY_FAVE_ANNOTATION)
        .apply(Chains.terminal());

    final Respond mockRespond = RespondersForTesting.newRespond();
    widget.render(new TestBackingType("Dhanji", "content", 12), mockRespond);
    final String s = mockRespond.toString();
    assert "<xml><div class=\"content\">hello </div></xml>"
        .equals(s) : "Did not write expected output, instead: " + s;
  }
View Full Code Here


  @Test
  public final void readEmbedWidgetOnly() {

    Renderable widget = compiler()
        .compile(TestBackingType.class, new Template("<html><div class='content'>hello @MyFave(should=false)<a href='/hi/${id}'>hideme</a></div></html>"));

    assert null != widget : " null ";

    //tell pagebook to track this as an embedded widget
    pageBook.embedAs(MyEmbeddedPage.class, MyEmbeddedPage.MY_FAVE_ANNOTATION)
        .apply(Chains.terminal());

    final Respond mockRespond = RespondersForTesting.newRespond();

    widget.render(new TestBackingType("Dhanji", "content", 12), mockRespond);

    final String s = mockRespond.toString();
    assert "<html><div class=\"content\">hello </div></html>"
        .equals(s) : "Did not write expected output, instead: " + s;
  }
View Full Code Here

  }

  public void loadAll(Set<Descriptor> templates) {
    // If in production mode, force load all the templates.
    for (Descriptor template : templates) {
      Renderable compiled = compilers.compile(template.clazz);
      Preconditions.checkArgument(null != compiled, "No template found attached to: %s",
          template.clazz);

      this.templates.put(template.clazz, compiled);
    }
View Full Code Here

      this.templates.put(template.clazz, compiled);
    }
  }

  public String render(Class<?> clazz, Object context) {
    Renderable compiled;
    if (reloadTemplates) {
      compiled = compilers.compile(clazz);

      templates.put(clazz, compiled);
    } else {
      compiled = templates.get(clazz);
    }
    Preconditions.checkArgument(null != compiled, "No template found attached to: %s", clazz);

    StringBuilderRespond respond = new StringBuilderRespond(context);
    //noinspection ConstantConditions
    compiled.render(context, respond);

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

TOP

Related Classes of com.google.sitebricks.Renderable

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.