Java Code Examples for org.beetl.core.Template#render()
The following examples show how to use
org.beetl.core.Template#render() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HtmlVarBinddingTagTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testLoopTag() throws Exception { //将默认搜索路径更改到tag目录下 gt.registerTag("tagloopbinding", VarBindingLoopSampleTag.class); //todo 会多出一个空行 Template t = gt.getTemplate("/tag/binding/tagloopbinding_template.html"); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/tag/binding/tagloopbinding_expected.html"), str); t = gt.getTemplate("/tag/binding/tagloopbinding_template.html"); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/tag/binding/tagloopbinding_expected.html"), str); }
Example 2
Source File: GeneralNumberTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testMul() throws Exception { Template t = gt.getTemplate("/exp/general_mul_template.html"); this.bind(t, "d1", d1, "d2", d2); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/general_mul_expected.html"), str); t = gt.getTemplate("/exp/general_mul_template.html"); this.bind(t, "d1", d1, "d2", d2); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/general_mul_expected.html"), str); }
Example 3
Source File: HtmlVarBinddingTagTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testBindingByAttribute() throws Exception { //测试通过特殊属性绑定 gt.registerTag("tagseqbinding", VarBindingSeqSampleTag.class); //todo 会多出一个空行 Template t = gt.getTemplate("/tag/binding/tagAttr_template.html"); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/tag/binding/tagAttr_expected.html"), str); t = gt.getTemplate("/tag/binding/tagAttr_template.html"); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/tag/binding/tagAttr_expected.html"), str); }
Example 4
Source File: IncludeTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testIncludeRel() throws Exception { User user = User.getTestUser(); Template t = gt.getTemplate("/tag/main_include_template.html"); this.bind(t, "user", user); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/tag/main_include_expected.html"), str); t = gt.getTemplate("/tag/main_include_template.html"); this.bind(t, "user", user); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/tag/main_include_expected.html"), str); }
Example 5
Source File: HtmlVarBinddingTagTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testTagSeq() throws Exception { //测试按照顺序绑定 gt.registerTag("tagseqbinding", VarBindingSeqSampleTag.class); //todo 会多出一个空行 Template t = gt.getTemplate("/tag/binding/tagseqbinding_template.html"); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/tag/binding/tagseqbinding_expected.html"), str); t = gt.getTemplate("/tag/binding/tagseqbinding_template.html"); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/tag/binding/tagseqbinding_expected.html"), str); }
Example 6
Source File: ConfigTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testSimple() throws Exception { Template t = gt.getTemplate("/lang/config_template.html"); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/lang/config_expected.html"), str); }
Example 7
Source File: ServiceImplBuilder.java From ApplicationPower with Apache License 2.0 | 5 votes |
@Override public String generateTemplate(TableInfo tableInfo) { String tableTemp = StringUtil.removePrefix(tableInfo.getName(), GeneratorProperties.tablePrefix()); String entityName = StringUtil.toCapitalizeCamelCase(tableTemp); String entitySimpleName = StringUtil.toCapitalizeCamelCase(entityName);//类名 String firstLowName = StringUtil.firstToLowerCase(entitySimpleName); String templateName = GeneratorProperties.getDbTemplatePath()+"/"+ConstVal.TPL_SERVICEIMPL; Template serviceImplTemplate = BeetlTemplateUtil.getByName(templateName); serviceImplTemplate.binding(GeneratorConstant.PRIMARY_KEY_TYPE, tableInfo.getPrimaryKeyType()); serviceImplTemplate.binding(GeneratorConstant.COMMON_VARIABLE);//作者 serviceImplTemplate.binding(GeneratorConstant.FIRST_LOWER_NAME, firstLowName); serviceImplTemplate.binding(GeneratorConstant.ENTITY_SIMPLE_NAME, entitySimpleName);//类名 serviceImplTemplate.binding(GeneratorProperties.getGenerateMethods());//过滤方法 return serviceImplTemplate.render(); }
Example 8
Source File: MapperBuilder.java From ApplicationPower with Apache License 2.0 | 5 votes |
@Override public String generateTemplate(TableInfo tableInfo) { String tableName = tableInfo.getName(); String tableTemp = StringUtil.removePrefix(tableName, GeneratorProperties.tablePrefix()); String entitySimpleName = StringUtil.toCapitalizeCamelCase(tableTemp);//类名 String firstLowName = StringUtil.firstToLowerCase(entitySimpleName); Map<String, Column> columnMap = tableInfo.getColumnsInfo(); String insertSql = generateInsertSql(columnMap, tableName); String batchInsertSql = generateBatchInsertSql(columnMap, tableName); String updateSql = generateConditionUpdateSql(tableInfo); String batchUpdateSql = generateBatchUpdateSql(tableInfo); String selectSql = generateSelectSql(tableInfo); String results = generateResultMap(columnMap); String primaryKey = getPrimaryKey(columnMap); String template = GeneratorProperties.getDbTemplatePath()+"/"+ConstVal.TPL_MAPPER; Template mapper = BeetlTemplateUtil.getByName(template); String idType = TypeConvert.mybatisType(tableInfo.getPrimaryKeyType()); mapper.binding(GeneratorConstant.PRIMARY_KEY_TYPE, idType); mapper.binding(GeneratorConstant.FIRST_LOWER_NAME, firstLowName); mapper.binding(GeneratorConstant.ENTITY_SIMPLE_NAME, entitySimpleName);//类名 mapper.binding(GeneratorConstant.BASE_PACKAGE, GeneratorProperties.basePackage());//基包名 mapper.binding(GeneratorConstant.INSERT_SQL, insertSql); mapper.binding(GeneratorConstant.BATCH_INSERT_SQL, batchInsertSql); mapper.binding(GeneratorConstant.UPDATE_SQL, updateSql); // mapper.binding(GeneratorConstant.BATCH_UPDATE_SQL,batchUpdateSql); mapper.binding(GeneratorConstant.SELECT_SQL, selectSql); mapper.binding(GeneratorConstant.RESULT_MAP, results); mapper.binding(GeneratorConstant.IS_RESULT_MAP, GeneratorProperties.getResultMap()); mapper.binding(GeneratorConstant.TABLE_NAME, tableName); mapper.binding(GeneratorConstant.PRIMARY_KEY, primaryKey); mapper.binding(GeneratorProperties.getGenerateMethods());//过滤方法 return mapper.render(); }
Example 9
Source File: AssignTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testVarBlock() throws Exception { Template t = gt.getTemplate("/exp/assign/block_template.html"); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/assign/block_expected.html"), str); t = gt.getTemplate("/exp/assign/block_template.html"); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/assign/block_expected.html"), str); }
Example 10
Source File: SwitchTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testDefault() throws Exception { Template t = gt.getTemplate("/control/swi/default_template.html"); this.bind(t, "dataList", data); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/control/swi/default_expected.html"), str); t = gt.getTemplate("/control/swi/default_template.html"); this.bind(t, "dataList", data); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/control/swi/default_expected.html"), str); }
Example 11
Source File: TernaryTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testId() throws Exception { Template t = gt.getTemplate("/exp/ternary_template.html"); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/ternary_expected.html"), str); t = gt.getTemplate("/exp/ternary_template.html"); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/ternary_expected.html"), str); }
Example 12
Source File: GeneralNumberTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testAdd() throws Exception { Template t = gt.getTemplate("/exp/general_add_template.html"); this.bind(t, "d1", d1, "d2", d2); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/general_add_expected.html"), str); t = gt.getTemplate("/exp/general_add_template.html"); this.bind(t, "d1", d1, "d2", d2); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/general_add_expected.html"), str); }
Example 13
Source File: AssignTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testAsign() throws Exception { Template t = gt.getTemplate("/exp/assign/assign_template.html"); t.binding("d", 100); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/assign/assign_expected.html"), str); t = gt.getTemplate("/exp/assign/assign_template.html"); t.binding("d", 100); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/assign/assign_expected.html"), str); }
Example 14
Source File: RegisterFunctionByFile.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] args) throws Exception { String root = System.getProperty("user.dir")+File.separator+"template"; FileResourceLoader resourceLoader = new FileResourceLoader(root,"utf-8"); Configuration cfg = Configuration.defaultConfiguration(); GroupTemplate gt = new GroupTemplate(resourceLoader, cfg); gt.registerFunctionPackage("t", new FunctionPackage()); Template t = gt.getTemplate("/s32/functionPackage.html"); String str = t.render(); System.out.println(str); }
Example 15
Source File: FunctionTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testToolKit() throws Exception { gt.registerFunction("str2Json", new Str2Json()); Template t = gt.getTemplate("/function/tojson_template.html"); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/function/tojson_expected.html"), str); t = gt.getTemplate("/function/tojson_template.html"); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/function/tojson_expected.html"), str); }
Example 16
Source File: FunctionTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testSafeOutput() throws Exception { gt.registerFunction("nullFunction", new NullFunction()); Template t = gt.getTemplate("/function/null_template.html"); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/function/null_expected.html"), str); t = gt.getTemplate("/function/null_template.html"); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/function/null_expected.html"), str); }
Example 17
Source File: HtmlGen.java From springboot-plus with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void make(Target target, Entity entity) { GroupTemplate gt = target.getGroupTemplate(); Template template = gt.getTemplate("/html/index.html"); template.binding("entity", entity); template.binding("target", target); String content = template.render(); target.flush(this, content); }
Example 18
Source File: HtmlTagTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testExpTag() throws Exception { Template t = gt.getTemplate("/tag/html6_template.html"); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/tag/html6_expected.html"), str); t = gt.getTemplate("/tag/html6_template.html"); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/tag/html6_expected.html"), str); }
Example 19
Source File: WhileTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testWhile() throws Exception { Template t = gt.getTemplate("/control/while/while_template.html"); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/control/while/while_expected.html"), str); t = gt.getTemplate("/control/while/while_template.html"); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/control/while/while_expected.html"), str); }
Example 20
Source File: MdGen.java From springboot-plus with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void make(Target target, Entity entity) { this.entity = entity; GroupTemplate gt = target.getGroupTemplate(); Template template = gt.getTemplate("/md/entity.md"); template.binding("entity", entity); template.binding("target", target); String content = template.render(); target.flush(this, content); }