Search in sources :

Example 26 with ParseResult

use of com.google.template.soy.SoyFileSetParser.ParseResult in project closure-templates by google.

the class GenJsCodeVisitorTest method testOnlyOneRequireStatementPerNamespace.

@Test
public void testOnlyOneRequireStatementPerNamespace() {
    String testFileContent = "{namespace boo.foo}\n" + "\n" + "/** Test template. */\n" + "{template .goo autoescape=\"deprecated-noncontextual\"}\n" + "  {call boo.woo.aaa data=\"all\" /}\n" + "  {call boo.woo.aaa.bbb data=\"all\" /}\n" + "  {call boo.woo.bbb data=\"all\" /}\n" + "{/template}\n";
    ParseResult parseResult = SoyFileSetParserBuilder.forFileContents(testFileContent).parse();
    // ------ Using Closure, provide/require Soy namespaces ------
    String expectedJsFileContentStart = "// This file was automatically generated from no-path.\n" + "// Please don't edit this file by hand.\n" + "\n" + "/**\n" + " * @fileoverview Templates in namespace boo.foo.\n" + " * @public\n" + " */\n" + "\n" + "goog.provide('boo.foo');\n" + "\n" + "goog.require('boo.woo');\n" + "goog.require('boo.woo.aaa');\n" + "\n";
    jsSrcOptions.setShouldProvideRequireSoyNamespaces(true);
    List<String> jsFilesContents = genJsCodeVisitor.gen(parseResult.fileSet(), parseResult.registry(), ErrorReporter.exploding());
    assertThat(jsFilesContents.get(0)).startsWith(expectedJsFileContentStart);
}
Also used : ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult) Test(org.junit.Test)

Example 27 with ParseResult

use of com.google.template.soy.SoyFileSetParser.ParseResult in project closure-templates by google.

the class GenJsCodeVisitorTest method testXid.

@Test
public void testXid() {
    assertGeneratedJsCode("{xid('some-id')}\n", "output += xid('some-id');\n");
    String testFileContent = "{namespace boo.foo}\n" + "\n" + "/** Test template. */\n" + "{template .goo autoescape=\"deprecated-noncontextual\"}\n" + "  {xid('some-id')}\n" + "{/template}\n";
    ParseResult parseResult = SoyFileSetParserBuilder.forFileContents(testFileContent).parse();
    jsSrcOptions.setShouldProvideRequireSoyNamespaces(true);
    List<String> jsFilesContents = genJsCodeVisitor.gen(parseResult.fileSet(), parseResult.registry(), ErrorReporter.exploding());
    assertThat(jsFilesContents.get(0)).contains("goog.require('xid');");
}
Also used : ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult) Test(org.junit.Test)

Example 28 with ParseResult

use of com.google.template.soy.SoyFileSetParser.ParseResult in project closure-templates by google.

the class GenJsCodeVisitorTest method testPrivateTemplateHasPrivateJsDocAnnotationInGencode.

// -----------------------------------------------------------------------------------------------
// Header params.
@Test
public void testPrivateTemplateHasPrivateJsDocAnnotationInGencode() {
    String testFileContent = "{namespace boo.foo}\n" + "\n" + "/** Test template. */\n" + "{template .goo autoescape=\"deprecated-noncontextual\" visibility=\"private\"}\n" + "  Blah\n" + "{/template}\n";
    String expectedJsCode = "" + "/**\n" + " * @param {Object<string, *>=} opt_data\n" + " * @param {Object<string, *>=} opt_ijData\n" + " * @param {Object<string, *>=} opt_ijData_deprecated\n" + " * @return {string}\n" + " * @suppress {checkTypes|uselessCode}\n" + " * @private\n" + " */\n" + "boo.foo.goo = function(opt_data, opt_ijData, opt_ijData_deprecated) {\n" + "  opt_ijData = opt_ijData_deprecated || opt_ijData;\n" + "  return 'Blah';\n" + "};\n" + "if (goog.DEBUG) {\n" + "  boo.foo.goo.soyTemplateName = 'boo.foo.goo';\n" + "}\n";
    // Setup the GenJsCodeVisitor's state before the template is visited.
    genJsCodeVisitor.jsCodeBuilder = new JsCodeBuilder();
    ParseResult parseResult = SoyFileSetParserBuilder.forFileContents(testFileContent).parse();
    TemplateNode template = (TemplateNode) SharedTestUtils.getNode(parseResult.fileSet());
    genJsCodeVisitor.visitForTesting(template, parseResult.registry(), ErrorReporter.exploding());
    assertThat(genJsCodeVisitor.jsCodeBuilder.getCode()).isEqualTo(expectedJsCode);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult) Test(org.junit.Test)

Example 29 with ParseResult

use of com.google.template.soy.SoyFileSetParser.ParseResult in project closure-templates by google.

the class SoyFileSet method compileToIncrementalDomSrc.

/**
 * Compiles this Soy file set into iDOM source code files and returns these JS files as a list of
 * strings, one per file.
 *
 * @param jsSrcOptions The compilation options for the JS Src output target.
 * @return A list of strings where each string represents the JS source code that belongs in one
 *     JS file. The generated JS files correspond one-to-one to the original Soy source files.
 * @throws SoyCompilationException If compilation fails.
 */
public List<String> compileToIncrementalDomSrc(SoyIncrementalDomSrcOptions jsSrcOptions) {
    resetErrorReporter();
    ParseResult result = preprocessIncrementalDOMResults();
    List<String> generatedSrcs = new IncrementalDomSrcMain(apiCallScopeProvider, typeRegistry).genJsSrc(result.fileSet(), result.registry(), jsSrcOptions, errorReporter);
    throwIfErrorsPresent();
    reportWarnings();
    return generatedSrcs;
}
Also used : ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult) IncrementalDomSrcMain(com.google.template.soy.incrementaldomsrc.IncrementalDomSrcMain)

Example 30 with ParseResult

use of com.google.template.soy.SoyFileSetParser.ParseResult in project closure-templates by google.

the class SoyFileSet method compileToPySrcFiles.

/**
 * Compiles this Soy file set into Python source code files and writes these Python files to disk.
 *
 * @param outputPathFormat The format string defining how to build the output file path
 *     corresponding to an input file path.
 * @param inputFilePathPrefix The prefix prepended to all input file paths (can be empty string).
 * @param pySrcOptions The compilation options for the Python Src output target.
 * @throws SoyCompilationException If compilation fails.
 * @throws IOException If there is an error in opening/reading a message file or opening/writing
 *     an output JS file.
 */
void compileToPySrcFiles(String outputPathFormat, String inputFilePathPrefix, SoyPySrcOptions pySrcOptions) throws IOException {
    resetErrorReporter();
    requireStrictAutoescaping();
    ParseResult result = parse(SyntaxVersion.V2_0);
    throwIfErrorsPresent();
    new PySrcMain(apiCallScopeProvider).genPyFiles(result.fileSet(), pySrcOptions, outputPathFormat, inputFilePathPrefix, errorReporter);
    throwIfErrorsPresent();
    reportWarnings();
}
Also used : PySrcMain(com.google.template.soy.pysrc.internal.PySrcMain) ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult)

Aggregations

ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)38 Test (org.junit.Test)21 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)13 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)13 TemplateNode (com.google.template.soy.soytree.TemplateNode)10 TransitiveDepTemplatesInfo (com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor.TransitiveDepTemplatesInfo)8 SoyRecord (com.google.template.soy.data.SoyRecord)2 IncrementalDomSrcMain (com.google.template.soy.incrementaldomsrc.IncrementalDomSrcMain)2 JsSrcMain (com.google.template.soy.jssrc.internal.JsSrcMain)2 SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)2 PluginResolver (com.google.template.soy.soyparse.PluginResolver)2 SoyTypeRegistry (com.google.template.soy.types.SoyTypeRegistry)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Injector (com.google.inject.Injector)1 SoyFileSetParserBuilder (com.google.template.soy.SoyFileSetParserBuilder)1 SoyModule (com.google.template.soy.SoyModule)1 UniqueNameGenerator (com.google.template.soy.base.internal.UniqueNameGenerator)1 CopyState (com.google.template.soy.basetree.CopyState)1 SyntaxVersion (com.google.template.soy.basetree.SyntaxVersion)1