@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; }
@Override protected String transform(String originalContent) { List<Module> guiceModules = new ArrayList<Module>(); guiceModules.add(new SoyModule()); guiceModules.add(new XliffMsgPluginModule()); guiceModules.add(new PicoBridgeModule()); guiceModules.add(new OurFunctionsModule()); final Injector injector = Guice.createInjector(guiceModules); SoyFileSet.Builder sfsBuilder = injector.getInstance(SoyFileSet.Builder.class); SoyJsSrcOptions jsSrcOptions = new SoyJsSrcOptions(); jsSrcOptions.setShouldGenerateJsdoc(false); sfsBuilder.add(originalContent, location); SoyFileSet sfs = sfsBuilder.build(); final List<String> output = sfs.compileToJsSrc(jsSrcOptions, null); if (output.size() != 1) { throw new IllegalStateException(i18n.getText("wfshare.exception.soy.did.not.manage.to.compile.soy.template", output.size())); } return output.get(0); } }
@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)); } } } } }
@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 = 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 void compile(SoyFileSet.Builder sfsBuilder, Injector injector) throws IOException { sfsBuilder.setAllowExternalCalls(allowExternalCalls); SoyFileSet sfs = sfsBuilder.build(); SoyMsgBundleHandler msgBundleHandler = new SoyMsgBundleHandler(messagePlugin); // Main loop. for (int i = 0; i < inputMsgFiles.size(); i++) { // Get the input msg bundle. File inputMsgFilePath = inputMsgFiles.get(i); SoyMsgBundle origTransMsgBundle = msgBundleHandler.createFromFile(inputMsgFilePath); if (origTransMsgBundle.getLocaleString() == null) { throw new IOException("Error opening or parsing message file " + inputMsgFilePath); } // Do the pruning. SoyMsgBundle prunedTransSoyMsgBundle = sfs.pruneTranslatedMsgs(origTransMsgBundle); // Write out the pruned msg bundle. File outputMsgFilePath = outputMsgFiles.get(i); msgBundleHandler.writeToTranslatedMsgsFile( prunedTransSoyMsgBundle, new OutputFileOptions(), outputMsgFilePath); } } }
/** * 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()); }
private SoyTofu strainTofu(String completeModuleKey) throws SoyException { SoyFileSet.Builder builder = makeSoyFileSetBuilder(); for (URL file : templateSetFactory.get(completeModuleKey)) { builder.add(file); } try { return builder.build().compileToTofu(); } catch (SoySyntaxException e) { if (isDevMode()) { throw new QuieterSoySyntaxException(e.getMessage()); } else { throw e; } } }
@Override public String compile(final CharSequence content, final String filePath) { try { final SoyFileSet soyFiles = makeSoyFileSetBuilder() .setSupportContentSecurityPolicy(true) .add(content, filePath) .build(); final SoyJsSrcOptions options = newOptions(); List<String> output = soyFiles.compileToJsSrc(options, null); if (output.size() != 1) { throw new IllegalStateException("Did not manage to compile soy template at:" + filePath + ", size=" + output.size()); } return output.get(0); } catch (SoySyntaxException e) { if (DevMode.isDevMode()) { throw new QuieterSoySyntaxException(e.getMessage()); } throw e; } }
public DoccoBatch(Docco docco, File basePath, File outputPath, String[] excludes, String[] includes, URL horizonatlSoyTemplate, URL verticalSoyTemplate, DoccoFileMappingManager fileMappings, String title, String indexFilename, boolean skipNoDocco) { this.docco = docco; this.basePath = basePath; this.outputPath = outputPath; this.excludes = excludes; this.includes = includes; this.fileMappings = fileMappings; this.title = title; this.indexFilename = indexFilename; this.skipNoDocco = skipNoDocco; SoyFileSet soyFileSetH = new SoyFileSet.Builder().add(horizonatlSoyTemplate).build(); this.horizontalTofu = soyFileSetH.compileToJavaObj().forNamespace("atlassian.docco"); SoyFileSet soyFileSetV = new SoyFileSet.Builder().add(verticalSoyTemplate).build(); this.verticalTofu = soyFileSetV.compileToJavaObj().forNamespace("atlassian.docco"); }
public Docco(URL horizonatlSoyTemplate, URL verticalSoyTemplate, DoccoFileMappingManager fileMappings, boolean stripJavadoc, boolean includeDefaultResources, List<File> customResources, PegDownProcessor pegDown) { this.fileMappings = fileMappings; this.stripJavadoc = stripJavadoc; this.pegDown = pegDown; this.includeDefaultResources = includeDefaultResources; this.customResources = customResources; /*!####ToFu Anyone? Here we create the soyTofu compilers for both horizontal and vertical displays so we can reuse them when making multiple calls to render the html. */ SoyFileSet soyFileSetH = new SoyFileSet.Builder().add(horizonatlSoyTemplate).build(); this.horizontalTofu = soyFileSetH.compileToJavaObj().forNamespace("atlassian.docco"); SoyFileSet soyFileSetV = new SoyFileSet.Builder().add(verticalSoyTemplate).build(); this.verticalTofu = soyFileSetV.compileToJavaObj().forNamespace("atlassian.docco"); }
/** * Constructs a closure template engine with the given soy file paths. * * @param soyFilePaths one or more paths to .soy files relative to /templates in the resources folder. * @throws IllegalArgumentException if the input is null. */ public ClosureTemplateEngine(final String... soyFilePaths) { Preconditions.checkNotNull(soyFilePaths, "at least one path to soy file must be specified"); SoyFileSet.Builder sfsBuilder = SoyFileSet.builder(); for (final String soyFilePath : soyFilePaths) { sfsBuilder = sfsBuilder.add(ClosureTemplateEngine.class.getResource("/templates/" + soyFilePath)); } soyTofu = sfsBuilder.build().compileToTofu(); }
private SoyTofu strainTofu(String completeModuleKey) throws SoyException { SoyFileSet.Builder builder = makeSoyFileSetBuilder() .setSupportContentSecurityPolicy(true) .setSoyAstCache(soyAstCache.get()); templateSetFactory.get(completeModuleKey).forEach(builder::add); try { return builder.build().compileToTofu(); } catch (SoySyntaxException e) { if (isDevMode()) { throw new QuieterSoySyntaxException(e.getMessage()); } throw e; } }
@Override void compile(SoyFileSet.Builder sfsBuilder, Injector injector) throws IOException { sfsBuilder.setAllowExternalCalls(allowExternalCalls); SoyFileSet sfs = sfsBuilder.build(); OutputFileOptions options = new OutputFileOptions(); options.setSourceLocaleString(sourceLocaleString); if (targetLocaleString.length() > 0) { options.setTargetLocaleString(targetLocaleString); } sfs.extractAndWriteMsgs( new SoyMsgBundleHandler(messagePlugin), options, Files.asByteSink(outputFile)); } }
private SoyFileSet buildSoyFileSetFrom(final Collection<URL> urls) { final SoyFileSet.Builder builder = new SoyFileSet.Builder(); for (final URL url : urls) { builder.setAllowExternalCalls(true); builder.add(url); } addCompileTimeGlobalModel(builder); return builder.build(); }
@Override void compile(SoyFileSet.Builder sfsBuilder) throws IOException { Optional<ByteSink> srcJarSink = Optional.absent(); if (outputSrcJar != null) { srcJarSink = Optional.of(Files.asByteSink(outputSrcJar)); } compile(sfsBuilder.build(), Files.asByteSink(output), srcJarSink); }
@Override void compile(SoyFileSet.Builder sfsBuilder) throws IOException { SoyFileSet sfs = sfsBuilder.build(); sfs.compileToIncrementalDomSrcFiles(outputPathFormat, new SoyIncrementalDomSrcOptions()); } }
@Override void compile(SoyFileSet.Builder sfsBuilder) throws IOException { sfsBuilder.setAllowExternalCalls(allowExternalCalls); SoyFileSet sfs = sfsBuilder.build(); OutputFileOptions options = new OutputFileOptions(); options.setSourceLocaleString(sourceLocaleString); if (targetLocaleString.length() > 0) { options.setTargetLocaleString(targetLocaleString); } sfs.extractAndWriteMsgs( new SoyMsgBundleHandler(messagePlugin), options, Files.asByteSink(outputFile)); } }
private SoyFileSet createSoyFileSet(List<File> soyFiles) { SoyFileSet.Builder builder = this.injector.getInstance(SoyFileSet.Builder.class); for(File file : soyFiles) { builder.add(file); }; return builder.build(); }
@Override void compile(SoyFileSet.Builder sfsBuilder) throws IOException { Optional<ByteSink> srcJarSink = Optional.absent(); if (outputSrcJar != null) { srcJarSink = Optional.of(Files.asByteSink(outputSrcJar)); } compile(sfsBuilder.build(), Files.asByteSink(output), srcJarSink); }