From d86e87fcd727fb2cfefb4ba350756f1791a788dc Mon Sep 17 00:00:00 2001 From: oppofind <836575280@qq.com> Date: Wed, 6 Nov 2019 18:38:13 +0800 Subject: [PATCH] update index.btl --- .../power/doc/builder/HtmlApiDocBuilder.java | 34 +++++++++++++++++++ .../doc/constants/DocGlobalConstants.java | 4 ++- src/main/resources/template/Dictionary.btl | 16 +++++++++ src/main/resources/template/Index.btl | 15 ++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/template/Dictionary.btl diff --git a/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java b/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java index e29b1b12..20127b53 100644 --- a/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java +++ b/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java @@ -3,10 +3,12 @@ import com.power.common.util.CollectionUtil; import com.power.common.util.DateTimeUtil; import com.power.common.util.FileUtil; +import com.power.doc.constants.DocGlobalConstants; import com.power.doc.constants.DocLanguage; import com.power.doc.constants.TemplateVariable; import com.power.doc.model.ApiConfig; import com.power.doc.model.ApiDoc; +import com.power.doc.model.ApiDocDict; import com.power.doc.model.ApiErrorCode; import com.power.doc.utils.BeetlTemplateUtil; import com.power.doc.utils.MarkDownUtil; @@ -42,10 +44,13 @@ public static void builderControllersApi(ApiConfig config) { FileUtil.nioWriteFile(indexCssTemplate.render(), config.getOutPath() + FILE_SEPARATOR + ALL_IN_ONE_CSS); builderTemplate.buildAllInOne(apiDocList, config, ALL_IN_ONE_HTML_TPL, INDEX_HTML); } else { + List<ApiDocDict> apiDocDictList = builderTemplate.buildDictionary(config); buildIndex(apiDocList, config); copyCss(config.getOutPath()); buildApiDoc(apiDocList, config.getOutPath()); buildErrorCodeDoc(config.getErrorCodes(), config.getOutPath()); + buildDictionary(apiDocDictList,config.getOutPath()); + } } @@ -74,14 +79,24 @@ private static void buildIndex(List<ApiDoc> apiDocList, ApiConfig config) { indexTemplate.binding(TemplateVariable.HOME_PAGE.getVariable(), homePage); indexTemplate.binding(TemplateVariable.API_DOC_LIST.getVariable(), apiDocList); indexTemplate.binding(TemplateVariable.VERSION.getVariable(), now); + indexTemplate.binding(TemplateVariable.ERROR_CODE_LIST.getVariable(),config.getErrorCodes()); + indexTemplate.binding(TemplateVariable.DICT_LIST.getVariable(),config.getDataDictionaries()); + if (CollectionUtil.isEmpty(config.getErrorCodes())) { + indexTemplate.binding(TemplateVariable.DICT_ORDER.getVariable(), apiDocList.size() + 1); + } else { + indexTemplate.binding(TemplateVariable.DICT_ORDER.getVariable(), apiDocList.size() + 2); + } if (null != config.getLanguage()) { if (DocLanguage.CHINESE.code.equals(config.getLanguage().getCode())) { indexTemplate.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), ERROR_CODE_LIST_CN_TITLE); + indexTemplate.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_CN_TITLE); } else { indexTemplate.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), ERROR_CODE_LIST_EN_TITLE); + indexTemplate.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_EN_TITLE); } } else { indexTemplate.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), ERROR_CODE_LIST_CN_TITLE); + indexTemplate.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_CN_TITLE); } FileUtil.nioWriteFile(indexTemplate.render(), config.getOutPath() + FILE_SEPARATOR + "api.html"); } @@ -131,4 +146,23 @@ private static void buildErrorCodeDoc(List<ApiErrorCode> errorCodeList, String o FileUtil.nioWriteFile(errorCodeDoc.render(), outPath + FILE_SEPARATOR + "error_code.html"); } } + + /** + * build dictionary + * @param apiDocDictList dictionary list + * @param outPath + */ + private static void buildDictionary(List<ApiDocDict> apiDocDictList, String outPath) { + if(CollectionUtil.isNotEmpty(apiDocDictList)){ + Template template = BeetlTemplateUtil.getByName(DICT_LIST_MD_TPL); + template.binding(TemplateVariable.DICT_LIST.getVariable(), apiDocDictList); + 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(), outPath + FILE_SEPARATOR + "dict.html"); + } + } } diff --git a/src/main/java/com/power/doc/constants/DocGlobalConstants.java b/src/main/java/com/power/doc/constants/DocGlobalConstants.java index e2ce7efa..7aef4053 100644 --- a/src/main/java/com/power/doc/constants/DocGlobalConstants.java +++ b/src/main/java/com/power/doc/constants/DocGlobalConstants.java @@ -35,6 +35,8 @@ public class DocGlobalConstants { public static final String ERROR_CODE_LIST_ADOC = "ErrorCodeList.md"; + public static final String DICT_LIST_MD_TPL = "Dictionary.btl"; + public static final String INDEX_TPL = "Index.btl"; public static final String INDEX_CSS_TPL = "index.css"; @@ -79,7 +81,7 @@ public class DocGlobalConstants { public static final String DICT_CN_TITLE = "数据字典"; - public static final String DICT_EN_TITLE = "Data Dictionary"; + public static final String DICT_EN_TITLE = "Data Dictionaries"; public static final String FIELD_SPACE = " "; diff --git a/src/main/resources/template/Dictionary.btl b/src/main/resources/template/Dictionary.btl new file mode 100644 index 00000000..71605509 --- /dev/null +++ b/src/main/resources/template/Dictionary.btl @@ -0,0 +1,16 @@ +<%if(isNotEmpty(dictList)){%> +# Data Dictionaries +<% +for(dict in dictList){ +%> +## ${dict.title} + +Code |Type|Description +---|---|--- +<% +for(dataDict in dict.dataDictList){ +%> +${dataDict.value}|${dataDict.type}|${dataDict.desc} +<%}%> +<%}%> +<%}%> \ No newline at end of file diff --git a/src/main/resources/template/Index.btl b/src/main/resources/template/Index.btl index 9a0e4084..ff34761a 100644 --- a/src/main/resources/template/Index.btl +++ b/src/main/resources/template/Index.btl @@ -31,9 +31,24 @@ </ul> </li> <%}%> + <%if(isNotEmpty(errorCodeList)){%> <li class="chapter " data-level="error_code" data-path="error_code.html"> <a href="error_code.html?v=${version}" target="book_iframe">${apiDocList.~size+1}. ${errorListTitle}</a> </li> + <%}%> + <%if(isNotEmpty(dictList)){%> + <li class="chapter " data-level="dict" data-path="dict.html"> + <a href="dict.html?v=${version}" target="book_iframe">${dictListOrder}. ${dictListTitle}</a> + <ul class="articles"> + <% + for(dict in dictList){ + %> + <li class="chapter " data-level="${dict.title}" data-path="dict.html"> + <a href="dict.html?v=${version}" target="book_iframe">${dictListOrder}.${dictLP.index} ${dict.title}</a></li> + <%}%> + </ul> + </li> + <%}%> <li class="divider"></li> <li class="footer_link"><a href="https://github.com/shalousun/smart-doc" target="_blank" class="gitbook-link">Created by smart-doc</a> </li>