Package com.google.sitebricks

Examples of com.google.sitebricks.Renderable


                    lexicalDescend(pc, child, shouldPopScope);
                }

            } else if (n instanceof TextNode) {
              TextNode child = (TextNode)n;
              Renderable textWidget;
             
                //setup a lexical scope if we're going into a repeat widget (by reading the previous node)
                final boolean shouldPopScope = lexicalClimb(pc, child);

                // construct the text widget
                try {
                  textWidget = registry.textWidget(cleanHtml(n), pc.lexicalScopes.peek());
                 
                  // if there are no annotations, add the text widget to the chain
                  if (!child.hasAttr(ANNOTATION_KEY))  {
                    widgetChain.addWidget(textWidget);
                  }
                  else  {
                    // construct a new widget chain for this text node
                    WidgetChain childsChildren = Chains.proceeding().addWidget(textWidget);
                   
                    // make a new widget for the annotation, making the text chain the child
                    String widgetName = child.attr(ANNOTATION_KEY).toLowerCase();
                    Renderable annotationWidget = registry.newWidget(widgetName, child.attr(ANNOTATION_CONTENT), childsChildren, pc.lexicalScopes.peek());
                    widgetChain.addWidget(annotationWidget);
                  }
                 
                } catch (ExpressionCompileException e) {
                    pc.errors.add(
View Full Code Here


  }
 
  @Test
  public final void readShowIfWidgetTrue() {
   
    Renderable widget =
        new FreemarkerTemplateCompiler()
          .compile(Object.class, template("<html><#if true><p>hello</p></#if></html>"));

    assert null != widget : " null ";

    final StringBuilder builder = new StringBuilder();
    final Respond mockRespond = RespondersForTesting.newRespond();
    widget.render(new Object(), mockRespond);
    final String value = mockRespond.toString();
    System.out.println(value);
    assert "<html><p>hello</p></html>".equals(value) : "Did not write expected output, instead: " + value;
  }
View Full Code Here

    String templateValue = String.format("<html><#if %s><p>hello</p></#if></html>", expression);

    System.out.println( templateValue );
   
    Renderable widget =
        new FreemarkerTemplateCompiler()
            .compile(Object.class, template(templateValue));

    assert null != widget : " null ";

    final StringBuilder builder = new StringBuilder();

    final Respond mockRespond = RespondersForTesting.newRespond();

    widget.render(new Object(), mockRespond);

    final String value = mockRespond.toString();
    System.out.println(value);
    assert "<html><p>hello</p></html>".equals(value) : "Did not write expected output, instead: " + value;
  }
View Full Code Here

    final Evaluator evaluator = new MvelEvaluator();

    final WidgetRegistry registry = injector.getInstance(WidgetRegistry.class);


    Renderable widget =
        new FreemarkerTemplateCompiler()
            .compile(Object.class, template("<html><#if false><p>hello</p></#if></html>"));

    assert null != widget : " null ";

    final StringBuilder builder = new StringBuilder();

    final Respond mockRespond = RespondersForTesting.newRespond();
    widget.render(new Object(), mockRespond);

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

      protected void configure() {
        bind(HttpServletRequest.class).toProvider(mockRequestProviderForContext());
      }
    });

    Renderable widget =
        new FreemarkerTemplateCompiler()
            .compile(Object.class, 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();
    assert "<html><div class='content'>hello <a href='/people/12'>Dhanji</a></div></html>"
        .replace("\"", "'")
        .equals(value) : "Did not write expected output, instead: " + value;
View Full Code Here

  @Test
  public final void readHtmlWidget() {

    final WidgetRegistry registry = injector.getInstance(WidgetRegistry.class);

    Renderable widget =
        new FreemarkerTemplateCompiler()
            .compile(Object.class, 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>"
        .replace( "\"", "'")               
        .equals(s) : "Did not write expected output, instead: " + s;
View Full Code Here

  @Test
  public final void readHtmlWidgetWithChildren() {

    final WidgetRegistry registry = injector.getInstance(WidgetRegistry.class);

    Renderable widget =
        new FreemarkerTemplateCompiler()
            .compile(Object.class, template("<!doctype html><html><body><div class='${clazz}'>hello <#if false><a href='/hi/${id}'>hideme</a></#if></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>".replace("\"", "'"));
  }
View Full Code Here

    @Test(dataProvider = WIDGETS_AND_KEYS)
    public final void storeRetrieveWidgets(final String key, final Class<Renderable> expected) throws ExpressionCompileException {
        final WidgetRegistry registry = new DefaultWidgetRegistry(new MvelEvaluator(), createNiceMock(PageBook.class), createNiceMock(Injector.class));
        registry.add(key, expected);

        Renderable widget = registry.newWidget(key, "some=expression", new ProceedingWidgetChain(), createMock(EvaluatorCompiler.class));

        assert expected.isInstance(widget) : "Wrong widget returned";
    }
View Full Code Here

    pageName = pageName.toLowerCase();

    final PageBook pageBook = createMock(PageBook.class);
    final PageBook.Page page = createMock(PageBook.Page.class);
    final Respond respond = RespondersForTesting.newRespond();
    final Renderable widget = createMock(Renderable.class);

    expect(pageBook.forName(pageName))
        .andReturn(page);


    //mypage does?
    final MyEmbeddedPage myEmbeddedPage = new MyEmbeddedPage();
    expect(page.instantiate())
        .andReturn(myEmbeddedPage);

    expect(page.doMethod(isA(String.class), anyObject(), isA(String.class),
        isA(Request.class)))
        .andReturn(null);
    expect(page.widget())
        .andReturn(widget);

    widget.render(eq(myEmbeddedPage), isA(Respond.class));


    replay(pageBook, page, widget);

    final MvelEvaluator evaluator = new MvelEvaluator();
View Full Code Here

          put("class", "pretty");
          put("id", "a-p-tag");
        }}));
    widget.addWidget(new ShowIfWidget(targetWidgetChain, "true", evaluator));

    Renderable bodyWrapper = new XmlWidget(widget, "body", createMock(EvaluatorCompiler.class), Collections.<String, String>emptyMap());

    expect(pageBook.forName(pageName))
        .andReturn(page);

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.