Package com.google.template.soy.data

Examples of com.google.template.soy.data.SoyListData


  // -----------------------------------------------------------------------------------------------
  // Implementations for collections.


  @Override protected SoyData visitListLiteralNode(ListLiteralNode node) {
    return new SoyListData(visitChildren(node));
  }
View Full Code Here


    if (!(dataRefValue instanceof SoyListData)) {
      throw new RenderException(
          "In 'foreach' command " + node.toSourceString() +
          ", the data reference does not resolve to a SoyListData.");
    }
    SoyListData foreachList = (SoyListData) dataRefValue;

    if (foreachList.length() > 0) {
      // Case 1: Nonempty list.
      String varName = node.getVarName();

      Map<String, SoyData> newEnvFrame = Maps.newHashMap();
      // Note: No need to save firstIndex as it's always 0.
      newEnvFrame.put(varName + "__lastIndex", IntegerData.forValue(foreachList.length() - 1));
      env.push(newEnvFrame);

      for (int i = 0; i < foreachList.length(); ++i) {
        newEnvFrame.put(varName + "__index", IntegerData.forValue(i));
        newEnvFrame.put(varName, foreachList.get(i));
        visitChildren((ForeachNonemptyNode) node.getChild(0));
      }

      env.pop();
View Full Code Here

    SoyData arg = args.get(0);

    if (! (arg instanceof SoyMapData)) {
      throw new IllegalArgumentException("Argument to keys() function is not SoyMapData.");
    }
    return new SoyListData(((SoyMapData) arg).getKeys());
  }
View Full Code Here

      if (nextCollectionData == null) {
        // Create the SoyData object that will be bound to keys.get(i). We need to check the first
        // part of keys[i+1] to know whether to create a SoyMapData or SoyListData (checking the
        // first char is sufficient).
        nextCollectionData =
            (Character.isDigit(keys.get(i + 1).charAt(0))) ? new SoyListData() : new SoyMapData();
        collectionData.putSingle(keys.get(i), nextCollectionData);
      }
      collectionData = nextCollectionData;
    }
View Full Code Here


  public void testComputeForTofu() {

    LengthFunction lengthFunction = new LengthFunction();
    SoyData list = new SoyListData(1, 3, 5, 7);
    assertEquals(IntegerData.forValue(4),
                 lengthFunction.computeForTofu(ImmutableList.of(list)));
  }
View Full Code Here

    KeysFunction keysFunction = new KeysFunction();
    SoyData map = new SoyMapData("boo", "bar", "foo", 2, "goo", new SoyMapData("moo", 4));
    SoyData result = keysFunction.computeForTofu(ImmutableList.of(map));

    assertTrue(result instanceof SoyListData);
    SoyListData resultAsList = (SoyListData) result;
    assertEquals(3, resultAsList.length());

    Set<String> resultItems = Sets.newHashSet();
    for (SoyData item : resultAsList) {
      resultItems.add(item.stringValue());
    }
View Full Code Here

        .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());
  }
View Full Code Here

        .setData(ImmutableMap.of("name", "Hal")).setMsgBundle(msgBundle).render());
    System.out.println(tofu.newRenderer(DEMO_SWITCH)
        .setData(ImmutableMap.of("name", "Ivy")).setMsgBundle(msgBundle).render());

    writeExampleHeader("demoForeach");
    SoyListData persons = new SoyListData();
    persons.add(new SoyMapData("name", "Jen", "numWaffles", 1));
    persons.add(new SoyMapData("name", "Kai", "numWaffles", 3));
    persons.add(new SoyMapData("name", "Lex", "numWaffles", 1));
    persons.add(new SoyMapData("name", "Mel", "numWaffles", 2));
    System.out.println(tofu.newRenderer(DEMO_FOREACH)
        .setData(new SoyMapData(DEMO_FOREACH.PERSONS, persons))
        .setMsgBundle(msgBundle)
        .render());

    writeExampleHeader("demoFor");
    System.out.println(tofu.newRenderer(DEMO_FOR)
        .setData(new SoyMapData(DEMO_FOR.NUM_LINES, 3))
        .setMsgBundle(msgBundle)
        .render());

    writeExampleHeader("demoCallWithoutParam");
    System.out.println(tofu.newRenderer(DEMO_CALL_WITHOUT_PARAM)
        .setData(new SoyMapData(
                     DEMO_CALL_WITHOUT_PARAM.NAME, "Neo",
                     DEMO_CALL_WITHOUT_PARAM.TRIP_INFO,
                         new SoyMapData("name", "Neo", "destination", "The Matrix")))
        .setMsgBundle(msgBundle)
        .render());

    writeExampleHeader("demoCallWithParam");
    System.out.println(tofu.newRenderer(DEMO_CALL_WITH_PARAM)
        .setData(ImmutableMap.of(
                 DEMO_CALL_WITH_PARAM.NAME, "Oz",
                 DEMO_CALL_WITH_PARAM.COMPANION_NAME, "Pip",
                 DEMO_CALL_WITH_PARAM.DESTINATIONS,
                 ImmutableList.of("Gillikin Country", "Munchkin Country",
                                  "Quadling Country", "Winkie Country")))
        .setMsgBundle(msgBundle)
        .render());

    writeExampleHeader("demoCallWithParamBlock");
    System.out.println(tofu.newRenderer(DEMO_CALL_WITH_PARAM_BLOCK)
        .setData(new SoyMapData(DEMO_CALL_WITH_PARAM_BLOCK.NAME, "Quo"))
        .setMsgBundle(msgBundle)
        .render());

    writeExampleHeader("demoExpressions");
    SoyListData students = new SoyListData();
    students.add(new SoyMapData("name", "Rob", "major", "Physics", "year", 1999));
    students.add(new SoyMapData("name", "Sha", "major", "Finance", "year", 1980));
    students.add(new SoyMapData("name", "Tim", "major", "Engineering", "year", 2005));
    students.add(new SoyMapData("name", "Uma", "major", "Biology", "year", 1972));
    System.out.println(tofu.newRenderer(DEMO_EXPRESSIONS)
        .setData(new SoyMapData(DEMO_EXPRESSIONS.STUDENTS, students,
                                DEMO_EXPRESSIONS.CURRENT_YEAR, 2008))
        .setMsgBundle(msgBundle)
        .render());
View Full Code Here

TOP

Related Classes of com.google.template.soy.data.SoyListData

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.