Package com.google.template.soy.soytree

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


  }


  public void testHandleReference() {

    SoyFileSetNode soyTree = SharedTestUtils.parseSoyCode("{css $cssSelectedOption}");
    (new HandleCssCommandVisitor(CssHandlingScheme.REFERENCE)).exec(soyTree);
    SoyNode soyNode = SharedTestUtils.getNode(soyTree, 0);
    assertEquals("$cssSelectedOption", ((PrintNode) soyNode).getExprText());

    soyTree = SharedTestUtils.parseSoyCode("{css CSS_SELECTED_OPTION}");
View Full Code Here


  void assertSourceLocations(
      String asciiArtExpectedOutput, String soySourcePath, String soySourceCode)
      throws Exception {

    SoyFileSetNode soyTree =
        (new SoyFileSetParser(SoyFileSupplier.Factory.create(
            soySourceCode, SoyFileKind.SRC, soySourcePath)))
            .setDoRunInitialParsingPasses(false)
            .parse();
View Full Code Here

            "{/deltemplate}"));
  }


  public void testStrictModeAllowsNonAutoescapeCancellingDirectives() {
    SoyFileSetNode soyTree = SharedTestUtils.parseSoyFiles(join(
        "{template main autoescape=\"strict\"}\n",
          "<b>{$foo |customOtherDirective}</b>\n",
        "{/template}"));
    String rewrittenTemplate = rewrittenSource(soyTree);
    assertEquals(
View Full Code Here

        "\n{/template}\n\n" +
        "{template .jsTemplate autoescape=\"strict\" kind=\"js\"}\n" +
          "foo()" +
        "\n{/template}";
   
    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",
View Full Code Here

        "/** A delegate returning HTML. */\n" +
        "{deltemplate ns.delegate autoescape=\"strict\"}\n" +
          "Hello World" +
        "\n{/deltemplate}";
   
    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",
View Full Code Here

        "/** A delegate returning JS. */\n" +
        "{deltemplate ns.delegateText autoescape=\"strict\" kind=\"text\"}\n" +
          "Hello World" +
        "\n{/deltemplate}";
   
    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.",
View Full Code Here

  }

  private void assertContextualRewriting(String expectedOutput, String... inputs)
      throws SoyAutoescapeException {

    SoyFileSetNode soyTree = SharedTestUtils.parseSoyFiles(inputs);
    new CheckEscapingSanityVisitor().exec(soyTree);

    String source = rewrittenSource(soyTree);
    assertEquals(expectedOutput, source.trim());

    // Make sure that the transformation is idempotent.
    if (!source.contains("__C")) {  // Skip if there are extern extra templates.
      assertEquals(expectedOutput, rewrittenSource(soyTree).trim());
    }

    // And idempotent from a normalized input if the templates are not autoescape="contextual".
    String input = join(inputs);
    String inputWithoutAutoescape = input
        .replaceAll("\\s+autoescape\\s*=\\s*\"(contextual|strict)\"", "")
        .replaceAll("\\s+kind\\s*=\\s*\"([a-z]*)\"", "");
    SoyFileSetNode soyTree2 = SharedTestUtils.parseSoyFiles(inputWithoutAutoescape);
    String original = soyTree2.getChild(0).toSourceString();
    assertEquals(original, rewrittenSource(soyTree2));
  }
View Full Code Here

    List<SoyFileSupplier> soyFileSuppliers = Lists.newArrayList();
    for (int i = 0; i < inputs.length; ++i) {
      soyFileSuppliers.add(SoyFileSupplier.Factory.create(
          inputs[i], SoyFileKind.SRC, inputs.length == 1 ? "no-path" : "no-path-" + i));
    }
    SoyFileSetNode soyTree = new SoyFileSetParser(soyFileSuppliers)
        .setDoRunInitialParsingPasses(true)
        .setDoRunCheckingPasses(true)
        .setDoEnforceSyntaxVersionV2(false)
        .parse();

    try {
      new CheckEscapingSanityVisitor().exec(soyTree);
      rewrittenSource(soyTree);
    } catch (SoyAutoescapeException ex) {
      if (msg != null && !msg.equals(ex.getMessage())) {
        throw (ComparisonFailure) new ComparisonFailure("", msg, ex.getMessage()).initCause(ex);
      }
      return;
    }
    fail("Expected failure but was " + soyTree.getChild(0).toSourceString());
  }
View Full Code Here

    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

   */
  public Pair<SoyFileSetNode, List<SoyFileSupplier.Version>> parseWithVersions()
      throws SoySyntaxException {

    IdGenerator nodeIdGen = new IncrementingIdGenerator();
    SoyFileSetNode soyTree = new SoyFileSetNode(nodeIdGen.genId(), nodeIdGen);
    ImmutableList.Builder<SoyFileSupplier.Version> versions = ImmutableList.builder();

    for (SoyFileSupplier soyFileSupplier : soyFileSuppliers) {
      Pair<SoyFileNode, SoyFileSupplier.Version> fileAndVersion =
          parseSoyFileHelper(soyFileSupplier, nodeIdGen);
      soyTree.addChild(fileAndVersion.first);
      versions.add(fileAndVersion.second);
    }

    // Run passes that are considered part of initial parsing.
    if (doRunInitialParsingPasses) {
View Full Code Here

TOP

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

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.