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");
}
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);
}
}
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);
}
}
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.");
}
}
}
}
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;
}
Aggregations