Package com.google.template.soy.soytree

Examples of com.google.template.soy.soytree.PrintNode


        "  {print 'blah    blahblahblah' |escapeHtml|insertWordBreaks:8}\n";

    List<StandaloneNode> nodes = parseTemplateBody(templateBody);
    assertEquals(4, nodes.size());

    PrintNode pn0 = (PrintNode) nodes.get(0);
    assertEquals(SyntaxVersion.V2, pn0.getSyntaxVersion());
    assertEquals("$boo.foo", pn0.getExprText());
    assertEquals(0, pn0.getChildren().size());
    assertEquals("FOO", pn0.genBasePlaceholderName());
    assertEquals("{$boo.foo}", pn0.toSourceString());
    assertTrue(pn0.getExprUnion().getExpr().getChild(0) instanceof DataRefNode);

    PrintNode pn1 = (PrintNode) nodes.get(1);
    assertTrue(pn0.genSamenessKey().equals(pn1.genSamenessKey()));
    assertTrue(pn1.getExprUnion().getExpr().getChild(0) instanceof DataRefNode);

    PrintNode pn2 = (PrintNode) nodes.get(2);
    assertEquals(SyntaxVersion.V2, pn2.getSyntaxVersion());
    assertEquals("$goo + 1", pn2.getExprText());
    assertEquals(1, pn2.getChildren().size());
    PrintDirectiveNode pn2d0 = pn2.getChild(0);
    assertEquals(SyntaxVersion.V1, pn2d0.getSyntaxVersion());
    assertEquals("|noAutoescape", pn2d0.getName());
    assertEquals("XXX", pn2.genBasePlaceholderName());
    assertTrue(pn2.getExprUnion().getExpr().getChild(0) instanceof PlusOpNode);

    PrintNode pn3 = (PrintNode) nodes.get(3);
    assertEquals(SyntaxVersion.V2, pn3.getSyntaxVersion());
    assertEquals("'blah    blahblahblah'", pn3.getExprText());
    assertEquals(2, pn3.getChildren().size());
    PrintDirectiveNode pn3d0 = pn3.getChild(0);
    assertEquals(SyntaxVersion.V2, pn3d0.getSyntaxVersion());
    assertEquals("|escapeHtml", pn3d0.getName());
    PrintDirectiveNode pn3d1 = pn3.getChild(1);
    assertEquals(SyntaxVersion.V2, pn3d1.getSyntaxVersion());
    assertEquals("|insertWordBreaks", pn3d1.getName());
    assertEquals(8, ((IntegerNode) pn3d1.getArgs().get(0).getChild(0)).getValue());
    assertEquals("XXX", pn3.genBasePlaceholderName());
    assertTrue(pn3.getExprUnion().getExpr().getChild(0) instanceof StringNode);

    assertFalse(pn0.genSamenessKey().equals(pn2.genSamenessKey()));
    assertFalse(pn3.genSamenessKey().equals(pn0.genSamenessKey()));
  }
View Full Code Here


        "  {$boo.foo phname=\"boo_foo\"}\n";

    List<StandaloneNode> nodes = parseTemplateBody(templateBody);
    assertEquals(4, nodes.size());

    PrintNode pn0 = (PrintNode) nodes.get(0);
    assertEquals("$boo.foo", pn0.getExprText());
    assertEquals("FOO", pn0.genBasePlaceholderName());
    assertEquals("{$boo.foo}", pn0.toSourceString());

    PrintNode pn1 = (PrintNode) nodes.get(1);
    assertEquals("$boo.foo", pn1.getExprText());
    assertEquals("BOO_FOO", pn1.genBasePlaceholderName());
    assertEquals("{$boo.foo phname=\"booFoo\"}", pn1.toSourceString());
    assertEquals(SyntaxVersion.V2, pn1.getSyntaxVersion());
    assertEquals(0, pn1.getChildren().size());
    assertTrue(pn1.getExprUnion().getExpr().getChild(0) instanceof DataRefNode);

    PrintNode pn2 = (PrintNode) nodes.get(2);
    assertEquals("$boo.foo", pn2.getExprText());
    assertEquals("BOO_FOO", pn2.genBasePlaceholderName());
    assertEquals("{$boo.foo phname=\"booFoo\"}", pn2.toSourceString());

    PrintNode pn3 = (PrintNode) nodes.get(3);
    assertEquals("$boo.foo", pn3.getExprText());
    assertEquals("BOO_FOO", pn3.genBasePlaceholderName());
    assertEquals("{$boo.foo phname=\"boo_foo\"}", pn3.toSourceString());

    assertFalse(pn0.genSamenessKey().equals(pn1.genSamenessKey()));
    assertTrue(pn1.genSamenessKey().equals(pn2.genSamenessKey()));
    assertFalse(pn1.genSamenessKey().equals(pn3.genSamenessKey()));
  }
View Full Code Here

    parent.removeChild(indexInParent);

    // If this CssNode has componentName, add a PrintNode (with '|id' directive) to print it.
    ExprRootNode<?> componentNameExpr = node.getComponentNameExpr();
    if (componentNameExpr != null) {
      PrintNode pn =
          new PrintNode(nodeIdGen.genId(), false, new ExprUnion(componentNameExpr), null);
      pn.addChild(new PrintDirectiveNode(nodeIdGen.genId(), "|id", ""));
      parent.addChild(indexInParent, pn);
      indexInParent += 1;
    }

    // Add a RawTextNode for the selectorText. Also includes preceding dash ("-") if there is a
View Full Code Here

        }

        // Now rewrite the PrintNode (reusing the old node id).
        String newExprText =
            "(" + currPluralNode.getExpr().toSourceString() + ") - " + currPluralNode.getOffset();
        PrintNode newPrintNode = new PrintNode(node.getId(), node.isImplicit(), newExprText, null);
        newPrintNode.addChildren(node.getChildren());
        node.getParent().replaceChild(node, newPrintNode);
      }
    }
  }
View Full Code Here

      if (cssHandlingScheme == CssHandlingScheme.LITERAL) {
        newNode = new RawTextNode(nodeIdGen.genId(), cssNode.getCommandText());

      } else if (cssHandlingScheme == CssHandlingScheme.REFERENCE) {
        PrintNode newPrintNode =
            new PrintNode(nodeIdGen.genId(), false, cssNode.getCommandText(), null);
        newPrintNode.addChild(new PrintDirectiveNode(nodeIdGen.genId(), "|noAutoescape", ""));
        newNode = newPrintNode;
        // Check that the expression is a valid reference.
        boolean isInvalidExpr = false;
        if (newPrintNode.getExprUnion().getExpr() == null) {
          isInvalidExpr = true;
        } else {
          ExprNode exprNode = newPrintNode.getExprUnion().getExpr().getChild(0);
          if (! (exprNode instanceof DataRefNode || exprNode instanceof GlobalNode)) {
            isInvalidExpr = true;
          }
        }
        if (isInvalidExpr) {
View Full Code Here

    // After.
    assertEquals(5, template.numChildren());
    RawTextNode rtn0 = (RawTextNode) template.getChild(0);
    assertEquals("<div class=\"AAA ", rtn0.getRawText());
    PrintNode pn1 = (PrintNode) template.getChild(1);
    assertEquals("$goo", pn1.getExprText());
    RawTextNode rtn2 = (RawTextNode) template.getChild(2);
    assertEquals("-AAA BBB ", rtn2.getRawText());
    PrintNode pn3 = (PrintNode) template.getChild(3);
    assertEquals("$goo", pn3.getExprText());
    RawTextNode rtn4 = (RawTextNode) template.getChild(4);
    assertEquals("-BBB\">", rtn4.getRawText());
  }
View Full Code Here

    // After.
    assertEquals(5, template.numChildren());
    RawTextNode rtn0 = (RawTextNode) template.getChild(0);
    assertEquals("<div class=\"XXX ", rtn0.getRawText());
    PrintNode pn1 = (PrintNode) template.getChild(1);
    assertEquals("$goo", pn1.getExprText());
    RawTextNode rtn2 = (RawTextNode) template.getChild(2);
    assertEquals("-XXX BBB ", rtn2.getRawText());
    PrintNode pn3 = (PrintNode) template.getChild(3);
    assertEquals("$goo", pn3.getExprText());
    RawTextNode rtn4 = (RawTextNode) template.getChild(4);
    assertEquals("-BBB\">", rtn4.getRawText());
  }
View Full Code Here

        "{/template}\n";

    SoyFileSetNode soyTree = SharedTestUtils.parseSoyFiles(testFileContent);

    TemplateNode template = soyTree.getChild(0).getChild(0);
    PrintNode a = (PrintNode) template.getChild(0);
    PrintNode bc = (PrintNode) template.getChild(1);
    IfNode ifNode = (IfNode) template.getChild(2);
    IfCondNode ifCondNode = (IfCondNode) ifNode.getChild(0);
    PrintNode e = (PrintNode) ifCondNode.getChild(0);
    ForeachNode foreachNode = (ForeachNode) ifCondNode.getChild(1);
    ForeachNonemptyNode foreachNonemptyNode = (ForeachNonemptyNode) foreachNode.getChild(0);
    PrintNode f = (PrintNode) foreachNonemptyNode.getChild(0);
    PrintNode gh = (PrintNode) foreachNonemptyNode.getChild(1);
    PrintDirectiveNode ghPdn = gh.getChild(0);
    MsgNode msgNode = (MsgNode) foreachNonemptyNode.getChild(2);
    MsgPlaceholderNode iPh = (MsgPlaceholderNode) msgNode.getChild(0);
    PrintNode i = (PrintNode) iPh.getChild(0);
    MsgPlaceholderNode callPh = (MsgPlaceholderNode) msgNode.getChild(1);
    CallNode callNode = (CallNode) callPh.getChild(0);
    CallParamValueNode cpvn = (CallParamValueNode) callNode.getChild(0);
    CallParamContentNode cpcn = (CallParamContentNode) callNode.getChild(1);
    PrintNode n = (PrintNode) cpcn.getChild(0);
    PrintNode fo = (PrintNode) cpcn.getChild(1);

    // Build the nearest-dependee map.
    Map<SoyNode, List<SoyNode>> allDependeesMap = (new BuildAllDependeesMapVisitor()).exec(soyTree);

    assertEquals(ImmutableList.of(template), allDependeesMap.get(a));
View Full Code Here

TOP

Related Classes of com.google.template.soy.soytree.PrintNode

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.