Examples of TemplateNode


Examples of cambridge.model.TemplateNode

      return template;
   }

   private void getNode() throws IOException, TemplateParsingException {
      TemplateNode node;
      switch (currentToken.getType()) {
         case COMMENT:
            node = new CommentNode();
            CommentNode comment = (CommentNode) node;
            comment.setContents(currentToken.getValue());
            node.setBeginLine(currentToken.getLineNo());
            node.setBeginColumn(currentToken.getColumn());
            node.setEndLine(peek(1).getLineNo());
            node.setEndColumn(peek(1).getColumn());
            matchedNodes.add(node);
            break;
         case CDATA:
         case DOC_TYPE:
         case EOL:
         case STRING:
         case WS:
            node = textNode();
            matchedNodes.add(node);
            break;
         case EXPRESSION:
            node = expression();
            matchedNodes.add(node);
            break;
         case EXTENSION:
            ExtensionToken tok = (ExtensionToken) currentToken;
            node = tok.createNode(expressionLanguage);
            matchedNodes.add(node);
            break;
         case OPEN_TAG:
            node = tag();
            matchedNodes.add(node);
            break;
         case PARSER_DIRECTIVE:
            node = parserDirective();
            if (node != null) {
               matchedNodes.add(node);
            }
            break;
         case CLOSE_TAG:
            CloseTagToken token = (CloseTagToken) currentToken;
            TagNode tag = null;
            int openIndex = -1;
            for (int i = matchedNodes.size() - 1; i != -1; i--) {
               TemplateNode n = matchedNodes.get(i);
               if (n instanceof TagNode) {
                  TagNode tn = (TagNode) n;
                  if (tn.getEndLine() == 0 && tn.getEndColumn() == 0 && tn.tagNameString.equals(token.getTagName())) {
                     tag = tn;
                     openIndex = i;
                     break;
                  }
               }
            }

            if (openIndex != -1 && tag != null) {
               ArrayList<TemplateNode> sub = new ArrayList<TemplateNode>();
               for (int i = openIndex + 1; i < matchedNodes.size(); i++) {
                  TemplateNode n = matchedNodes.get(i);
                  n.setParent(tag);
                  sub.add(n);
               }

               tag.addChildren(sub);
View Full Code Here

Examples of cambridge.model.TemplateNode

        return template;
    }

    private void getNode() throws IOException, TemplateParsingException {
        TemplateNode node;
        switch (currentToken.getType()) {
            case COMMENT:
                node = new CommentNode();
                CommentNode comment = (CommentNode) node;
                comment.setContents(currentToken.getValue());
                node.setBeginLine(currentToken.getLineNo());
                node.setBeginColumn(currentToken.getColumn());
                node.setEndLine(peek(1).getLineNo());
                node.setEndColumn(peek(1).getColumn());
                matchedNodes.add(node);
                break;
            case CDATA:
            case DOC_TYPE:
            case EOL:
            case STRING:
            case WS:
                node = textNode();
                matchedNodes.add(node);
                break;
            case EXPRESSION:
                node = expression();
                matchedNodes.add(node);
                break;
            case EXTENSION:
                ExtensionToken tok = (ExtensionToken) currentToken;
                node = tok.createNode(expressionLanguage);
                matchedNodes.add(node);
                break;
            case OPEN_TAG:
                node = tag();
                matchedNodes.add(node);
                break;
            case PARSER_DIRECTIVE:
                node = parserDirective();
                if (node != null) {
                    matchedNodes.add(node);
                }
                break;
            case CLOSE_TAG:
                CloseTagToken token = (CloseTagToken) currentToken;
                TagNode tag = null;
                int openIndex = -1;
                for (int i = matchedNodes.size() - 1; i != -1; i--) {
                    TemplateNode n = matchedNodes.get(i);
                    if (n instanceof TagNode) {
                        TagNode tn = (TagNode) n;
                        if (tn.getEndLine() == 0 && tn.getEndColumn() == 0 && tn.tagNameString.equals(token.getTagName())) {
                            tag = tn;
                            openIndex = i;
                            break;
                        }
                    }
                }

                if (openIndex != -1 && tag != null) {
                    ArrayList<TemplateNode> sub = new ArrayList<TemplateNode>();
                    for (int i = openIndex + 1; i < matchedNodes.size(); i++) {
                        TemplateNode n = matchedNodes.get(i);
                        n.setParent(tag);
                        sub.add(n);
                    }

                    tag.addChildren(sub);
View Full Code Here

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

   
    SoyFileSetNode soyTree = SharedTestUtils.parseSoyFiles(source);
    new CheckEscapingSanityVisitor().exec(soyTree);
    new ContextualAutoescaper(SOY_PRINT_DIRECTIVES).rewrite(
        soyTree, false /* assumeNoExternalCalls */);
    TemplateNode mainTemplate = soyTree.getChild(0).getChild(0);
    assertEquals("Sanity check", "ns.main", mainTemplate.getTemplateName());
    final List<CallNode> callNodes = SharedTestUtils.getAllNodesOfType(
        mainTemplate, CallNode.class);
    assertEquals(4, callNodes.size());
    assertEquals("HTML->HTML escaping should be pruned",
        ImmutableList.of(), callNodes.get(0).getEscapingDirectiveNames());
View Full Code Here

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

   
    SoyFileSetNode soyTree = SharedTestUtils.parseSoyFiles(source);
    new CheckEscapingSanityVisitor().exec(soyTree);
    new ContextualAutoescaper(SOY_PRINT_DIRECTIVES).rewrite(
        soyTree, false /* assumeNoExternalCalls */);
    TemplateNode mainTemplate = soyTree.getChild(0).getChild(0);
    assertEquals("Sanity check", "ns.main", mainTemplate.getTemplateName());
    final List<CallNode> callNodes = SharedTestUtils.getAllNodesOfType(
        mainTemplate, CallNode.class);
    assertEquals(1, callNodes.size());
    assertEquals("Escaping should be there since there might be extern delegates",
        ImmutableList.of("|escapeHtml"), callNodes.get(0).getEscapingDirectiveNames());
View Full Code Here

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

   
    SoyFileSetNode soyTree = SharedTestUtils.parseSoyFiles(source);
    new CheckEscapingSanityVisitor().exec(soyTree);
    new ContextualAutoescaper(SOY_PRINT_DIRECTIVES).rewrite(
        soyTree, true /* assumeNoExternalCalls */);
    TemplateNode mainTemplate = soyTree.getChild(0).getChild(0);
    assertEquals("Sanity check", "ns.main", mainTemplate.getTemplateName());
    final List<CallNode> callNodes = SharedTestUtils.getAllNodesOfType(
        mainTemplate, CallNode.class);
    assertEquals(2, callNodes.size());
    assertEquals("We're compiling a complete set; we can optimize based on usages.",
        ImmutableList.of(), callNodes.get(0).getEscapingDirectiveNames());
View Full Code Here

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

   * thread-safe manner, then please use {@link #execForAllTemplates}() in a thread-safe manner.
   */
  @Override public IjParamsInfo exec(SoyNode node) {

    Preconditions.checkArgument(node instanceof TemplateNode);
    TemplateNode nodeAsTemplate = (TemplateNode) node;

    // Build templateRegistry and initialize templateToFinishedInfoMap if necessary.
    if (templateRegistry == null) {
      SoyFileSetNode soyTree = nodeAsTemplate.getParent().getParent();
      templateRegistry = new TemplateRegistry(soyTree);
    }
    if (templateToFinishedInfoMap == null) {
      templateToFinishedInfoMap = Maps.newHashMap();
    }
View Full Code Here

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

    // If all the data keys being passed are listed using 'param' commands, then check that all
    // required params of the callee are included.
    if (! node.isPassingData()) {

      // Get the callee node (basic or delegate).
      TemplateNode callee;
      if (node instanceof CallBasicNode) {
        callee = templateRegistry.getBasicTemplate(((CallBasicNode) node).getCalleeName());
      } else {
        Set<DelegateTemplateDivision> divisions =
            templateRegistry.getDelTemplateDivisionsForAllVariants(
                ((CallDelegateNode) node).getDelCalleeName());
        if (divisions != null) {
          callee = Iterables.get(
              Iterables.getFirst(divisions, null).delPackageNameToDelTemplateMap.values(), 0);
        } else {
          callee = null;
        }
      }

      // Do the check if the callee node has SoyDoc.
      if (callee != null && callee.getSoyDocParams() != null) {
        // Get param keys passed by caller.
        Set<String> callerParamKeys = Sets.newHashSet();
        for (CallParamNode callerParam : node.getChildren()) {
          callerParamKeys.add(callerParam.getKey());
        }
        // Check param keys required by callee.
        List<String> missingParamKeys = Lists.newArrayListWithCapacity(2);
        for (SoyDocParam calleeParam : callee.getSoyDocParams()) {
          if (calleeParam.isRequired && ! callerParamKeys.contains(calleeParam.key)) {
            missingParamKeys.add(calleeParam.key);
          }
        }
        // Report errors.
        if (missingParamKeys.size() > 0) {
          String errorMsgEnd = (missingParamKeys.size() == 1) ?
              "param '" + missingParamKeys.get(0) + "'" : "params " + missingParamKeys;
          throw SoySyntaxExceptionUtils.createWithNode(
              String.format(
                  "Call to '%s' is missing required %s.",
                  callee.getTemplateNameForUserMsgs(), errorMsgEnd),
              node);
        }
      }
    }
  }
View Full Code Here

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

    return getUsedIjParamsForTemplate(templateInfo.getName());
  }


  @Override public ImmutableSortedSet<String> getUsedIjParamsForTemplate(String templateName) {
    TemplateNode template = templateRegistryForNoCaching.getBasicTemplate(templateName);
    if (template == null) {
      throw new SoyTofuException("Template '" + templateName + "' not found.");
    }
    IjParamsInfo ijParamsInfo = templateToIjParamsInfoMap.get(template);
    // TODO: Ideally we'd check that there are no external calls, but we find that in practice many
View Full Code Here

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

  private void renderMainHelper(
      TemplateRegistry templateRegistry, Appendable outputBuf, String templateName,
      @Nullable SoyMapData data, @Nullable SoyMapData ijData, Set<String> activeDelPackageNames,
      @Nullable SoyMsgBundle msgBundle, @Nullable SoyCssRenamingMap cssRenamingMap) {

    TemplateNode template = templateRegistry.getBasicTemplate(templateName);
    if (template == null) {
      throw new SoyTofuException("Attempting to render undefined template '" + templateName + "'.");
    }

    if (data == null) {
View Full Code Here

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

      int cloneId = tn.getNearestAncestor(SoyFileSetNode.class).getNodeIdGenerator().genId();

      // We need to use the unnamespaced name in the command text since we'll be inserting this
      // template into a file node that already has a namespace declaration.
      TemplateNode clone;
      boolean useAttrStyleForName = tn.getCommandText().contains("name=");
      if (tn instanceof TemplateBasicNode) {
        TemplateBasicNode tbn = (TemplateBasicNode) tn;

        String derivedPartialName = (tn.getPartialTemplateName() != null) ?
            derivedName.substring(soyFileHeaderInfo.namespace.length()) : null;

        clone = new TemplateBasicNode(
            cloneId, soyFileHeaderInfo, derivedName, derivedPartialName,
            useAttrStyleForName, tbn.isOverride(), tn.isPrivate(),
            tn.getAutoescapeMode(), tn.getContentKind(), tn.getSoyDoc(), tn.getSyntaxVersion());

        if (! (derivedName.equals(clone.getTemplateName()) &&
            Objects.equal(derivedPartialName, clone.getPartialTemplateName()))) {
          throw new AssertionError();
        }
      } else if (tn instanceof TemplateDelegateNode) {
        TemplateDelegateNode tdn = (TemplateDelegateNode) tn;
        clone = new TemplateDelegateNode(
            cloneId, soyFileHeaderInfo, derivedName, tdn.getDelTemplateVariant(),
            tdn.getDelPriority(), tn.getAutoescapeMode(), tn.getContentKind(), tn.getSoyDoc());

        if (! (derivedName.equals(((TemplateDelegateNode) clone).getDelTemplateName()))) {
          throw new AssertionError();
        }
      } else {
        throw new AssertionError("Unknown template node type: " + tn.getClass());
      }

      clone.setSourceLocation(tn.getSourceLocation());

      for (StandaloneNode child : tn.getChildren()) {
        clone.addChild(SoytreeUtils.cloneWithNewIds(child));
      }

      b.add(clone);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.