Search in sources :

Example 1 with Doc

use of org.eclipse.ceylon.common.tools.help.model.Doc in project ceylon by eclipse.

the class CeylonDocToolTool method generateToolList.

private void generateToolList(List<Doc> docs, Html html, String title) {
    html.open("table class='table table-condensed table-bordered table-hover'").text("\n");
    html.open("thead").text("\n");
    html.open("tr class='table-header'");
    html.open("td colspan='2'").text(title).close("td");
    html.close("tr").text("\n");
    html.close("thead").text("\n");
    html.open("tbody");
    for (Doc doc : docs) {
        html.open("tr");
        html.open("td class='span3'", "a class='link' href='" + filename(doc) + "'");
        html.open("code").text(Tools.progName() + " " + doc.getName()).close("code");
        html.close("a", "td").text("\n");
        html.open("td", "p");
        html.text(doc.getSummary().getSummary());
        html.close("p", "td");
        html.close("tr").text("\n");
    }
    html.close("tbody").text("\n");
    html.close("table").text("\n");
}
Also used : Doc(org.eclipse.ceylon.common.tools.help.model.Doc)

Example 2 with Doc

use of org.eclipse.ceylon.common.tools.help.model.Doc in project ceylon by eclipse.

the class CeylonDocToolTool method generateDoc.

private void generateDoc(List<Doc> docs) throws IOException {
    for (Doc doc : docs) {
        File out = new File(applyCwd(dir), filename(doc));
        try (FileWriter writer = new FileWriter(out)) {
            Visitor visitor = format.newOutput(this, writer);
            doc.accept(visitor);
        }
    }
    if (index && format == Format.html) {
        generateIndexHtml(docs);
    }
}
Also used : Visitor(org.eclipse.ceylon.common.tools.help.model.Visitor) FileWriter(java.io.FileWriter) Doc(org.eclipse.ceylon.common.tools.help.model.Doc) File(java.io.File)

Example 3 with Doc

use of org.eclipse.ceylon.common.tools.help.model.Doc in project ceylon by eclipse.

the class CeylonDocToolTool method generateIndexHtml.

private void generateIndexHtml(List<Doc> docs) throws IOException {
    File indexFile = new File(applyCwd(dir), "index" + format.extension);
    ResourceBundle bundle = CeylonHelpToolMessages.RESOURCE_BUNDLE;
    try (FileWriter writer = new FileWriter(indexFile)) {
        HtmlVisitor htmlOutput = (HtmlVisitor) Format.html.newOutput(this, writer);
        Html html = htmlOutput.getHtml();
        indexHeader(html, bundle.getString("index.title"), bundle.getString("index.overview"));
        List<Doc> porcelain = new ArrayList<>();
        List<Doc> plumbing = new ArrayList<>();
        for (Doc model : docs) {
            if (model.getToolModel().isPorcelain() || model.getName().isEmpty()) {
                porcelain.add(model);
            } else if (model.getToolModel().isPlumbing()) {
                plumbing.add(model);
            }
        }
        if (!porcelain.isEmpty()) {
            generateToolList(porcelain, html, bundle.getString("index.porcelain.tools"));
        }
        if (!plumbing.isEmpty()) {
            generateToolList(plumbing, html, bundle.getString("index.plumbing.tools"));
        }
        indexFooter(html);
    }
}
Also used : FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) Doc(org.eclipse.ceylon.common.tools.help.model.Doc) ResourceBundle(java.util.ResourceBundle) File(java.io.File)

Example 4 with Doc

use of org.eclipse.ceylon.common.tools.help.model.Doc in project ceylon by eclipse.

the class CeylonHelpTool method run.

@Override
public void run() {
    if (wantsPager && OSUtil.isWindows() && tool != null) {
        if (openHelpInBrowser()) {
            return;
        }
    }
    docBuilder.setIncludeHidden(includeHidden);
    Doc doc;
    if (tool != null) {
        doc = docBuilder.buildDoc(tool);
    } else {
        final ToolModel<CeylonTool> root = toolLoader.loadToolModel("");
        doc = docBuilder.buildDoc(root, true);
    }
    Process pagerProcess = null;
    if (wantsPager && !OSUtil.isWindows()) {
        pagerProcess = startPager();
    }
    OutputStream pagerPipe = null;
    if (pagerProcess != null)
        pagerPipe = pagerProcess.getOutputStream();
    try {
        final WordWrap wrap = getWrap(pagerPipe);
        Visitor plain = new PlainVisitor(wrap);
        if (synopsis) {
            plain = new SynopsisOnlyVisitor(plain);
        } else if (options != null) {
            plain = new OptionsOnlyVisitor(plain, new HashSet<String>(Arrays.asList(options.trim().split("\\s*,\\s*"))));
        }
        doc.accept(plain);
        wrap.flush();
    } finally {
        // shutdown pager
        if (pagerPipe != null) {
            try {
                pagerPipe.close();
            } catch (IOException e) {
            // Seems common on MacOS so let's just ignore this
            }
            // wait for pager to be done, there's no point doing anything else meanwhile
            try {
                int errorCode = pagerProcess.waitFor();
                if (errorCode != 0) {
                    throw new ToolUsageError("Pager process returned an error exit code: " + errorCode + ". Try fixing your $CEYLON_PAGER or $PAGER environment variable or invoke with the --no-pager command-line option.");
                }
            } catch (InterruptedException e) {
                throw new ToolUsageError("Pager process interrupted. Try fixing your $CEYLON_PAGER or $PAGER environment variable or invoke with the --no-pager command-line option.");
            }
        }
    }
}
Also used : Visitor(org.eclipse.ceylon.common.tools.help.model.Visitor) OutputStream(java.io.OutputStream) CeylonTool(org.eclipse.ceylon.common.tools.CeylonTool) IOException(java.io.IOException) WordWrap(org.eclipse.ceylon.common.tool.WordWrap) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) Doc(org.eclipse.ceylon.common.tools.help.model.Doc)

Example 5 with Doc

use of org.eclipse.ceylon.common.tools.help.model.Doc in project ceylon by eclipse.

the class DocBuilder method buildDoc.

public Doc buildDoc(ToolModel<?> model, boolean specialRoot) {
    checkModel(model);
    boolean rootHack = specialRoot && (model instanceof AnnotatedToolModel) && CeylonTool.class.isAssignableFrom(((AnnotatedToolModel<?>) model).getToolClass());
    Doc doc = new Doc();
    doc.setVersion(Versions.CEYLON_VERSION);
    doc.setToolModel(model);
    doc.setInvocation(getCeylonInvocation(model));
    doc.setSummary(buildSummary(model));
    doc.setSynopses(rootHack ? buildRootSynopsis(model) : buildSynopsis(model));
    doc.setDescription(rootHack ? buildRootDescription(model) : buildDescription(model));
    doc.setOptions(buildOptions(model));
    if (model.getSubtoolModel() != null) {
    // doc.setSubcommands(buildSubcommands(model));
    }
    doc.setAdditionalSections(buildAdditionalSections(model));
    return doc;
}
Also used : AnnotatedToolModel(org.eclipse.ceylon.common.tool.AnnotatedToolModel) Doc(org.eclipse.ceylon.common.tools.help.model.Doc) CeylonTool(org.eclipse.ceylon.common.tools.CeylonTool)

Aggregations

Doc (org.eclipse.ceylon.common.tools.help.model.Doc)5 File (java.io.File)2 FileWriter (java.io.FileWriter)2 CeylonTool (org.eclipse.ceylon.common.tools.CeylonTool)2 Visitor (org.eclipse.ceylon.common.tools.help.model.Visitor)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 ResourceBundle (java.util.ResourceBundle)1 AnnotatedToolModel (org.eclipse.ceylon.common.tool.AnnotatedToolModel)1 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)1 WordWrap (org.eclipse.ceylon.common.tool.WordWrap)1