if (engine == null) { LOGGER.info("Initializing Asciidoctor engine..."); if (options.map().containsKey(OPT_GEM_PATH)) { engine = Asciidoctor.Factory.create(String.valueOf(options.map().get(OPT_GEM_PATH))); } else { engine = Asciidoctor.Factory.create(); if (options.map().containsKey(OPT_REQUIRES)) { String[] requires = String.valueOf(options.map().get(OPT_REQUIRES)).split(","); if (requires.length != 0) { for (String require : requires) {
@Test public void snippetsAttributeFromDocumentPreambleIsNotOverridden() { Options options = new Options(); options.setAttributes(new Attributes("projectdir=../../..")); String converted = Asciidoctor.Factory.create() .convert(":snippets: custom\n{snippets}", options); assertThat(converted).contains("custom"); }
/** * Sets doctype option. * * @param docType * value. * @return this instance. */ public OptionsBuilder docType(String docType) { this.options.setDocType(docType); return this; }
private File configurePdfOutput() { this.options.setBackend("pdf"); File output = new File("build/output.pdf"); this.options.setToFile(output.getAbsolutePath()); return output; }
private Options getAsciiDocOptionsAndAttributes(ParserContext context) { JBakeConfiguration config = context.getConfig(); List<String> asciidoctorAttributes = config.getAsciidoctorAttributes(); final AttributesBuilder attributes = attributes(asciidoctorAttributes.toArray(new String[asciidoctorAttributes.size()])); if (config.getExportAsciidoctorAttributes()) { final String prefix = config.getAttributesExportPrefixForAsciidoctor(); for (final Iterator<String> it = config.getKeys(); it.hasNext(); ) { final String key = it.next(); if (!key.startsWith("asciidoctor")) { attributes.attribute(prefix + key.replace(".", "_"), config.get(key)); } } } final List<String> optionsSubset = config.getAsciidoctorOptionKeys(); final Options options = options().attributes(attributes.get()).get(); for (final String optionKey : optionsSubset) { Object optionValue = config.getAsciidoctorOption(optionKey); if (optionKey.equals(Options.TEMPLATE_DIRS)) { List<String> dirs = getAsList(optionValue); if (!dirs.isEmpty()) { options.setTemplateDirs(String.valueOf(dirs)); } } else { options.setOption(optionKey, optionValue); } } options.setBaseDir(context.getFile().getParentFile().getAbsolutePath()); options.setSafe(UNSAFE); return options; }
options = new Options(); if (to_file != null) options.setToFile(to_file); if (in_place != null) options.setInPlace(in_place); if (backend != null) options.setBackend(backend); if (base_dir != null) options.setBaseDir(base_dir); if (compact != null) options.setCompact(compact); if (destination_dir != null) options.setDestinationDir(destination_dir); if (doctype != null) options.setDocType(doctype); if (safe != null) options.setSafe(safe); if (header_footer != null) options.setHeaderFooter(header_footer); if (parse_header_only != null) options.setParseHeaderOnly(parse_header_only); if (mk_dirs != null) options.setMkDirs(mk_dirs); if (eruby != null) options.setEruby(eruby); if (template_cache != null) options.setTemplateCache(template_cache); if (template_dirs != null) options.setTemplateDirs(template_dirs);
private Options getOptions() { Options options = new Options(); options.setCompact(true); options.setDocType("inline"); Attributes attributes = new Attributes(); attributes.setExperimental(true); attributes.setDataUri(true); options.setAttributes(attributes); return options; } }
@Before public void setUp() { this.options.setAttributes(getAttributes()); }
private List<InputStream> convertToInputStreams(List<File> source) throws IOException { List<InputStream> inputStreams = new ArrayList<>(); Asciidoctor asciidoctor = Factory.create(); ExtensionGroup group = asciidoctor.createGroup(); Preprocessor preprocessor = new Preprocessor(); group.preprocessor(preprocessor); Options options = new Options(); options.setToFile(false); options.setSafe(SafeMode.UNSAFE); group.register(); for (File file : source) { inputStreams.add(processSingleFile(file, asciidoctor, group, preprocessor, options)); } return inputStreams; }
/** * Sets a custom or unlisted option. * * @param option * name. * @param value * for given option. * @return this instance. */ public OptionsBuilder option(String option, Object value) { this.options.setOption(option, value); return this; }
/** * Sets template directory. * * @param templateDir * directory where templates are stored. * @return this instance. */ public OptionsBuilder templateDir(File templateDir) { this.options.setTemplateDirs(templateDir.getAbsolutePath()); return this; }
/** * Sets base dir for working directory. * * @param baseDir * working directory. * @return this instance. */ public OptionsBuilder baseDir(File baseDir) { this.options.setBaseDir(baseDir.getAbsolutePath()); return this; }
/** * Sets to file value. This toggles writing output to a file or returning output * as a string. If writing to a string, the header and footer are omitted from the * output by default. * * @param toFile * <code>true</code> to write output to a file, <code>false</code> * to write output to a string. * @return this instance. */ public OptionsBuilder toFile(boolean toFile) { this.options.setToFile(toFile); return this; }
/** * Compact the output removing blank lines. * * @param compact * value. * @return this instance. */ public OptionsBuilder compact(boolean compact) { this.options.setCompact(compact); return this; }
/** * Sets the safe mode. * @param safeMode to run asciidoctor. * @return this instance. */ public OptionsBuilder safe(SafeMode safeMode) { this.options.setSafe(safeMode); return this; }
private Options getOptions() { Options options = new Options(); options.setCompact(true); options.setDocType("inline"); Attributes attributes = new Attributes(); attributes.setExperimental(true); attributes.setDataUri(true); options.setAttributes(attributes); return options; } }
private Options getAsciiDocOptionsAndAttributes(ParserContext context) { JBakeConfiguration config = context.getConfig(); List<String> asciidoctorAttributes = config.getAsciidoctorAttributes(); final AttributesBuilder attributes = attributes(asciidoctorAttributes.toArray(new String[asciidoctorAttributes.size()])); if (config.getExportAsciidoctorAttributes()) { final String prefix = config.getAttributesExportPrefixForAsciidoctor(); for (final Iterator<String> it = config.getKeys(); it.hasNext(); ) { final String key = it.next(); if (!key.startsWith("asciidoctor")) { attributes.attribute(prefix + key.replace(".", "_"), config.get(key)); } } } final List<String> optionsSubset = config.getAsciidoctorOptionKeys(); final Options options = options().attributes(attributes.get()).get(); for (final String optionKey : optionsSubset) { Object optionValue = config.getAsciidoctorOption(optionKey); if (optionKey.equals(Options.TEMPLATE_DIRS)) { List<String> dirs = getAsList(optionValue); if (!dirs.isEmpty()) { options.setTemplateDirs(String.valueOf(dirs)); } } else { options.setOption(optionKey, optionValue); } } options.setBaseDir(context.getFile().getParentFile().getAbsolutePath()); options.setSafe(UNSAFE); return options; }
@Test public void operationWithParameterizedName() throws Exception { Attributes attributes = getAttributes(); attributes.setAttribute("name", "some"); this.options.setAttributes(attributes); String result = this.asciidoctor.convert( "operation::{name}-operation[snippets='curl-request']", this.options); assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-simple")); }
/** * Sets a custom or unlisted option. * @param option name. * @param value for given option. * @return this instance. */ public OptionsBuilder option(String option, Object value) { this.options.setOption(option, value); return this; }