Search in sources :

Example 16 with SoyMapData

use of com.google.template.soy.data.SoyMapData in project closure-templates by google.

the class SimpleUsage method main.

/**
 * Prints the generated HTML to stdout.
 *
 * @param args Not used.
 */
public static void main(String[] args) {
    // Compile the template.
    SoyFileSet sfs = SoyFileSet.builder().add(Resources.getResource("simple.soy")).build();
    SoyTofu tofu = sfs.compileToTofu();
    // Example 1.
    writeExampleHeader();
    System.out.println(tofu.newRenderer("soy.examples.simple.helloWorld").render());
    // Create a namespaced tofu object to make calls more concise.
    SoyTofu simpleTofu = tofu.forNamespace("soy.examples.simple");
    // Example 2.
    writeExampleHeader();
    System.out.println(simpleTofu.newRenderer(".helloName").setData(new SoyMapData("name", "Ana")).render());
    // Example 3.
    writeExampleHeader();
    System.out.println(simpleTofu.newRenderer(".helloNames").setData(new SoyMapData("names", new SoyListData("Bob", "Cid", "Dee"))).render());
}
Also used : SoyMapData(com.google.template.soy.data.SoyMapData) SoyFileSet(com.google.template.soy.SoyFileSet) SoyTofu(com.google.template.soy.tofu.SoyTofu) SoyListData(com.google.template.soy.data.SoyListData)

Example 17 with SoyMapData

use of com.google.template.soy.data.SoyMapData in project gitiles by GerritCodeReview.

the class HostIndexServletTest method rootHtml.

@Test
public void rootHtml() throws Exception {
    Map<String, ?> data = buildData("/");
    assertThat(data).containsEntry("hostName", URLS.getHostName(null));
    assertThat(data).containsEntry("breadcrumbs", NullData.INSTANCE);
    assertThat(data).containsEntry("prefix", "");
    SoyListData repos = (SoyListData) data.get("repositories");
    assertThat(repos).hasSize(1);
    SoyMapData ent = (SoyMapData) repos.get(0);
    assertThat(ent.get("name").toString()).isEqualTo(NAME);
    assertThat(ent.get("url").toString()).isEqualTo("/b/" + NAME + "/");
}
Also used : SoyMapData(com.google.template.soy.data.SoyMapData) SoyListData(com.google.template.soy.data.SoyListData) Test(org.junit.Test)

Aggregations

SoyMapData (com.google.template.soy.data.SoyMapData)17 Test (org.junit.Test)9 SoyListData (com.google.template.soy.data.SoyListData)8 SoyTofu (com.google.template.soy.tofu.SoyTofu)3 TraceAttributes (com.facebook.buck.util.trace.BuildTraces.TraceAttributes)2 SoyFileSet (com.google.template.soy.SoyFileSet)2 Matcher (java.util.regex.Matcher)2 Nullable (javax.annotation.Nullable)2 Request (org.eclipse.jetty.server.Request)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Splitter (com.google.common.base.Splitter)1 Injector (com.google.inject.Injector)1 SoyModule (com.google.template.soy.SoyModule)1 SanitizedContent (com.google.template.soy.data.SanitizedContent)1 SoyData (com.google.template.soy.data.SoyData)1 SoyDataException (com.google.template.soy.data.SoyDataException)1 SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)1 SoyMsgBundleHandler (com.google.template.soy.msgs.SoyMsgBundleHandler)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1