use of freemarker.template.Configuration in project freemarker by apache.
the class IncludeAndImportConfigurableLayersTest method test3LayerImportClashes.
@Test
public void test3LayerImportClashes() throws Exception {
Configuration cfg = getConfiguration();
cfg.addAutoImport("t1", "t1.ftl");
cfg.addAutoImport("t2", "t2.ftl");
cfg.addAutoImport("t3", "t3.ftl");
TemplateConfiguration tc = new TemplateConfiguration();
tc.addAutoImport("t2", "t2b.ftl");
cfg.setTemplateConfigurations(new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("main.ftl"), tc));
{
Template t = cfg.getTemplate("main.ftl");
StringWriter sw = new StringWriter();
Environment env = t.createProcessingEnvironment(null, sw);
env.addAutoImport("t3", "t3b.ftl");
env.process();
assertEquals("In main: t1;t2b;t3b;", sw.toString());
}
{
Template t = cfg.getTemplate("main2.ftl");
StringWriter sw = new StringWriter();
Environment env = t.createProcessingEnvironment(null, sw);
env.addAutoImport("t3", "t3b.ftl");
env.process();
assertEquals("In main2: t1;t2;t3b;", sw.toString());
}
{
Template t = cfg.getTemplate("main.ftl");
StringWriter sw = new StringWriter();
Environment env = t.createProcessingEnvironment(null, sw);
env.process();
assertEquals("In main: t1;t3;t2b;", sw.toString());
}
}
use of freemarker.template.Configuration in project freemarker by apache.
the class IncludeAndImportTest method lazyAutoImportSettings.
@Test
public void lazyAutoImportSettings() throws IOException, TemplateException {
Configuration cfg = getConfiguration();
cfg.addAutoImport("l1", "lib1.ftl");
cfg.addAutoImport("l2", "lib2.ftl");
cfg.addAutoImport("l3", "lib3.ftl");
String ftl = "<@l2.m/>, <@l1.m/>; ${history}";
String expectedEagerOutput = "In lib2, In lib1; L1L2L3";
String expecedLazyOutput = "In lib2, In lib1; L2L1";
assertOutput(ftl, expectedEagerOutput);
cfg.setLazyImports(true);
assertOutput(ftl, expecedLazyOutput);
cfg.setLazyImports(false);
assertOutput(ftl, expectedEagerOutput);
cfg.setLazyAutoImports(true);
assertOutput(ftl, expecedLazyOutput);
cfg.setLazyAutoImports(null);
assertOutput(ftl, expectedEagerOutput);
cfg.setLazyImports(true);
cfg.setLazyAutoImports(false);
assertOutput(ftl, expectedEagerOutput);
}
use of freemarker.template.Configuration in project freemarker by apache.
the class IncludeAndImportTest method createConfiguration.
@Override
protected Configuration createConfiguration() throws Exception {
Configuration cfg = super.createConfiguration();
cfg.setTemplateLoader(new StringTemplateLoader());
return cfg;
}
use of freemarker.template.Configuration in project freemarker by apache.
the class InterpretSettingInheritanceTest method tagSyntaxTest.
@Test
public void tagSyntaxTest() throws IOException, TemplateException {
Configuration cfg = getConfiguration();
cfg.setTagSyntax(Configuration.ANGLE_BRACKET_TAG_SYNTAX);
assertOutput(FTL_S_A_S, OUT_A_S_WHEN_SYNTAX_IS_A);
assertOutput(FTL_S_S_A, OUT_S_A_WHEN_SYNTAX_IS_A);
assertOutput(FTL_A_A_S, OUT_A_S_WHEN_SYNTAX_IS_A);
assertOutput(FTL_A_S_A, OUT_S_A_WHEN_SYNTAX_IS_A);
cfg.setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX);
assertOutput(FTL_S_A_S, OUT_A_S_WHEN_SYNTAX_IS_S);
assertOutput(FTL_S_S_A, OUT_S_A_WHEN_SYNTAX_IS_S);
assertOutput(FTL_A_A_S, OUT_A_S_WHEN_SYNTAX_IS_S);
assertOutput(FTL_A_S_A, OUT_S_A_WHEN_SYNTAX_IS_S);
cfg.setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX);
assertOutput(FTL_S_A_S, OUT_A_S_WHEN_SYNTAX_IS_A);
assertOutput(FTL_S_S_A, OUT_S_A_WHEN_SYNTAX_IS_S);
assertOutput(FTL_A_A_S, OUT_A_S_WHEN_SYNTAX_IS_A);
assertOutput(FTL_A_S_A, OUT_S_A_WHEN_SYNTAX_IS_S);
assertOutput("<@'[#ftl]x'?interpret />[#if true]y[/#if]", "x[#if true]y[/#if]");
}
use of freemarker.template.Configuration in project freemarker by apache.
the class InterpretSettingInheritanceTest method evalTest.
@Test
public void evalTest() throws IOException, TemplateException {
Configuration cfg = getConfiguration();
cfg.setTagSyntax(Configuration.ANGLE_BRACKET_TAG_SYNTAX);
assertOutput("<@'\"[#if true]s[/#if]<#if true>a</#if>\"?interpret'?eval />", OUT_S_A_WHEN_SYNTAX_IS_A);
assertOutput("[#ftl][@'\"[#if true]s[/#if]<#if true>a</#if>\"?interpret'?eval /]", OUT_S_A_WHEN_SYNTAX_IS_A);
cfg.setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX);
assertOutput("[@'\"[#if true]s[/#if]<#if true>a</#if>\"?interpret'?eval /]", OUT_S_A_WHEN_SYNTAX_IS_S);
assertOutput("<#ftl><@'\"[#if true]s[/#if]<#if true>a</#if>\"?interpret'?eval />", OUT_S_A_WHEN_SYNTAX_IS_S);
}
Aggregations