Java Code Examples for org.beetl.core.Template#binding()
The following examples show how to use
org.beetl.core.Template#binding() .
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: SetTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testArrayMap() throws Exception { Template t = gt.getTemplate("/exp/set_template.html"); int[] c = new int[]{1,2}; int[][] d = new int[][]{{1,2},{3,4}}; t.binding("c", c); t.binding("d", d); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/set_expected.html"), str); t = gt.getTemplate("/exp/set_template.html"); t.binding("c", c); t.binding("d", d); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/set_expected.html"), str); }
Example 2
Source File: DaoBuilder.java From ApplicationPower with Apache License 2.0 | 6 votes |
@Override public String generateTemplate(TableInfo table) { String tableTemp = StringUtil.removePrefix(table.getName(), GeneratorProperties.tablePrefix()); String entityName = StringUtil.toCapitalizeCamelCase(tableTemp); String entitySimpleName = StringUtil.toCapitalizeCamelCase(entityName);//类名 String templateName = GeneratorProperties.getDbTemplatePath()+"/"+ConstVal.TPL_DAO; Template daoTemplate = BeetlTemplateUtil.getByName(templateName); daoTemplate.binding(GeneratorConstant.PRIMARY_KEY_TYPE, table.getPrimaryKeyType()); daoTemplate.binding(GeneratorConstant.COMMON_VARIABLE); daoTemplate.binding(GeneratorConstant.ENTITY_SIMPLE_NAME, entitySimpleName);//类名 daoTemplate.binding(GeneratorProperties.getGenerateMethods());//过滤方法 daoTemplate.binding(GeneratorConstant.IS_MULTIPLE_DATA_SOURCE, GeneratorProperties.isMultipleDataSource()); Set<String> dataSource = GeneratorProperties.getMultipleDataSource(); int i = 0; for (String str : dataSource) { if (i == 0) { daoTemplate.binding("defaultDataSource", str.toUpperCase()); break; } } return daoTemplate.render(); }
Example 3
Source File: BeetlTemplateUtil.java From ApplicationPower with Apache License 2.0 | 6 votes |
/** * @param path * @param params * @return */ public static Map<String, String> getTemplatesRendered(String path, Map<String, Object> params) { Map<String, String> templateMap = new HashMap<>(); File[] files = FileUtil.getResourceFolderFiles(path); GroupTemplate gt = getGroupTemplate(path); for (File f : files) { if (f.isFile()) { String fileName = f.getName(); Template tp = gt.getTemplate(fileName); if (null != params) { tp.binding(params); } templateMap.put(fileName, tp.render()); } } return templateMap; }
Example 4
Source File: HTMLTagSupportWrapper.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void callHtmlTag(String path) { Template t = null; t = gt.getHtmlFunctionOrTagTemplate(path, this.ctx.getResourceId()); t.binding(ctx.globalVar); t.dynamic(ctx.objectKeys); if (args.length == 2) { Map<String, Object> map = (Map<String, Object>) args[1]; for (Entry<String, Object> entry : map.entrySet()) { t.binding(entry.getKey(), entry.getValue()); } } BodyContent bodyContent = super.getBodyContent(); t.binding("tagBody", bodyContent); t.renderTo(ctx.byteWriter); }
Example 5
Source File: RpcDocBuilderTemplate.java From smart-doc with Apache License 2.0 | 6 votes |
/** * Merge all api doc into one document * * @param apiDocList list data of Api doc * @param config api config * @param javaProjectBuilder JavaProjectBuilder * @param template template * @param outPutFileName output file */ public void buildAllInOne(List<RpcApiDoc> apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder, String template, String outPutFileName) { String outPath = config.getOutPath(); String strTime = DateTimeUtil.long2Str(now, DateTimeUtil.DATE_FORMAT_SECOND); String rpcConfig = config.getRpcConsumerConfig(); String rpcConfigConfigContent = null; if (Objects.nonNull(rpcConfig)) { rpcConfigConfigContent = FileUtil.getFileContent(rpcConfig); } FileUtil.mkdirs(outPath); List<ApiErrorCode> errorCodeList = errorCodeDictToList(config); Template tpl = BeetlTemplateUtil.getByName(template); tpl.binding(TemplateVariable.API_DOC_LIST.getVariable(), apiDocList); tpl.binding(TemplateVariable.ERROR_CODE_LIST.getVariable(), errorCodeList); tpl.binding(TemplateVariable.VERSION_LIST.getVariable(), config.getRevisionLogs()); tpl.binding(TemplateVariable.DEPENDENCY_LIST.getVariable(), config.getRpcApiDependencies()); tpl.binding(TemplateVariable.VERSION.getVariable(), now); tpl.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime); tpl.binding(TemplateVariable.PROJECT_NAME.getVariable(), config.getProjectName()); tpl.binding(TemplateVariable.RPC_CONSUMER_CONFIG.getVariable(), rpcConfigConfigContent); setDirectoryLanguageVariable(config, tpl); FileUtil.nioWriteFile(tpl.render(), outPath + FILE_SEPARATOR + outPutFileName); }
Example 6
Source File: RpcHtmlBuilder.java From smart-doc with Apache License 2.0 | 6 votes |
/** * build dictionary * * @param apiDocDictList dictionary list * @param outPath */ private static void buildDependency(ApiConfig config) { List<RpcApiDependency> apiDependencies = config.getRpcApiDependencies(); if (CollectionUtil.isNotEmpty(config.getRpcApiDependencies())) { String rpcConfig = config.getRpcConsumerConfig(); String rpcConfigConfigContent = null; if (Objects.nonNull(rpcConfig)) { rpcConfigConfigContent = FileUtil.getFileContent(rpcConfig); } Template template = BeetlTemplateUtil.getByName(RPC_DEPENDENCY_MD_TPL); template.binding(TemplateVariable.RPC_CONSUMER_CONFIG.getVariable(), rpcConfigConfigContent); template.binding(TemplateVariable.DEPENDENCY_LIST.getVariable(), apiDependencies); String dictHtml = MarkDownUtil.toHtml(template.render()); Template dictTpl = BeetlTemplateUtil.getByName(HTML_API_DOC_TPL); dictTpl.binding(TemplateVariable.VERSION.getVariable(), now); dictTpl.binding(TemplateVariable.TITLE.getVariable(), DICT_EN_TITLE); dictTpl.binding(TemplateVariable.HTML.getVariable(), dictHtml); dictTpl.binding(TemplateVariable.CREATE_TIME.getVariable(), DateTimeUtil.long2Str(now, DateTimeUtil.DATE_FORMAT_SECOND)); FileUtil.nioWriteFile(dictTpl.render(), config.getOutPath() + FILE_SEPARATOR + "dependency.html"); } }
Example 7
Source File: ControllerTestBuilder.java From ApplicationPower with Apache License 2.0 | 5 votes |
@Override public String generateTemplate(TableInfo tableInfo) { Map<String, Column> columnMap = tableInfo.getColumnsInfo(); //实体名需要移除表前缀 String tableTemp = StringUtil.removePrefix(tableInfo.getName(), GeneratorProperties.tablePrefix()); String entitySimpleName = StringUtil.toCapitalizeCamelCase(tableTemp);//类名 String firstLowName = StringUtil.firstToLowerCase(entitySimpleName);//类实例变量名 Template controllerTemplate = BeetlTemplateUtil.getByName(ConstVal.TPL_CONTROLLER_TEST); controllerTemplate.binding(GeneratorConstant.COMMON_VARIABLE);//作者 controllerTemplate.binding(GeneratorConstant.FIRST_LOWER_NAME, firstLowName); controllerTemplate.binding(GeneratorConstant.ENTITY_SIMPLE_NAME, entitySimpleName);//类名 controllerTemplate.binding(controllerTestParams, generateParams(columnMap)); controllerTemplate.binding(GeneratorProperties.getGenerateMethods()); return controllerTemplate.render(); }
Example 8
Source File: JSGen.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("/js/index.js"); template.binding("entity", entity); template.binding("target", target); String content = template.render(); target.flush(this, content); }
Example 9
Source File: ServiceTestBuilder.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 entitySimpleName = StringUtil.toCapitalizeCamelCase(tableTemp);//类名 String firstLowName = StringUtil.firstToLowerCase(entitySimpleName); String templateName = GeneratorProperties.getDbTemplatePath()+"/"+ConstVal.TPL_SERVICE_TEST; Template serviceTestTemplate = BeetlTemplateUtil.getByName(templateName); serviceTestTemplate.binding(GeneratorConstant.COMMON_VARIABLE);//作者 serviceTestTemplate.binding(GeneratorConstant.FIRST_LOWER_NAME, firstLowName); serviceTestTemplate.binding(GeneratorConstant.ENTITY_SIMPLE_NAME, entitySimpleName);//类名 serviceTestTemplate.binding(GeneratorProperties.getGenerateMethods());//过滤方法 return serviceTestTemplate.render(); }
Example 10
Source File: PojoTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testWrongSimple() throws Exception { Pojo2 p = new Pojo2(); Template t = gt.getTemplate("/lang/pojo2_template.html"); t.binding("p",p); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/lang/pojo2_expected.html"), str); }
Example 11
Source File: DocBuilderTemplate.java From smart-doc with Apache License 2.0 | 5 votes |
/** * Generate a single controller api document * * @param projectBuilder projectBuilder * @param controllerName controller name * @param template template * @param fileExtension file extension */ public void buildSingleApi(ProjectDocConfigBuilder projectBuilder, String controllerName, String template, String fileExtension) { ApiConfig config = projectBuilder.getApiConfig(); FileUtil.mkdirs(config.getOutPath()); IDocBuildTemplate<ApiDoc> docBuildTemplate = new SpringBootDocBuildTemplate(); ApiDoc doc = docBuildTemplate.getSingleApiData(projectBuilder, controllerName); Template mapper = BeetlTemplateUtil.getByName(template); mapper.binding(TemplateVariable.DESC.getVariable(), doc.getDesc()); mapper.binding(TemplateVariable.NAME.getVariable(), doc.getName()); mapper.binding(TemplateVariable.LIST.getVariable(), doc.getList()); FileUtil.writeFileNotAppend(mapper.render(), config.getOutPath() + FILE_SEPARATOR + doc.getName() + fileExtension); }
Example 12
Source File: ServiceBuilder.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 templateName = GeneratorProperties.getDbTemplatePath()+"/"+ConstVal.TPL_SERVICE; Template serviceTemplate = BeetlTemplateUtil.getByName(templateName); serviceTemplate.binding(GeneratorConstant.PRIMARY_KEY_TYPE, tableInfo.getPrimaryKeyType()); serviceTemplate.binding(GeneratorConstant.COMMON_VARIABLE);//作者 serviceTemplate.binding(GeneratorConstant.ENTITY_SIMPLE_NAME, entitySimpleName);//类名 serviceTemplate.binding(GeneratorProperties.getGenerateMethods());//过滤方法 return serviceTemplate.render(); }
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: RpcHtmlBuilder.java From smart-doc with Apache License 2.0 | 5 votes |
/** * build error_code html * * @param errorCodeList list of error code * @param outPath */ private static void buildErrorCodeDoc(List<ApiErrorCode> errorCodeList, String outPath) { if (CollectionUtil.isNotEmpty(errorCodeList)) { Template error = BeetlTemplateUtil.getByName(ERROR_CODE_LIST_MD_TPL); error.binding(TemplateVariable.LIST.getVariable(), errorCodeList); String errorHtml = MarkDownUtil.toHtml(error.render()); Template errorCodeDoc = BeetlTemplateUtil.getByName(HTML_API_DOC_TPL); errorCodeDoc.binding(TemplateVariable.VERSION.getVariable(), now); errorCodeDoc.binding(TemplateVariable.HTML.getVariable(), errorHtml); errorCodeDoc.binding(TemplateVariable.TITLE.getVariable(), ERROR_CODE_LIST_EN_TITLE); errorCodeDoc.binding(TemplateVariable.CREATE_TIME.getVariable(), DateTimeUtil.long2Str(now, DateTimeUtil.DATE_FORMAT_SECOND)); FileUtil.nioWriteFile(errorCodeDoc.render(), outPath + FILE_SEPARATOR + "error_code.html"); } }
Example 15
Source File: AssignTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testLeftAsign() throws Exception { Template t = gt.getTemplate("/exp/assign/left_template.html"); t.binding("d", 100); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/assign/left_expected.html"), str); t = gt.getTemplate("/exp/assign/left_template.html"); t.binding("d", 100); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/exp/assign/left_expected.html"), str); }
Example 16
Source File: CodeWriter.java From ApplicationPower with Apache License 2.0 | 5 votes |
private void writeDbSourceAndJTACode(ConfigBuilder config, SpringBootProjectConfig projectConfig) { String basePackage = GeneratorProperties.basePackage(); Map<String, String> dirMap = config.getPathInfo(); Set<String> dataSources = GeneratorProperties.getMultipleDataSource(); if (GeneratorProperties.isJTA() || dataSources.size() > 0) { Template jtaTpl = BeetlTemplateUtil.getByName(ConstVal.TPL_JTA); jtaTpl.binding(GeneratorConstant.COMMON_VARIABLE); // FileUtil.writeFileNotAppend(jtaTpl.render(),dirMap.get(ConstVal.DATA_SOURCE_FIG)+"\\TransactionManagerConfig.java"); } if (dataSources.size() > 0) { String configPath = dirMap.get(ConstVal.DATA_SOURCE_FIG); Template aspectTpl = BeetlTemplateUtil.getByName(ConstVal.TPL_DATASOURCE_ASPECT); aspectTpl.binding(GeneratorConstant.COMMON_VARIABLE); FileUtil.writeFileNotAppend(aspectTpl.render(), dirMap.get(ConstVal.ASPECT) + ConstVal.FILE_SEPARATOR + "DbAspect.java"); DataSourceKeyBuilder sourceKeyBuilder = new DataSourceKeyBuilder(); String dataSourceTpl = sourceKeyBuilder.builderDataSourceKey(dataSources); FileUtil.writeFileNotAppend(dataSourceTpl, dirMap.get(ConstVal.CONSTANTS) + ConstVal.FILE_SEPARATOR + "DataSourceKey.java"); Template abstractCfg = BeetlTemplateUtil.getByName(ConstVal.TPL_DATASOURCE_CFG); abstractCfg.binding(GeneratorConstant.COMMON_VARIABLE); FileUtil.writeFileNotAppend(abstractCfg.render(), configPath + ConstVal.FILE_SEPARATOR + "AbstractDataSourceConfig.java"); SpringBootMybatisCfgBuilder builder = new SpringBootMybatisCfgBuilder(); String mybatisCfgTpl = builder.createMybatisCfg(dataSources); FileUtil.writeFileNotAppend(mybatisCfgTpl, configPath + ConstVal.FILE_SEPARATOR + "MyBatisConfig.java"); } }
Example 17
Source File: GunsTemplateEngine.java From MeetingFilm with Apache License 2.0 | 5 votes |
protected void configTemplate(Template template) { template.binding("controller", super.controllerConfig); template.binding("context", super.contextConfig); template.binding("dao", super.daoConfig); template.binding("service", super.serviceConfig); template.binding("sqls", super.sqlConfig); template.binding("table", super.tableInfo); }
Example 18
Source File: JSGen.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("/js/edit.js"); template.binding("entity", entity); template.binding("target", target); String content = template.render(); target.flush(this, content); }
Example 19
Source File: DocBuilderTemplate.java From smart-doc with Apache License 2.0 | 3 votes |
/** * build error_code adoc * * @param config api config * @param template template * @param outPutFileName output file */ public void buildErrorCodeDoc(ApiConfig config, String template, String outPutFileName) { List<ApiErrorCode> errorCodeList = errorCodeDictToList(config); Template mapper = BeetlTemplateUtil.getByName(template); mapper.binding(TemplateVariable.LIST.getVariable(), errorCodeList); FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + FILE_SEPARATOR + outPutFileName); }
Example 20
Source File: DocBuilderTemplate.java From smart-doc with Apache License 2.0 | 3 votes |
/** * build common_data doc * * @param config api config * @param javaProjectBuilder JavaProjectBuilder * @param template template * @param outPutFileName output file */ public void buildDirectoryDataDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder, String template, String outPutFileName) { List<ApiDocDict> directoryList = buildDictionary(config, javaProjectBuilder); Template mapper = BeetlTemplateUtil.getByName(template); setDirectoryLanguageVariable(config, mapper); mapper.binding(TemplateVariable.DICT_LIST.getVariable(), directoryList); FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + FILE_SEPARATOR + outPutFileName); }