@Test public void testCompileSoyToBinaryWithCompileTimeModelAndSoyMsgBundle() throws Exception { final String compiledJs = " " "\n" + "\n" + "\n" + "if (typeof soy == 'undefined') { var soy = {}; }\n" + "if (typeof soy.example == 'undefined') { soy.example = {}; }\n" + "\n" + "\n" + "soy.example.test = function(opt_data, opt_ignored) {\n" + " return soydata.VERY_UNSAFE.ordainSanitizedHtml('notTranslated');\n" + "};\n" + "if (goog.DEBUG) {\n" + " soy.example.test.soyTemplateName = 'soy.example.test';\n" + "}\n"; final SoyMsgPart soyMsgPart = SoyMsgRawTextPart.of("translated"); final SoyMsg soyMsg = new SoyMsg(1, 1, "pl_PL", "test1", "desc", false, null, null, true, Lists.newArrayList(soyMsgPart)); final SoyMsgBundle soyMsgBundle = new SoyMsgBundleImpl("pl_PL", Lists.<SoyMsg>newArrayList(soyMsg)); when(compileTimeGlobalModelResolver.resolveData()).thenReturn(Optional.<SoyMapData>absent()); final URL template1 = getClass().getClassLoader().getResource("templates/template3.soy"); final Collection<String> tofu = defaultTofuCompiler.compileToJsSrc(Lists.newArrayList(template1), soyMsgBundle); Assert.assertFalse("tofu compiled collection should not be empty", tofu.isEmpty()); Assert.assertEquals("tofu compiled collection.size should be 1", 1, tofu.size()); Assert.assertEquals("compiledJs should be equal", compiledJs, tofu.iterator().next()); }
@Override public final Optional<String> compileToJsSrc(@Nullable final URL url, @Nullable final SoyMsgBundle soyMsgBundle) { if (url == null) { return Optional.absent(); } final Collection<String> compiledTemplates = compileToJsSrc(Lists.newArrayList(url), soyMsgBundle); if (compiledTemplates.isEmpty()) { return Optional.absent(); } return Optional.fromNullable(compiledTemplates.iterator().next()); }
DefaultTofuCompiler implements TofuCompiler { @Override public final Optional<String> compileToJsSrc(@Nullable final URL url, @Nullable final SoyMsgBundle soyMsgBundle) { if (url == null) { return Optional.absent(); } final Collection<String> compiledTemplates = compileToJsSrc(Lists.newArrayList(url), soyMsgBundle); if (compiledTemplates.isEmpty()) { return Optional.absent(); } return Optional.fromNullable(compiledTemplates.iterator().next()); } }
DefaultTofuCompiler implements TofuCompiler { @Override public final Optional<String> compileToJsSrc(@Nullable final URL url, @Nullable final SoyMsgBundle soyMsgBundle) { if (url == null) { return Optional.absent(); } final Collection<String> compiledTemplates = compileToJsSrc(Lists.newArrayList(url), soyMsgBundle); if (compiledTemplates.isEmpty()) { return Optional.absent(); } return Optional.fromNullable(compiledTemplates.iterator().next()); }  }
DefaultTofuCompiler implements TofuCompiler { @Override public final Optional<String> compileToJsSrc(@Nullable final URL url, @Nullable final SoyMsgBundle soyMsgBundle) { if (url == null) { return Optional.absent(); } final Collection<String> compiledTemplates = compileToJsSrc(Lists.newArrayList(url), soyMsgBundle); if (compiledTemplates.isEmpty()) { return Optional.absent(); } return Optional.fromNullable(compiledTemplates.iterator().next()); }  @Override SoyTofu compile(@Nullable final Collection<URL> urls); @Override final Optional<String> compileToJsSrc(@Nullable final URL url, @Nullable final SoyMsgBundle soyMsgBundle); @Override Collection<String> compileToJsSrc(Collection<URL> templates, @Nullable SoyMsgBundle soyMsgBundle); void setHotReloadMode(final boolean hotReloadMode); void setCompileTimeGlobalModelResolver(final CompileTimeGlobalModelResolver compileTimeGlobalModelResolver); void setSoyJsSrcOptions(final SoyJsSrcOptions soyJsSrcOptions); boolean isHotReloadMode(); boolean isHotReloadModeOff(); SoyJsSrcOptions getSoyJsSrcOptions(); SoyTofuOptions getSoyTofuOptions(); void setSoyTofuOptions(SoyTofuOptions soyTofuOptions); }
DefaultTofuCompiler implements TofuCompiler { @Override public final Optional<String> compileToJsSrc(@Nullable final URL url, @Nullable final SoyMsgBundle soyMsgBundle) { if (url == null) { return Optional.absent(); } final Collection<String> compiledTemplates = compileToJsSrc(Lists.newArrayList(url), soyMsgBundle); if (compiledTemplates.isEmpty()) { return Optional.absent(); } return Optional.fromNullable(compiledTemplates.iterator().next()); }  @Override SoyTofu compile(@Nullable final Collection<URL> urls); @Override final Optional<String> compileToJsSrc(@Nullable final URL url, @Nullable final SoyMsgBundle soyMsgBundle); @Override Collection<String> compileToJsSrc(Collection<URL> templates, @Nullable SoyMsgBundle soyMsgBundle); void setHotReloadMode(final boolean hotReloadMode); void setCompileTimeGlobalModelResolver(final CompileTimeGlobalModelResolver compileTimeGlobalModelResolver); void setSoyJsSrcOptions(final SoyJsSrcOptions soyJsSrcOptions); boolean isHotReloadMode(); boolean isHotReloadModeOff(); SoyJsSrcOptions getSoyJsSrcOptions(); SoyTofuOptions getSoyTofuOptions(); void setSoyTofuOptions(SoyTofuOptions soyTofuOptions);  }