@Override public Collection<String> compileToJsSrc(Collection<URL> templates, @Nullable SoyMsgBundle soyMsgBundle) { Preconditions.checkNotNull("soyJsSrcOptions", soyJsSrcOptions); logger.debug("SoyJavaScript compilation of template:" + templates); final long time1 = System.currentTimeMillis(); final SoyFileSet soyFileSet = buildSoyFileSetFrom(templates); final List<String> ret = soyFileSet.compileToJsSrc(soyJsSrcOptions, soyMsgBundle); final long time2 = System.currentTimeMillis(); logger.debug("SoyJavaScript compilation complete." + (time2 - time1) + " ms"); return ret; }
public List<String> renderJs(List<File> files) { SoyFileSet sfs = createSoyFileSet(files); return sfs.compileToJsSrc(jsSrcOptions, null); } }
public String load(Locale locale) { SoyJsSrcOptions opts = new SoyJsSrcOptions(); // FUTURE: Allow configuration of opts via config? List<String> js = generateSoyFileSet(JS_SOY_EXTENSION).compileToJsSrc(opts, msgBundleCache.getUnchecked(locale)); StringBuilder sb = new StringBuilder(); for (String s : js) { sb.append(s).append("\r\n"); } return sb.toString(); }
@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 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; } }