All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.sinri.keel.web.http.fastdocs.page.MarkdownPageBuilder Maven / Gradle / Ivy

Go to download

A website framework with VERT.X for ex-PHP-ers, exactly Ark Framework Users.

The newest version!
package io.github.sinri.keel.web.http.fastdocs.page;

import io.github.sinri.keel.markdown.KeelMarkdownKit;
import io.vertx.core.Future;
import io.vertx.ext.web.RoutingContext;

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

import static io.github.sinri.keel.helper.KeelHelpersInterface.KeelHelpers;

/**
 * @since 1.12
 */
public class MarkdownPageBuilder implements FastDocsContentResponder {

    private final PageBuilderOptions options;

    public MarkdownPageBuilder(PageBuilderOptions options) {
        this.options = options;
    }

    protected String getPageTitle() {
        return options.subjectOfDocuments
                + " - "
                + URLDecoder.decode(options.ctx.request().path().substring(this.options.rootURLPath.length()), StandardCharsets.UTF_8);
    }

    protected String getLogoDivContent() {
        return options.subjectOfDocuments;
    }

    protected String getComputedBreadcrumbDivContent() {
        String[] components = URLDecoder.decode(
                options.ctx.request().path().substring(this.options.rootURLPath.length()),
                StandardCharsets.UTF_8
        ).split("/");
        List x = new ArrayList<>();
        StringBuilder href = new StringBuilder(this.options.rootURLPath);
        x.add("" + options.subjectOfDocuments + "");
        for (var component : components) {
            if (!href.toString().endsWith("/")) {
                href.append("/");
            }
            href.append(component);
            x.add("" + component + "");
        }
        return KeelHelpers.stringHelper().joinStringArray(x, " ‣ ");
    }

    protected String getFooterDivContent() {
        return options.footerText + " 
|
Powered by FastDocs"; } private String getCatalogueLink(String fromDoc) { return this.options.rootURLPath + "catalogue" + ( (fromDoc != null && !fromDoc.isEmpty()) ? ("?from_doc=" + fromDoc) : "" ); } protected String buildPage() { KeelMarkdownKit keelMarkdownKit = new KeelMarkdownKit(); return "\n" + "\n" + "\n" + " \n" + " " + getPageTitle() + "\n" + " \n" + " \n" + " \n" + " \n" + "
\n" + "
" + getLogoDivContent() + "
\n" + "
" + getComputedBreadcrumbDivContent() + "
\n" + "
\n" + "
\n" + " " + keelMarkdownKit.convertMarkdownToHtml(options.markdownContent) + "\n" + "
\n" + "
\n" + "
" + getFooterDivContent() + "
\n" + "
|
\n" + "
\n" + " Catalogue\n" + "
\n" + "
\n" + "
\n" + " \n" + "
\n" + " \n" + ""; } @Override public void setRoutingContext(RoutingContext ctx) { this.options.ctx = ctx; } @Override public Future respond() { return this.options.ctx.response() .putHeader("Content-Type", "text/html;charset=UTF-8") .end(this.buildPage()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy