Package com.google.sitebricks

Examples of com.google.sitebricks.Renderable


  @Test
  public final void dispatchRequestAndRespondOnGet() throws IOException {
    final HttpServletRequest request = createMock(HttpServletRequest.class);
    PageBook pageBook = createMock(PageBook.class);
    PageBook.Page page = createMock(PageBook.Page.class);
    Renderable widget = createMock(Renderable.class);
    final Respond respond = createMock(Respond.class);
    RequestBinder binder = createMock(RequestBinder.class);

    Object pageOb = new Object();


    expect(request.getRequestURI())
        .andReturn("/thing")
        .anyTimes();

    expect(request.getContextPath())
        .andReturn("")
        .anyTimes();

    expect(request.getParameterMap())
        .andReturn(new HashMap())
        .anyTimes();

    expect(pageBook.get("/thing"))
        .andReturn(page);

    binder.bind(request, pageOb);
    expectLastCall().once();

    expect(page.isHeadless())
        .andReturn(false);

    expect(page.widget())
        .andReturn(widget);

    expect(page.instantiate())
        .andReturn(pageOb);

    expect(request.getMethod())
        .andReturn("GET");

    expect(page.doMethod("get", pageOb, "/thing", request))
        .andReturn(null);


    widget.render(pageOb, respond);
    expectLastCall().once();


    replay(request, page, pageBook, widget, respond, binder);
View Full Code Here


  @Test
  public final void dispatchRequestToCorrectEventHandlerOnGet() throws IOException {
    final HttpServletRequest request = createMock(HttpServletRequest.class);
    PageBook pageBook = createMock(PageBook.class);
    PageBook.Page page = createMock(PageBook.Page.class);
    Renderable widget = createMock(Renderable.class);
    final Respond respond = createMock(Respond.class);
    RequestBinder binder = createMock(RequestBinder.class);

    Object pageOb = new Object();


    expect(request.getRequestURI())
        .andReturn("/thing")
        .anyTimes();

    expect(request.getContextPath())
        .andReturn("")
        .anyTimes();

    expect(pageBook.get("/thing"))
        .andReturn(page);

    binder.bind(request, pageOb);
    expectLastCall().once();


    expect(page.isHeadless())
        .andReturn(false);

    expect(page.widget())
        .andReturn(widget);

    expect(page.instantiate())
        .andReturn(pageOb);

    expect(request.getMethod())
        .andReturn("GET");

    final HashMap<String, String[]> parameterMap = new HashMap<String, String[]>();
    expect(request.getParameterMap())
        .andReturn(parameterMap)
        .anyTimes();

    expect(page.doMethod("get", pageOb, "/thing", request))
        .andReturn(null);

    widget.render(pageOb, respond);
    expectLastCall().once();


    replay(request, page, pageBook, widget, respond, binder);
View Full Code Here

  @Test
  public final void dispatchRequestAndRespondOnPost() throws IOException {
    final HttpServletRequest request = createMock(HttpServletRequest.class);
    PageBook pageBook = createMock(PageBook.class);
    PageBook.Page page = createMock(PageBook.Page.class);
    Renderable widget = createMock(Renderable.class);
    final Respond respond = createMock(Respond.class);
    RequestBinder binder = createMock(RequestBinder.class);

    Object pageOb = new Object();

    expect(request.getRequestURI())
        .andReturn("/thing")
        .anyTimes();

    expect(request.getContextPath())
        .andReturn("")
        .anyTimes();

    expect(request.getParameterMap())
        .andReturn(new HashMap())
        .anyTimes();

    expect(pageBook.get("/thing"))
        .andReturn(page);

    binder.bind(request, pageOb);
    expectLastCall().once();


    expect(page.isHeadless())
        .andReturn(false);

    expect(page.widget())
        .andReturn(widget);

    expect(page.instantiate())
        .andReturn(pageOb);

    expect(request.getMethod())
        .andReturn("POST");

    //noinspection unchecked
    expect(page.doMethod(matches("post"), eq(pageOb), eq("/thing"), isA(HttpServletRequest.class)))
        .andReturn(null);
//        expectLastCall().once();


    widget.render(pageOb, respond);
    expectLastCall().once();


    replay(request, page, pageBook, widget, respond, binder);
View Full Code Here

  @Test
  public final void dispatchRequestAndRedirectOnPost() throws IOException {
    final HttpServletRequest request = createMock(HttpServletRequest.class);
    PageBook pageBook = createMock(PageBook.class);
    PageBook.Page page = createMock(PageBook.Page.class);
    Renderable widget = createMock(Renderable.class);
    final Respond respond = createMock(Respond.class);
    RequestBinder binder = createMock(RequestBinder.class);

    Object pageOb = new Object();
View Full Code Here

  @Test
  public final void dispatchRequestAndRedirectOnGet() throws IOException {
    final HttpServletRequest request = createMock(HttpServletRequest.class);
    PageBook pageBook = createMock(PageBook.class);
    PageBook.Page page = createMock(PageBook.Page.class);
    Renderable widget = createMock(Renderable.class);
    final Respond respond = createMock(Respond.class);
    RequestBinder binder = createMock(RequestBinder.class);

    Object pageOb = new Object();
View Full Code Here

    if (TEXT_WIDGET.equals(key))
      return new TextWidget(null, compiler);

    //otherwise construct via reflection (all sitebricks MUST have
    // a constructor with: widgetchain, expression, evaluator; in that order)
    final Renderable widget = widgets
        .get(key)
        .newWidget(widgetChain, expression, evaluator, pageBook);

    //add some injection (some sitebricks require it). It's a bit hacky, maybe we can reimplement some stuff later with @AssistedInject
    injector.injectMembers(widget);
View Full Code Here

                    lexicalDescend(child, shouldPopScope);
                }

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

                // construct the text widget
                try {
                  textWidget = registry.textWidget(cleanHtml(n), 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, lexicalScopes.peek());
                    widgetChain.addWidget(annotationWidget);
                  }
                 
                } catch (ExpressionCompileException e) {
                    errors.add(
View Full Code Here

              ". You must use @Show on a superclass of an @Extension page");
        }
      }
    }

    Renderable widget = compile(templateClass);

    //apply the compiled widget chain to the page (completing compile step)
    page.apply(widget);
  }
View Full Code Here

  @Override
  public Renderable compile(Class<?> templateClass) {
    final Template template = loader.load(templateClass);

    Renderable widget;

    //is this an HTML, XML, or a flat-file template?
    switch(template.getKind()) {
      default:
      case HTML:
View Full Code Here

  public Renderable compile(String template) {
    // Compile template immediately.
    final CompiledTemplate compiledTemplate = TemplateCompiler.compileTemplate(template);

    return new Renderable() {
      @Override
      public void render(Object bound, Respond respond) {
        assert page.isInstance(bound);
        respond.write(TemplateRuntime.execute(compiledTemplate, bound).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.