Commit 6e102e7c authored by Alexander Basov's avatar Alexander Basov Committed by Matija Obreza
Browse files

Feature #28109 Genesys documentation pages (setup ascii-doctor plagin)

parent dcee4a11
......@@ -659,6 +659,7 @@
<doctype>book</doctype>
<sourceHighlighter>coderay</sourceHighlighter>
<attributes>
<stylesheet>${basedir}/src/main/sourceapp/styles/ascii-doc.scss</stylesheet>
<copycss>true</copycss>
<!-- <linkcss /> -->
<toc>left</toc>
......
package org.genesys2.server.servlet.controller;
import org.apache.commons.io.IOUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@Controller
@RequestMapping("/doc")
public class AsciiDocController extends BaseController {
private static final String GENERATED_DOCS_DIR = "/generated-docs/";
private static final String GENERATED_DOCS_SECTIONS_DIR = "sections/";
private static final String HTML_EXTENSION = ".html";
private static final String PNG_EXTENSION = ".png";
@RequestMapping("/0/{documentName}")
public String viewDoc(ModelMap model, @PathVariable(value = "documentName") String documentName) throws IOException {
String docPath = getDocPathByName(documentName, HTML_EXTENSION);
InputStream resourceStream = new FileInputStream(docPath);
String html = IOUtils.toString(resourceStream);
Document document = Jsoup.parse(html);
String title = document.getElementsByTag("title").text();
String head = document.getElementsByTag("head").toString();
String menu = document.getElementById("toc").toString();
document.getElementById("toc").remove();
Element header = document.getElementById("header");
header.getElementsByTag("h1").remove();
header.attr("id", "body-header");
Element content = document.getElementById("content");
content.attr("id", "body-content");
Element footer = document.getElementById("footer");
footer.attr("id", "body-footer");
model.addAttribute("title", title);
model.addAttribute("head", head);
model.addAttribute("menu", menu);
model.addAttribute("bodyHeader", header.toString());
model.addAttribute("bodyContent", content.toString());
model.addAttribute("bodyFooter", footer.toString());
return "/content/ascii-doc";
}
@RequestMapping("/0/sections/{documentName}")
public String viewSection(ModelMap model, @PathVariable(value = "documentName") String documentName) throws IOException {
return viewDoc(model, GENERATED_DOCS_SECTIONS_DIR + documentName);
}
@RequestMapping("/0/images/{imageName}")
@ResponseBody
public byte[] getImage(@PathVariable(value = "imageName") String imageName) throws IOException {
String imagePath = getDocPathByName("images/" + imageName, PNG_EXTENSION);
InputStream inputStream = new FileInputStream(imagePath);
return IOUtils.toByteArray(inputStream);
}
private String getDocPathByName(String documentName, String extension) {
URL classesFolderURL = this.getClass().getProtectionDomain()
.getCodeSource().getLocation();
File classesFolderFile = new File(classesFolderURL.getPath());
String targetFolderName = classesFolderFile.getParent();
return targetFolderName + GENERATED_DOCS_DIR + documentName + extension;
}
}
#toc {
border-bottom:1px solid #efefed;
padding-bottom:.5em
}
#toc>ul {
margin-left:.125em
}
#toc ul.sectlevel0>li>a {
font-style:italic
}
#toc ul.sectlevel0 ul.sectlevel1 {
margin:.5em 0
}
#toc ul {
font-family:"Open Sans","DejaVu Sans",sans-serif;
list-style-type:none
}
#toc li {
line-height:1.3334
}
#toc a {
text-decoration:none
}
#toc a:active {
text-decoration:underline
}
#toctitle {
color:#7a2518;
font-size:1.2em
}
@media only screen and (min-width:768px) {
#toctitle{
font-size:1.375em;
}
body.toc2 {
padding-right:0
}
#toc.toc2 {
margin-top:0!important;
background-color:#f8f8f7;
position:relative;
width:15em;
left:0;
top:0;
border-right:1px solid #efefed;
border-top-width:0!important;
border-bottom-width:0!important;
z-index:1000;
padding:1.25em 1em;
height:100%;
overflow:auto
}
#toc.toc2 #toctitle {
margin-top:0;
margin-bottom:.8rem;
font-size:1.2em
}
#toc.toc2>ul {
font-size:.9em;
margin-bottom:0
}
#toc.toc2 ul ul {
margin-left:0;
padding-left:1em
}
#toc.toc2 ul.sectlevel0 ul.sectlevel1 {
padding-left:0;
margin-top:.5em;
margin-bottom:.5em
}
body.toc2.toc-right {
padding-left:0;
padding-right:15em
}
body.toc2.toc-right #toc.toc2 {
border-right-width:0;
border-left:1px solid #efefed;
left:auto;right:0
}
}
@media only screen and (min-width:1280px) {
body.toc2 {
padding-right:0
}
#toc.toc2 {
width:20em
}
#toc.toc2 #toctitle {
font-size:1.375em
}
#toc.toc2>ul {
font-size:.95em
}
#toc.toc2 ul ul {
padding-left:1.25em
}
body.toc2.toc-right {
padding-left:0;
padding-right:20em
}
}
.article img {
border:0
}
.article img,object,embed {
max-width:100%;
height:auto
}
.article img {
-ms-interpolation-mode:bicubic
}
.article img,object,svg {
display:inline-block;
vertical-align:middle
}
.article a img {
border:none
}
\ No newline at end of file
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp" %>
<html>
<head>
<c:out value="${head}" escapeXml="false" />
<title>${title}</title>
</head>
<body>
<content tag="header">
<div class="hidden-xs top-image">
<img src="<c:url value="/html/images/aim/banner-${jspHelper.randomInt(1, 4)}.jpg" />" title="${title}"/>
</div>
<div class="top-title">
<div class="container">
<h1>
<c:out value="${title}" escapeXml="false"/>
</h1>
</div>
</div>
</content>
<%@include file="transifex-responses.jsp" %>
<div class="article">
<div class="right-side main-col col-md-9">
<div class="free-text">
<c:out value="${bodyHeader}" escapeXml="false"/>
<c:out value="${bodyContent}" escapeXml="false"/>
<c:out value="${bodyFooter}" escapeXml="false"/>
</div>
</div>
<div class="col-md-3 col-xs-12">
<c:out value="${menu}" escapeXml="false"/>
</div>
</div>
<content tag="javascript">
<script type="text/javascript">
$(document).ready(function () {
$('a[href="' + window.location.pathname + '"]').parent().addClass('active-link');
});
</script>
</content>
</body>
</html>
\ No newline at end of file
......@@ -25,6 +25,7 @@
<mapping path="/welcome" decorator="/WEB-INF/decorator/entry.jsp" />
<mapping path="/*" decorator="/WEB-INF/decorator/main.jsp" />
<mapping path="/content/*" decorator="/WEB-INF/decorator/article.jsp" />
<mapping path="/doc/*" decorator="/WEB-INF/decorator/article.jsp" />
<mapping path="/html/*" exclude="true" />
<mapping path="/index.html" exclude="true" />
<mapping path="*/ajax/*" exclude="true" />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment