Skip to content

Commit

Permalink
update index.btl
Browse files Browse the repository at this point in the history
  • Loading branch information
shalousun committed Nov 6, 2019
1 parent 85789c8 commit d86e87f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

}

}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/template/Dictionary.btl
Original file line number Diff line number Diff line change
@@ -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}
<%}%>
<%}%>
<%}%>
15 changes: 15 additions & 0 deletions src/main/resources/template/Index.btl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit d86e87f

Please sign in to comment.