protected void setAttributesOnBuilder(AttributesBuilder attributesBuilder) throws MojoExecutionException { if (sourceHighlighter != null) { attributesBuilder.sourceHighlighter(sourceHighlighter); } if (embedAssets) { attributesBuilder.linkCss(false); attributesBuilder.dataUri(true); } if (imagesDir != null) { attributesBuilder.imagesDir(imagesDir); } if ("skip".equals(attributeMissing) || "drop".equals(attributeMissing) || "drop-line".equals(attributeMissing)) { attributesBuilder.attributeMissing(attributeMissing); } else { throw new MojoExecutionException(attributeMissing + " is not valid. Must be one of 'skip', 'drop' or 'drop-line'"); } if ("drop".equals(attributeUndefined) || "drop-line".equals(attributeUndefined)) { attributesBuilder.attributeUndefined(attributeUndefined); } else { throw new MojoExecutionException(attributeUndefined + " is not valid. Must be one of 'drop' or 'drop-line'"); } AsciidoctorHelper.addAttributes(attributes, attributesBuilder); if (!attributesChain.isEmpty()) { getLog().info("Attributes: " + attributesChain); attributesBuilder.arguments(attributesChain); } }
@Test public void copycss_with_in_place_should_copy_css_to_rendered_directory() { Attributes attributes = attributes().linkCss(true).copyCss(true).get(); Options options = options().inPlace(true).safe(SafeMode.UNSAFE) .attributes(attributes).get(); File inputFile = classpath.getResource("rendersample.asciidoc"); asciidoctor.convertFile(inputFile, options); File cssFile = new File(inputFile.getParent(),"asciidoctor.css"); assertThat(cssFile.exists(), is(true)); cssFile.delete(); }
@Test public void copycss_and_linkcss_negated_should_not_copy_css_to_rendered_file() { Attributes attributes = attributes().copyCss(true).linkCss(false).get(); Options options = options().inPlace(true).safe(SafeMode.UNSAFE) .attributes(attributes).get(); File inputFile = classpath.getResource("rendersample.asciidoc"); asciidoctor.convertFile(inputFile, options); try { File cssFile = new File(inputFile.getParent(), "asciidoctor.css"); assertThat(cssFile.exists(), is(false)); } catch (RuntimeException e) { assertThat(e.getCause(), is(instanceOf(FileNotFoundException.class))); } }
@Test public void linkcss_should_not_embed_css_file() throws IOException { Attributes attributes = attributes().linkCss(true).get(); Options options = options().inPlace(false).safe(SafeMode.UNSAFE) .toDir(testFolder.getRoot()).attributes(attributes).get(); asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options); Document doc = Jsoup.parse(new File(testFolder.getRoot(), "rendersample.html"), "UTF-8"); Elements link = doc.select("link[href]"); String attr = link.get(1).attr("href"); assertThat(attr, is("./asciidoctor.css")); }
@Test public void unsetting_linkcss_should_embed_css_file() throws IOException { Attributes attributes = attributes().linkCss(false).get(); Options options = options().inPlace(false).safe(SafeMode.UNSAFE) .toDir(testFolder.getRoot()).attributes(attributes).get(); asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options); // String readFull = IOUtils.readFull(new FileInputStream(new // File(testFolder.getRoot(), "rendersample.html"))); Document doc = Jsoup.parse(new File(testFolder.getRoot(), "rendersample.html"), "UTF-8"); Elements cssStyle = doc.select("style"); assertThat(cssStyle.html(), is(not(""))); Elements link = doc.select("link"); assertThat(link.html(), is("".trim())); }
@Test public void copycss_with_render_to_file_should_copy_css_to_to_file_directory() { Attributes attributes = attributes().linkCss(true).copyCss(true).get(); Options options = options().inPlace(false) .toFile(new File(testFolder.getRoot(), "output.html")) .safe(SafeMode.UNSAFE).attributes(attributes).get(); asciidoctor.convert("This is Asciidoctor", options); File cssFile = new File(testFolder.getRoot(), "asciidoctor.css"); assertThat(cssFile.exists(), is(true)); }
@Test public void copycss_with_to_file_should_copy_css_to_to_file_directory() { Attributes attributes = attributes().linkCss(true).copyCss(true).get(); Options options = options().inPlace(false) .toFile(new File(testFolder.getRoot(), "output.html")) .safe(SafeMode.UNSAFE).attributes(attributes).get(); asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options); File cssFile = new File(testFolder.getRoot(), "asciidoctor.css"); assertThat(cssFile.exists(), is(true)); }
@Test public void copycss_with_render_to_dir_should_copy_css_to_to_dir_directory() { Attributes attributes = attributes().linkCss(true).copyCss(true).get(); Options options = options().inPlace(false).toDir(testFolder.getRoot()) .safe(SafeMode.UNSAFE).attributes(attributes).get(); asciidoctor.convert("This is Asciidoctor", options); File cssFile = new File(testFolder.getRoot(), "asciidoctor.css"); assertThat(cssFile.exists(), is(true)); }
@Test public void copycss_with_to_dir_should_copy_css_to_to_dir_directory() { Attributes attributes = attributes().linkCss(true).copyCss(true).get(); Options options = options().inPlace(false).toDir(testFolder.getRoot()) .safe(SafeMode.UNSAFE).attributes(attributes).get(); asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options); File cssFile = new File(testFolder.getRoot(), "asciidoctor.css"); assertThat(cssFile.exists(), is(true)); }
@Test public void styleSheetName_is_set_custom_stylesheet_should_be_used_() throws IOException { Attributes attributes = attributes().linkCss(true) .styleSheetName("mycustom.css").get(); Options options = options().inPlace(false).safe(SafeMode.UNSAFE) .toDir(testFolder.getRoot()).attributes(attributes).get(); asciidoctor.convertFile( classpath.getResource("rendersample.asciidoc"), options); Document doc = Jsoup.parse(new File(testFolder.getRoot(), "rendersample.html"), "UTF-8"); Elements link = doc.select("link[href]"); String attr = link.attr("href"); assertThat(attr, is("./mycustom.css")); }
@Test public void styles_dir_is_set_css_routes_should_use_it() throws IOException { Attributes attributes = attributes().stylesDir("./styles") .linkCss(true).styleSheetName("mycustom.css").get(); Options options = options().inPlace(false).safe(SafeMode.UNSAFE) .toDir(testFolder.getRoot()) .mkDirs(true) .attributes(attributes).get(); asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options); Document doc = Jsoup.parse(new File(testFolder.getRoot(), "rendersample.html"), "UTF-8"); Elements link = doc.select("link[href]"); String attr = link.attr("href"); assertThat(attr, is("./styles/mycustom.css")); }