Search in sources :

Example 6 with SplitOutlineItem

use of org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem in project mylyn.docs by eclipse.

the class WikiToDocTask method computeTocRelativeFile.

private String computeTocRelativeFile(OutlineItem item, Path path) {
    String name = ((SplitOutlineItem) item).getSplitTarget();
    File pathDestDir = computeDestDir(path);
    File tocParentFile = tocFile.getParentFile();
    String prefix = computePrefixPath(pathDestDir, tocParentFile);
    String relativePath = prefix + '/' + name;
    relativePath = relativePath.replace('\\', '/');
    if (helpPrefix != null) {
        String helpPath = helpPrefix;
        helpPath = helpPath.replace('\\', '/');
        if (!helpPath.endsWith("/")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            helpPath += "/";
        }
        relativePath = helpPath + relativePath;
    }
    // $NON-NLS-1$//$NON-NLS-2$
    relativePath = relativePath.replaceAll("/{2,}", "/");
    return relativePath;
}
Also used : SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) File(java.io.File)

Example 7 with SplitOutlineItem

use of org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem in project mylyn.docs by eclipse.

the class MarkupToEclipseHelpMojoTest method embeddedTableOfContents.

@Test
public void embeddedTableOfContents() {
    HtmlDocumentBuilder builder = mock(HtmlDocumentBuilder.class);
    SplitOutlineItem item = mock(SplitOutlineItem.class);
    File htmlOutputFile = mock(File.class);
    SplittingHtmlDocumentBuilder splittingBuilder = markupToEclipseHelp.createSplittingBuilder(builder, item, htmlOutputFile, "");
    assertFalse(splittingBuilder.isEmbeddedTableOfContents());
    markupToEclipseHelp.embeddedTableOfContents = true;
    splittingBuilder = markupToEclipseHelp.createSplittingBuilder(builder, item, htmlOutputFile, "");
    assertTrue(splittingBuilder.isEmbeddedTableOfContents());
}
Also used : SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) File(java.io.File) Test(org.junit.Test)

Example 8 with SplitOutlineItem

use of org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem in project mylyn.docs by eclipse.

the class MarkupToEclipseHelpMojoTest method assertNavigationImagesPath.

private void assertNavigationImagesPath(String expected, String relativePath) {
    HtmlDocumentBuilder builder = mock(HtmlDocumentBuilder.class);
    SplitOutlineItem item = mock(SplitOutlineItem.class);
    SplittingHtmlDocumentBuilder splittingBuilder = markupToEclipseHelp.createSplittingBuilder(builder, item, mock(File.class), relativePath);
    assertEquals(expected, splittingBuilder.getNavigationImagePath());
}
Also used : SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) File(java.io.File)

Example 9 with SplitOutlineItem

use of org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem in project mylyn.docs by eclipse.

the class MarkupToEclipseHelpMojo method processMarkup.

protected void processMarkup(File sourceFile, String relativePath, MarkupLanguage markupLanguage) {
    getLog().info(format("Processing markup file: {0}", sourceFile));
    String name = sourceFile.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    File htmlOutputFile = computeHtmlFile(relativePath, name);
    if (!htmlOutputFile.exists() || htmlOutputFile.lastModified() < sourceFile.lastModified()) {
        String markupContent = readFully(sourceFile);
        if (!htmlOutputFile.getParentFile().exists()) {
            if (!htmlOutputFile.getParentFile().mkdirs()) {
                throw new BuildFailureException(format("Cannot create folder {0}", htmlOutputFile.getParentFile()));
            }
        }
        Writer writer = createWriter(htmlOutputFile);
        try {
            HtmlDocumentBuilder builder = createRootBuilder(writer, name, relativePath);
            SplittingStrategy splittingStrategy = createSplittingStrategy();
            SplittingOutlineParser outlineParser = createOutlineParser(markupLanguage, splittingStrategy);
            SplitOutlineItem rootTocItem = outlineParser.parse(markupContent);
            rootTocItem.setSplitTarget(htmlOutputFile.getName());
            SplittingHtmlDocumentBuilder splittingBuilder = createSplittingBuilder(builder, rootTocItem, htmlOutputFile, relativePath);
            MarkupParser parser = new MarkupParser();
            parser.setMarkupLanguage(markupLanguage);
            parser.setBuilder(splittingBuilder);
            parser.parse(markupContent);
            createEclipseHelpToc(rootTocItem, sourceFile, relativePath, htmlOutputFile, name);
        } finally {
            close(writer, htmlOutputFile);
        }
    }
}
Also used : SplittingStrategy(org.eclipse.mylyn.wikitext.splitter.SplittingStrategy) NoSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.NoSplittingStrategy) DefaultSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy) SplittingOutlineParser(org.eclipse.mylyn.wikitext.splitter.SplittingOutlineParser) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) File(java.io.File) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 10 with SplitOutlineItem

use of org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem in project mylyn.docs by eclipse.

the class SplittingHtmlDocumentBuilderTest method generateContents.

private void generateContents(String markup, boolean embeddedTableOfContents) throws IOException, FileNotFoundException {
    try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)) {
        rootBuilder = new HtmlDocumentBuilder(out, true);
        SplittingOutlineParser outlineParser = new SplittingOutlineParser();
        outlineParser.setMarkupLanguage(new TextileLanguage());
        outlineParser.setSplittingStrategy(new DefaultSplittingStrategy());
        SplitOutlineItem outline = outlineParser.parse(markup);
        outline.setSplitTarget(outputFile.getName());
        builder.setEmbeddedTableOfContents(embeddedTableOfContents);
        builder.setRootBuilder(rootBuilder);
        builder.setRootFile(outputFile);
        builder.setFormatting(true);
        builder.setOutline(outline);
        MarkupParser parser = new MarkupParser(new TextileLanguage());
        parser.setBuilder(builder);
        parser.parse(markup);
    }
}
Also used : TextileLanguage(org.eclipse.mylyn.wikitext.textile.TextileLanguage) FileOutputStream(java.io.FileOutputStream) SplittingOutlineParser(org.eclipse.mylyn.wikitext.splitter.SplittingOutlineParser) OutputStreamWriter(java.io.OutputStreamWriter) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) DefaultSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Aggregations

SplitOutlineItem (org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem)11 File (java.io.File)8 OutputStreamWriter (java.io.OutputStreamWriter)6 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)6 SplittingHtmlDocumentBuilder (org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder)6 FileOutputStream (java.io.FileOutputStream)5 Writer (java.io.Writer)5 BuildException (org.apache.tools.ant.BuildException)5 BufferedOutputStream (java.io.BufferedOutputStream)4 IOException (java.io.IOException)4 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)4 DefaultSplittingStrategy (org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy)4 SplittingOutlineParser (org.eclipse.mylyn.wikitext.splitter.SplittingOutlineParser)4 StringWriter (java.io.StringWriter)3 HashMap (java.util.HashMap)3 NoSplittingStrategy (org.eclipse.mylyn.wikitext.splitter.NoSplittingStrategy)3 SplittingStrategy (org.eclipse.mylyn.wikitext.splitter.SplittingStrategy)3 MediaWikiLanguage (org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage)2 OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)2 SplittingMarkupToEclipseToc (org.eclipse.mylyn.wikitext.splitter.SplittingMarkupToEclipseToc)2