PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/sitebricks/src/main/java/com/google/sitebricks/rendering/control/HeaderWidget.java

http://github.com/dhanji/sitebricks
Java | 46 lines | 31 code | 11 blank | 4 comment | 0 complexity | cab3905eea475fee8d081139b35f19b9 MD5 | raw file
 1package com.google.sitebricks.rendering.control;
 2
 3import com.google.sitebricks.Renderable;
 4import com.google.sitebricks.Respond;
 5import com.google.sitebricks.compiler.EvaluatorCompiler;
 6import com.google.sitebricks.compiler.ExpressionCompileException;
 7import com.google.sitebricks.compiler.Token;
 8import com.google.sitebricks.rendering.SelfRendering;
 9
10import java.util.List;
11import java.util.Map;
12import java.util.Set;
13
14/**
15 * @author Dhanji R. Prasanna (dhanji@gmail.com)
16 */
17@SelfRendering
18class HeaderWidget implements Renderable {
19  private final WidgetChain widgetChain;
20  private Map<String, List<Token>> attribs;
21
22  public HeaderWidget(WidgetChain widgetChain, Map<String, String> attribs,
23                      EvaluatorCompiler compiler) throws ExpressionCompileException {
24
25    this.widgetChain = widgetChain;
26    this.attribs = XmlWidget.compile(attribs, compiler);
27  }
28
29  public void render(Object bound, Respond respond) {
30    XmlWidget.writeOpenTag(bound, respond, "head", attribs);
31
32    respond.write('>');
33
34    //render children (as necessary)
35    widgetChain.render(bound, respond);
36
37    respond.withHtml()
38        .headerPlaceholder(); //TODO replace placeholder with an index?
39    respond.write("</head>");
40  }
41
42
43  public <T extends Renderable> Set<T> collect(Class<T> clazz) {
44    return widgetChain.collect(clazz);
45  }
46}