add html and css template
This commit is contained in:
parent
c0612b61c0
commit
6b742ca614
|
@ -12,11 +12,14 @@ import org.beetl.core.Template;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import static com.power.doc.constants.GlobalConstants.FILE_SEPARATOR;
|
||||
|
||||
/**
|
||||
* use to create markdown doc
|
||||
* @author yu 2019/09/20
|
||||
*/
|
||||
public class ApiDocBuilder {
|
||||
|
||||
|
||||
public static final String FILE_SEPARATOR = System.getProperty("file.separator");
|
||||
|
||||
/**
|
||||
* 生成所有controller的api文档
|
||||
*
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package com.power.doc.builder;
|
||||
|
||||
import com.power.common.util.FileUtil;
|
||||
import com.power.common.util.StringUtil;
|
||||
import com.power.doc.model.ApiConfig;
|
||||
import com.power.doc.model.ApiDoc;
|
||||
import com.power.doc.utils.BeetlTemplateUtil;
|
||||
import org.beetl.core.Template;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import static com.power.doc.constants.GlobalConstants.FILE_SEPARATOR;
|
||||
|
||||
/**
|
||||
* @author yu 2019/9/20.
|
||||
*/
|
||||
public class HtmlApiDocBuilder {
|
||||
|
||||
/**
|
||||
* @param config 配置
|
||||
*/
|
||||
public static void builderControllersApi(ApiConfig config) {
|
||||
if (null == config) {
|
||||
throw new NullPointerException("ApiConfig can't be null");
|
||||
}
|
||||
if (StringUtil.isEmpty(config.getOutPath())) {
|
||||
throw new RuntimeException("doc output path can't be null or empty");
|
||||
}
|
||||
SourceBuilder sourceBuilder = new SourceBuilder(config);
|
||||
List<ApiDoc> apiDocList = sourceBuilder.getControllerApiData();
|
||||
buildIndex(apiDocList, config.getOutPath());
|
||||
copyCss(config.getOutPath());
|
||||
}
|
||||
|
||||
private static void copyCss(String outPath) {
|
||||
Template indexCssTemplate = BeetlTemplateUtil.getByName("index.css");
|
||||
Template mdCssTemplate = BeetlTemplateUtil.getByName("markdown.css");
|
||||
FileUtil.nioWriteFile(indexCssTemplate.render(), outPath + FILE_SEPARATOR + "index.css");
|
||||
FileUtil.nioWriteFile(mdCssTemplate.render(), outPath + FILE_SEPARATOR + "markdown.css");
|
||||
}
|
||||
|
||||
private static void buildIndex(List<ApiDoc> apiDocList, String outPath) {
|
||||
FileUtil.mkdirs(outPath);
|
||||
Template indexTemplate = BeetlTemplateUtil.getByName("Index.btl");
|
||||
ApiDoc doc = apiDocList.get(0);
|
||||
String homePage = doc.getName();
|
||||
indexTemplate.binding("home", homePage);
|
||||
indexTemplate.binding("apiDocList", apiDocList);
|
||||
FileUtil.nioWriteFile(indexTemplate.render(), outPath + FILE_SEPARATOR + "api.html");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 公共生成controller api 文档
|
||||
*
|
||||
* @param apiDocList
|
||||
* @param outPath
|
||||
*/
|
||||
private static void buildApiDoc(List<ApiDoc> apiDocList, String outPath) {
|
||||
FileUtil.mkdirs(outPath);
|
||||
for (ApiDoc doc : apiDocList) {
|
||||
Template mapper = BeetlTemplateUtil.getByName("ApiDoc.btl");
|
||||
mapper.binding("desc", doc.getDesc());
|
||||
mapper.binding("name", doc.getName());
|
||||
mapper.binding("list", doc.getList());//类名
|
||||
FileUtil.nioWriteFile(mapper.render(), outPath + FILE_SEPARATOR + doc.getName() + "Api.md");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ package com.power.doc.constants;
|
|||
*/
|
||||
public class GlobalConstants {
|
||||
|
||||
public static final String FILE_SEPARATOR = System.getProperty("file.separator");
|
||||
/**
|
||||
* controller注解全名称
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset='UTF-8'>
|
||||
<meta name='viewport' content='width=device-width initial-scale=1'>
|
||||
<link rel="stylesheet" href="index.css"/>
|
||||
</head>
|
||||
<div class="book without-animation with-summary font-size-2 font-family-1">
|
||||
<div class="book-summary">
|
||||
<div id="book-search-input"><input type="text" placeholder="Type to search"></div>
|
||||
<nav role="navigation">
|
||||
<ul class="summary">
|
||||
<li><a href="${home}.html" target="_blank" class="custom-link">Home</a></li>
|
||||
<li class="divider"></li>
|
||||
<%
|
||||
for(api in apiDocList){
|
||||
%>
|
||||
<li class="chapter " data-level="${api.name}" data-path="${api.name}.html">
|
||||
<a href="${api.name}.html" target="book_iframe">${api.desc}</a>
|
||||
<ul class="articles">
|
||||
<%
|
||||
for(doc in api.list){
|
||||
%>
|
||||
<li class="chapter " data-level="${api.name}" data-path="${api.name}.html">
|
||||
<a href="${api.name}.html" target="book_frame">${doc.desc}</a></li>
|
||||
<%}%>
|
||||
</ul>
|
||||
</li>
|
||||
<%}%>
|
||||
<li class="divider"></li>
|
||||
<li><a href="https://www.gitbook.com" target="blank" class="gitbook-link">Published with GitBook</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<div id="book-body" class="book-body" height="100%">
|
||||
<iframe src="TestControllerApi.html" frameborder="0" id="book_iframe" name="book_frame" width="100%"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
function changeFrameHeight() {
|
||||
var ifm = document.getElementById("book_iframe");
|
||||
ifm.height = document.documentElement.clientHeight
|
||||
}
|
||||
changeFrameHeight();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1 @@
|
|||
.book-summary{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;position:absolute;top:0;left:-300px;bottom:0;z-index:1;overflow-y:auto;width:300px;color:#364149;background:#fafafa;border-right:1px solid rgba(0,0,0,.07);-webkit-transition:left 250ms ease;-moz-transition:left 250ms ease;-o-transition:left 250ms ease;transition:left 250ms ease}.book-summary ul.summary{list-style:none;margin:0;padding:0;-webkit-transition:top .5s ease;-moz-transition:top .5s ease;-o-transition:top .5s ease;transition:top .5s ease}.book-summary ul.summary li{list-style:none}.book-summary ul.summary li.header{padding:10px 15px;padding-top:20px;text-transform:uppercase;color:#939da3}.book-summary ul.summary li.divider{height:1px;margin:7px 0;overflow:hidden;background:rgba(0,0,0,.07)}.book-summary ul.summary li i.fa-check{display:none;position:absolute;right:9px;top:16px;font-size:9px;color:#3c3}.book-summary ul.summary li.done>a{color:#364149;font-weight:400}.book-summary ul.summary li.done>a i{display:inline}.book-summary ul.summary li a,.book-summary ul.summary li span{display:block;padding:10px 15px;border-bottom:0;color:#364149;background:0;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;position:relative}.book-summary ul.summary li a:hover{text-decoration:underline}.book-summary ul.summary li a:focus{outline:0}.book-summary ul.summary li.active>a{color:#008cff;background:0;text-decoration:none}.book-summary ul.summary li ul{padding-left:20px}@media(max-width:600px){.book-summary{width:calc(100% - 60px);bottom:0;left:-100%}}.book.with-summary .book-summary{left:0}.book.without-animation .book-summary{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;transition:none!important}.book{position:relative;width:100%;height:100%}@media(min-width:600px){.book.with-summary .book-body{left:300px}}@media(max-width:600px){.book.with-summary{overflow:hidden}.book.with-summary .book-body{-webkit-transform:translate(calc(100% - 60px),0);-moz-transform:translate(calc(100% - 60px),0);-ms-transform:translate(calc(100% - 60px),0);-o-transform:translate(calc(100% - 60px),0);transform:translate(calc(100% - 60px),0)}}.book.without-animation .book-body{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;transition:none!important}.book-body{position:absolute;top:0;right:0;left:0;bottom:0;overflow-y:auto;color:#000;background:#fff;-webkit-transition:left 250ms ease;-moz-transition:left 250ms ease;-o-transition:left 250ms ease;transition:left 250ms ease}@media(max-width:1240px){.book-body{-webkit-transition:-webkit-transform 250ms ease;-moz-transition:-moz-transform 250ms ease;-o-transition:-o-transform 250ms ease;transition:transform 250ms ease;padding-bottom:20px}}#book-search-input{padding:6px;background:0;transition:top .5s ease;border-bottom:1px solid rgba(0,0,0,.07);border-top:1px solid rgba(0,0,0,.07);margin-bottom:10px;margin-top:-1px}#book-search-input input,#book-search-input input:focus,#book-search-input input:hover{width:100%;background:0;border:1px solid transparent;box-shadow:none;outline:0;line-height:22px;padding:7px 7px;color:inherit}a{text-decoration:none}body,html{height:100%}html{font-size:62.5%}body{margin:0}body{text-rendering:optimizeLegibility;font-smoothing:antialiased;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;letter-spacing:.2px;text-size-adjust:100%;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue