Package com.google.template.soy.data

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


   * @return The value of the local var.
   */
  private SoyData getLocalVar(String localVarName) {

    for (Map<String, SoyData> envFrame : env) {
      SoyData value = envFrame.get(localVarName);
      if (value != null) {
        return value;
      }
    }

View Full Code Here


   *     nor the template data.
   */
  protected SoyData resolveDataRefFirstKey(DataRefNode dataRefNode) {

    String firstKey = dataRefNode.getFirstKey();
    SoyData value = null;

    if (dataRefNode.isIjDataRef()) {

      if (ijData != null) {
        value = ijData.getSingle(firstKey);
View Full Code Here

    return ImmutableSet.of(1);
  }


  @Override public SoyData compute(List<SoyData> args) {
    SoyData arg = args.get(0);

    if (arg instanceof IntegerData) {
      return arg;
    } else {
      return toSoyData((int) Math.floor(arg.floatValue()));
    }
  }
View Full Code Here

    return ImmutableSet.of(2);
  }


  @Override public SoyData compute(List<SoyData> args) {
    SoyData arg0 = args.get(0);
    SoyData arg1 = args.get(1);

    if (arg0 instanceof IntegerData && arg1 instanceof IntegerData) {
      return toSoyData(Math.min(arg0.integerValue(), arg1.integerValue()));
    } else {
      return toSoyData(Math.min(arg0.numberValue(), arg1.numberValue()));
    }
  }
View Full Code Here

    return ImmutableSet.of(1);
  }


  @Override public SoyData compute(List<SoyData> args) {
    SoyData arg = args.get(0);
    return BooleanData.forValue(! (arg instanceof UndefinedData || arg instanceof NullData));
  }
View Full Code Here

  }


  @Override protected void visitPrintNode(PrintNode node) {

    SoyData result = eval(node.getExprUnion().getExpr());
    if (result instanceof UndefinedData) {
      throw new RenderException(
          "In 'print' tag, expression \"" + node.getExprText() + "\" evaluates to undefined.");
    }

    // Process directives.
    for (PrintDirectiveNode directiveNode : node.getChildren()) {

      // Evaluate directive args.
      List<ExprRootNode<?>> argsExprs = directiveNode.getArgs();
      List<SoyData> argsSoyDatas = Lists.newArrayListWithCapacity(argsExprs.size());
      for (ExprRootNode<?> argExpr : argsExprs) {
        argsSoyDatas.add(evalVisitor.exec(argExpr));
      }

      // Apply directive.
      result = applyDirective(directiveNode.getName(), result, argsSoyDatas, node);
    }

    append(currOutputBuf, result.toString());
  }
View Full Code Here

    env.peek().put(node.getVarName(), eval(node.getValueExpr()));
  }


  @Override protected void visitLetContentNode(LetContentNode node) {
    SoyData renderedBlock = renderBlock(node);

    // If the let 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 let block is wrapped in SanitizedContent of the specified kind.
    // TODO: Consider adding mutable state to nodes that allows the contextual escaper to tag
    // nodes it has processed, and assert presence of this tag here.
    if (node.getContentKind() != null) {
      renderedBlock = UnsafeSanitizedContentOrdainer.ordainAsSafe(
          renderedBlock.stringValue(), node.getContentKind());
    }

    env.peek().put(node.getVarName(), renderedBlock);
  }
View Full Code Here

  }


  @Override protected void visitSwitchNode(SwitchNode node) {

    SoyData switchValue = eval(node.getExpr());

    for (SoyNode child : node.getChildren()) {

      if (child instanceof SwitchCaseNode) {
        SwitchCaseNode scn = (SwitchCaseNode) child;
        for (ExprNode caseExpr : scn.getExprList()) {
          if (switchValue.equals(eval(caseExpr))) {
            visit(scn);
            return;
          }
        }
View Full Code Here

  }


  @Override protected void visitForeachNode(ForeachNode node) {

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

  @Override protected void visitForNode(ForNode node) {

    List<Integer> rangeArgValues = Lists.newArrayList();

    for (ExprNode rangeArg : node.getRangeArgs()) {
      SoyData rangeArgValue = eval(rangeArg);
      if (!(rangeArgValue instanceof IntegerData)) {
        throw new RenderException(
            "In 'for' command " + node.toSourceString() + ", the expression \"" +
            rangeArg.toSourceString() + "\" does not resolve to an integer.");
      }
View Full Code Here

TOP

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

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.