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);
}
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');");
}
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);
}
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;
}
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();
}
Aggregations