Package com.google.template.soy.soytree

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


        CallParamValueNode cpvn = (CallParamValueNode) child;
        JavaExpr valueJavaExpr = ttjev.exec(cpvn.getValueExprUnion().getExpr());
        paramsObjSb.append(valueJavaExpr.getText());

      } else {
        CallParamContentNode cpcn = (CallParamContentNode) child;

        if (cpcn.getContentKind() != null) {
          throw SoySyntaxExceptionUtils.createWithNode(
              "JavaSrc backend doesn't support param blocks with 'kind' attribute.", cpcn);
        }

        if (isComputableAsJavaExprsVisitor.exec(cpcn)) {
          List<JavaExpr> cpcnJavaExprs =
              genJavaExprsVisitorFactory.create(localVarTranslations).exec(cpcn);
          JavaExpr valueJavaExpr = JavaExprUtils.concatJavaExprs(cpcnJavaExprs);
          paramsObjSb.append(valueJavaExpr.getText());

        } else {
          // This is a param with content that cannot be represented as Java expressions, so we
          // assume that code has been generated to define the temporary variable 'param<n>'.
          if (javaSrcOptions.getCodeStyle() == SoyJavaSrcOptions.CodeStyle.STRINGBUILDER) {
            paramsObjSb.append("param").append(cpcn.getId()).append(".toString()");
          } else {
            paramsObjSb.append("param").append(cpcn.getId());
          }
        }
      }
    }
View Full Code Here


      if (child instanceof CallParamValueNode) {
        callData.putSingle(
            child.getKey(), eval(((CallParamValueNode) child).getValueExprUnion().getExpr()));

      } else if (child instanceof CallParamContentNode) {
        CallParamContentNode childCpcn = (CallParamContentNode) child;
        SoyData renderedBlock = renderBlock(childCpcn);

        // If the param node has a content kind attribute, it will have been autoescaped in the
        // corresponding context by the strict contextual autoescaper. Hence, the result of
        // evaluating the param block is wrapped in SanitizedContent of the specified kind.
        if (childCpcn.getContentKind() != null) {
          renderedBlock = UnsafeSanitizedContentOrdainer.ordainAsSafe(
              renderedBlock.stringValue(), childCpcn.getContentKind());
        }

        callData.putSingle(child.getKey(), renderedBlock);

      } else {
View Full Code Here

        JsExpr valueJsExpr = jsExprTranslator.translateToJsExpr(
            cpvn.getValueExprUnion().getExpr(), cpvn.getValueExprText(), localVarTranslations);
        paramsObjSb.append(valueJsExpr.getText());

      } else {
        CallParamContentNode cpcn = (CallParamContentNode) child;
        JsExpr valueJsExpr;
        if (isComputableAsJsExprsVisitor.exec(cpcn)) {
          valueJsExpr = JsExprUtils.concatJsExprs(
              genJsExprsVisitorFactory.create(localVarTranslations).exec(cpcn));
        } else {
          // This is a param with content that cannot be represented as JS expressions, so we assume
          // that code has been generated to define the temporary variable 'param<n>'.
          String paramExpr = "param" + cpcn.getId();
          if (jsSrcOptions.getCodeStyle() == SoyJsSrcOptions.CodeStyle.STRINGBUILDER) {
            paramExpr += ".toString()";
          }
          valueJsExpr = new JsExpr(paramExpr, Integer.MAX_VALUE);
        }

        // If the param node had a content kind specified, it was autoescaped in the
        // corresponding context. Hence the result of evaluating the param block is wrapped
        // in a SanitizedContent instance of the appropriate kind.

        // The expression for the constructor of SanitizedContent of the appropriate kind (e.g.,
        // "new SanitizedHtml"), or null if the node has no 'kind' attribute.
        valueJsExpr = JsExprUtils.maybeWrapAsSanitizedContent(cpcn.getContentKind(), valueJsExpr);

        paramsObjSb.append(valueJsExpr.getText());
      }
    }
View Full Code Here

    CallParamValueNode cn2cpvn0 = (CallParamValueNode) cn2.getChild(0);
    assertEquals("yoo", cn2cpvn0.getKey());
    assertEquals("round($too)", cn2cpvn0.getValueExprText());
    assertTrue(cn2cpvn0.getValueExprUnion().getExpr().getChild(0) instanceof FunctionNode);

    CallParamContentNode cn2cpcn1 = (CallParamContentNode) cn2.getChild(1);
    assertEquals("woo", cn2cpcn1.getKey());
    assertEquals("poo", ((RawTextNode) cn2cpcn1.getChild(0)).getRawText());
  }
View Full Code Here

    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

      assertEquals("round($too)", cn2cpvn0.getValueExprText());
      assertTrue(cn2cpvn0.getValueExprUnion().getExpr().getChild(0) instanceof FunctionNode);
    }

    {
      final CallParamContentNode cn2cpcn1 = (CallParamContentNode) cn2.getChild(1);
      assertEquals("woo", cn2cpcn1.getKey());
      assertNull(cn2cpcn1.getContentKind());
      assertEquals("poo", ((RawTextNode) cn2cpcn1.getChild(0)).getRawText());
    }

    {
      final CallParamContentNode cn2cpcn2 = (CallParamContentNode) cn2.getChild(2);
      assertEquals("doo", cn2cpcn2.getKey());
      assertNotNull(cn2cpcn2.getContentKind());
      assertEquals(ContentKind.HTML, cn2cpcn2.getContentKind());
      assertEquals("doopoo", ((RawTextNode) cn2cpcn2.getChild(0)).getRawText());
    }

    CallBasicNode cn3 = (CallBasicNode) nodes.get(3);
    assertEquals(SyntaxVersion.V2, cn3.getSyntaxVersion());
    assertEquals(null, cn3.getCalleeName());
    assertEquals(".booTemplate_", cn3.getSrcCalleeName());
    assertEquals(false, cn3.isPassingData());
    assertEquals(false, cn3.isPassingAllData());
    assertEquals(null, cn3.getDataExpr());
    assertEquals("XXX", cn3.genBasePlaceholderName());
    assertEquals(0, cn3.numChildren());

    CallBasicNode cn4 = (CallBasicNode) nodes.get(4);
    assertEquals(SyntaxVersion.V2, cn4.getSyntaxVersion());
    assertEquals(null, cn4.getCalleeName());
    assertEquals(".zooTemplate", cn4.getSrcCalleeName());
    assertEquals(true, cn4.isPassingData());
    assertEquals(false, cn4.isPassingAllData());
    assertTrue(cn4.getDataExpr().getChild(0) != null);
    assertEquals("$animals", cn4.getDataExpr().toSourceString());
    assertEquals(4, cn4.numChildren());

    {
      final CallParamValueNode cn4cpvn0 = (CallParamValueNode) cn4.getChild(0);
      assertEquals("yoo", cn4cpvn0.getKey());
      assertEquals("round($too)", cn4cpvn0.getValueExprText());
      assertTrue(cn4cpvn0.getValueExprUnion().getExpr().getChild(0) instanceof FunctionNode);
    }

    {
      final CallParamContentNode cn4cpcn1 = (CallParamContentNode) cn4.getChild(1);
      assertEquals("woo", cn4cpcn1.getKey());
      assertNull(cn4cpcn1.getContentKind());
      assertEquals("poo", ((RawTextNode) cn4cpcn1.getChild(0)).getRawText());
    }

    {
      final CallParamValueNode cn4cpvn2 = (CallParamValueNode) cn4.getChild(2);
      assertEquals("zoo", cn4cpvn2.getKey());
      assertEquals("0", cn4cpvn2.getValueExprText());
    }

    {
      final CallParamContentNode cn4cpcn3 = (CallParamContentNode) cn4.getChild(3);
      assertEquals("doo", cn4cpcn3.getKey());
      assertNotNull(cn4cpcn3.getContentKind());
      assertEquals(ContentKind.HTML, cn4cpcn3.getContentKind());
      assertEquals("doopoo", ((RawTextNode) cn4cpcn3.getChild(0)).getRawText());
    }
  }
View Full Code Here

TOP

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

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.