/** * Prints the generated HTML to stdout. * * @param args Not used. */ public static void main(String[] args) { // Compile the template. SoyFileSet sfs = SoyFileSet.builder().add(Resources.getResource("simple.soy")).build(); SoyTofu tofu = sfs.compileToTofu(); // Example 1. writeExampleHeader(); System.out.println(tofu.newRenderer("soy.examples.simple.helloWorld").render()); // Create a namespaced tofu object to make calls more concise. SoyTofu simpleTofu = tofu.forNamespace("soy.examples.simple"); // Example 2. writeExampleHeader(); System.out.println( simpleTofu.newRenderer(".helloName").setData(ImmutableMap.of("name", "Ana")).render()); // Example 3. writeExampleHeader(); System.out.println( simpleTofu .newRenderer(".helloNames") .setData(ImmutableMap.of("names", ImmutableList.of("Bob", "Cid", "Dee"))) .render()); }
@Override public SoyTofu compile(@Nullable final Collection<URL> urls) throws IOException { Preconditions.checkNotNull("compileTimeGlobalModelResolver", compileTimeGlobalModelResolver); if (urls == null || urls.isEmpty()) { throw new IOException("Unable to compile, no urls found"); } logger.debug("SoyTofu compilation of templates:" + urls.size()); final long time1 = System.currentTimeMillis(); final SoyFileSet.Builder sfsBuilder = new SoyFileSet.Builder(); for (final URL url : urls) { sfsBuilder.add(url); } addCompileTimeGlobalModel(sfsBuilder); final SoyFileSet soyFileSet = sfsBuilder.build(); final SoyTofuOptions soyTofuOptions = createSoyTofuOptions(); final SoyTofu soyTofu = soyFileSet.compileToTofu(soyTofuOptions); final long time2 = System.currentTimeMillis(); logger.debug("SoyTofu compilation complete." + (time2 - time1) + " ms"); return soyTofu; }
injector .getInstance(SoyFileSet.Builder.class) .setWarningSink(err) .setConformanceConfig(conformanceConfig) .setValidatedLoggingConfig(parseLoggingConfig()) .setExperimentalFeatures(experimentalFeatures); sfsBuilder.addProtoDescriptorsFromFile(protoFileDescriptor); } catch (IOException ioe) { throw new CommandLineError( sfsBuilder.setCompileTimeGlobals(globalsFile); sfsBuilder.disableOptimizer();
SoyFileSet sfs = sfsBuilder .add(Resources.getResource("simple.soy")) .add(Resources.getResource("features.soy")) .setCompileTimeGlobals(Resources.getResource("FeaturesUsage_globals.txt")) .build(); SoyTofu tofu = sfs.compileToTofu().forNamespace("soy.examples.features");
SoyFileSet sfs = sfsBuilder .add(Resources.getResource("simple.soy")) .add(Resources.getResource("features.soy")) .setCompileTimeGlobals(Resources.getResource("FeaturesUsage_globals.txt")) .build(); SoyTofu tofu = sfs.compileToTofu().forNamespace("soy.examples.features");
.add(Resources.getResource("simple.soy")) .add(Resources.getResource("features.soy")) .setCompileTimeGlobals(Resources.getResource("FeaturesUsage_globals.txt")) .build(); SoyTofu tofu = sfs.compileToTofu().forNamespace("soy.examples.features");
.addSourceFunctions(sourceFunctions) .setWarningSink(err) .setConformanceConfig(conformanceConfig) .setValidatedLoggingConfig(parseLoggingConfig()) .setExperimentalFeatures(experimentalFeatures); sfsBuilder.addProtoDescriptorsFromFile(protoFileDescriptor); } catch (IOException ioe) { throw new CommandLineError( sfsBuilder.setCompileTimeGlobals(globalsFile); sfsBuilder.disableOptimizer();
final String searchPath = config.getSearchPath(); SoyFileSet.Builder builder = new SoyFileSet.Builder(); builder.setCompileTimeGlobals(config.getCompileTimeGlobalsProvider().getGlobals()); hasSetGlobals = true; List<URL> sharedSoyFiles = fileSetResolver.filesFromNamespace(searchPath, ns, suffix); for (URL url : sharedSoyFiles) { builder.add(url); if (sharedGlobalFiles.size() > 0) { try { builder.setCompileTimeGlobals(sharedGlobalFiles.get(0)); } catch (IOException e) { throw new RuntimeException("Error sourcing globals file.", e); builder.add(url); if (globalFiles.size() > 0) { try { builder.setCompileTimeGlobals(globalFiles.get(0)); } catch (IOException e) { throw new RuntimeException("Error sourcing globals file.", e); return builder.build();
MainClassUtils.addSoyFilesToBuilder( sfsBuilder, inputPrefix, srcs, arguments, ImmutableList.<String>of(), exitWithErrorFn); sfsBuilder.setAllowExternalCalls(allowExternalCalls); SoyFileSet sfs = sfsBuilder.build();
MainClassUtils.addSoyFilesToBuilder(sfsBuilder, inputPrefix, srcs, arguments, deps, exitWithErrorFn); sfsBuilder.setAllowExternalCalls(allowExternalCalls); String cssHandlingSchemeUc = cssHandlingScheme.toUpperCase(); sfsBuilder.setCssHandlingScheme( cssHandlingSchemeUc.equals("GOOG") ? CssHandlingScheme.BACKEND_SPECIFIC : CssHandlingScheme.valueOf(cssHandlingSchemeUc)); if (compileTimeGlobalsFile.length() > 0) { sfsBuilder.setCompileTimeGlobals(new File(compileTimeGlobalsFile)); SoyFileSet sfs = sfsBuilder.build();
sfsBuilder, inputPrefix, ImmutableSet.copyOf(srcs), ImmutableSet.copyOf(arguments), ImmutableSet.copyOf(deps), exitWithErrorFn); sfsBuilder.setAllowExternalCalls(allowExternalCalls); SoyFileSet sfs = sfsBuilder.build();
MainClassUtils.addSoyFilesToBuilder(sfsBuilder, inputPrefix, srcs, arguments, deps, exitWithErrorFn); sfsBuilder.setAllowExternalCalls(allowExternalCalls); sfsBuilder.setCssHandlingScheme(CssHandlingScheme.valueOf(cssHandlingScheme.toUpperCase())); if (compileTimeGlobalsFile.length() > 0) { sfsBuilder.setCompileTimeGlobals(new File(compileTimeGlobalsFile)); SoyFileSet sfs = sfsBuilder.build();
exitWithError("Declared syntax version must be 2.0 or greater."); sfsBuilder.setDeclaredSyntaxVersionName(syntaxVersion); sfsBuilder.setAllowExternalCalls(false); sfsBuilder.setStrictAutoescapingRequired(true); SoyFileSet sfs = sfsBuilder.build();
@Override void compile(SoyFileSet.Builder sfsBuilder) throws IOException { if (!syntaxVersion.isEmpty()) { sfsBuilder.setDeclaredSyntaxVersionName(syntaxVersion); sfsBuilder.setAllowExternalCalls(allowExternalCalls); SoyFileSet sfs = sfsBuilder.build();
/** * Prints the generated HTML to stdout. * * @param args Not used. */ public static void main(String[] args) { // Compile the template. SoyFileSet sfs = SoyFileSet.builder().add(Resources.getResource("simple.soy")).build(); SoyTofu tofu = sfs.compileToTofu(); // Example 1. writeExampleHeader(); System.out.println(tofu.newRenderer("soy.examples.simple.helloWorld").render()); // Create a namespaced tofu object to make calls more concise. SoyTofu simpleTofu = tofu.forNamespace("soy.examples.simple"); // Example 2. writeExampleHeader(); System.out.println( simpleTofu.newRenderer(".helloName").setData(new SoyMapData("name", "Ana")).render()); // Example 3. writeExampleHeader(); System.out.println( simpleTofu .newRenderer(".helloNames") .setData(new SoyMapData("names", new SoyListData("Bob", "Cid", "Dee"))) .render()); }
@Override void compile(SoyFileSet.Builder sfsBuilder) throws IOException { sfsBuilder.setAllowExternalCalls(allowExternalCalls); SoyFileSet sfs = sfsBuilder.build(); // Create SoyJsSrcOptions. SoyJsSrcOptions jsSrcOptions = new SoyJsSrcOptions(); jsSrcOptions.setShouldAllowDeprecatedSyntax(shouldAllowDeprecatedSyntax); jsSrcOptions.setShouldGenerateGoogMsgDefs(shouldGenerateGoogMsgDefs); jsSrcOptions.setGoogMsgsAreExternal(googMsgsAreExternal); jsSrcOptions.setBidiGlobalDir(bidiGlobalDir); jsSrcOptions.setUseGoogIsRtlForBidiGlobalDir(useGoogIsRtlForBidiGlobalDir); // Compile. boolean generateLocalizedJs = !locales.isEmpty(); if (generateLocalizedJs) { sfs.compileToJsSrcFiles( outputPathFormat, jsSrcOptions, locales, messagePlugin, messageFilePathFormat); } else { sfs.compileToJsSrcFiles(outputPathFormat, jsSrcOptions, locales, null, null); } } }
@Override void compile(SoyFileSet.Builder sfsBuilder) throws IOException { sfsBuilder.setAllowExternalCalls(allowExternalCalls); SoyFileSet sfs = sfsBuilder.build(); ImmutableMap<String, String> parseInfo = sfs.generateParseInfo(javaPackage, javaClassNameSource); if (outputSrcJar == null) { for (Map.Entry<String, String> entry : parseInfo.entrySet()) { File outputFile = new File(outputDirectory, entry.getKey()); BaseUtils.ensureDirsExistInPath(outputFile.getPath()); Files.asCharSink(outputFile, UTF_8).write(entry.getValue()); } } else { String resourcePath = javaPackage.replace('.', '/') + "/"; try (SoyJarFileWriter writer = new SoyJarFileWriter(new FileOutputStream(outputSrcJar))) { for (Map.Entry<String, String> entry : parseInfo.entrySet()) { writer.writeEntry( resourcePath + entry.getKey(), CharSource.wrap(entry.getValue()).asByteSource(UTF_8)); } } } } }
/** * Prints the generated HTML to stdout. * @param args Not used. */ public static void main(String[] args) { // Compile the template. SoyFileSet sfs = (new SoyFileSet.Builder()).add(Resources.getResource("simple.soy")).build(); SoyTofu tofu = sfs.compileToTofu(); // Example 1. writeExampleHeader(); System.out.println(tofu.newRenderer("soy.examples.simple.helloWorld").render()); // Create a namespaced tofu object to make calls more concise. SoyTofu simpleTofu = tofu.forNamespace("soy.examples.simple"); // Example 2. writeExampleHeader(); System.out.println(simpleTofu.newRenderer(".helloName") .setData(new SoyMapData("name", "Ana")).render()); // Example 3. writeExampleHeader(); System.out.println(simpleTofu.newRenderer(".helloNames") .setData(new SoyMapData("names", new SoyListData("Bob", "Cid", "Dee"))) .render()); }
@Override void compile(SoyFileSet.Builder sfsBuilder) throws IOException { // Disallow external call entirely in Python. sfsBuilder.setAllowExternalCalls(false); // Require strict templates in Python. sfsBuilder.setStrictAutoescapingRequired(true); SoyFileSet sfs = sfsBuilder.build(); // Load the manifest if available. ImmutableMap<String, String> manifest = loadNamespaceManifest(namespaceManifestPaths); if (!manifest.isEmpty() && outputNamespaceManifest == null) { exitWithError("Namespace manifests provided without outputting a new manifest."); } // Create SoyPySrcOptions. SoyPySrcOptions pySrcOptions = new SoyPySrcOptions( runtimePath, environmentModulePath, bidiIsRtlFn, translationClass, manifest, outputNamespaceManifest); // Compile. sfs.compileToPySrcFiles(outputPathFormat, pySrcOptions); }
@Override void compile(SoyFileSet.Builder sfsBuilder) throws IOException { sfsBuilder.setAllowExternalCalls(allowExternalCalls); SoyFileSet sfs = sfsBuilder.build(); ImmutableMap<String, String> parseInfo = sfs.generateParseInfo(javaPackage, javaClassNameSource); if (outputSrcJar == null) { for (Map.Entry<String, String> entry : parseInfo.entrySet()) { File outputFile = new File(outputDirectory, entry.getKey()); BaseUtils.ensureDirsExistInPath(outputFile.getPath()); Files.asCharSink(outputFile, UTF_8).write(entry.getValue()); } } else { String resourcePath = javaPackage.replace('.', '/') + "/"; try (SoyJarFileWriter writer = new SoyJarFileWriter(new FileOutputStream(outputSrcJar))) { for (Map.Entry<String, String> entry : parseInfo.entrySet()) { writer.writeEntry( resourcePath + entry.getKey(), CharSource.wrap(entry.getValue()).asByteSource(UTF_8)); } } } } }