本文整理汇总了Java中org.asciidoctor.Asciidoctor类的典型用法代码示例。如果您正苦于以下问题:Java Asciidoctor类的具体用法?Java Asciidoctor怎么用?Java Asciidoctor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Asciidoctor类属于org.asciidoctor包,在下文中一共展示了Asciidoctor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
private Runnable run(final List<Feature> features, final DocumentAttributes attrs, final String outputPath) {
return new Runnable() {
@Override
public void run() {
Asciidoctor asciidoctor = null;
try {
asciidoctor = Asciidoctor.Factory.create(CukedoctorPublisher.class.getClassLoader());
generateDocumentation(features, attrs, outputPath, asciidoctor);
} catch (Exception e) {
logger.println(String.format("Unexpected error on documentation generation, message %s, cause %s", e.getMessage(), e.getCause()));
e.printStackTrace();
} finally {
if (asciidoctor != null) {
asciidoctor.shutdown();
}
}
}
};
}
示例2: generateDocumentation
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
private void generateDocumentation(DocumentAttributes documentAttributes, File adocFile, Asciidoctor asciidoctor) {
OptionsBuilder ob;
ob = OptionsBuilder.options().backend(documentAttributes.getBackend());
ob.safe(SafeMode.UNSAFE);
if (allowUriRead) {
Attributes attr = new Attributes();
attr.setAllowUriRead(true);
ob.attributes(attr);
}
if ("pdf".equals(documentAttributes.getBackend())) {
asciidoctor.unregisterAllExtensions();
}
asciidoctor.convertFile(adocFile, ob);
//remove auxiliary files
if ("pdf".equals(documentAttributes.getBackend())) {
FileUtil.removeFile(adocFile.getParent() + "/" + outputFileName + "-theme.yml");
}
getLog().info("Generated documentation at: " + adocFile.getParent());
}
示例3: register
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
@Override
public void register(Asciidoctor asciidoctor) {
//null means extension is enabled (by default)
asciidoctor.javaExtensionRegistry().postprocessor(CukedoctorScriptExtension.class);
if(System.getProperty(FILTER_DISABLE_EXT_KEY) == null){
asciidoctor.javaExtensionRegistry().postprocessor(CukedoctorFilterExtension.class);
}
if(System.getProperty(MINMAX_DISABLE_EXT_KEY) == null){
asciidoctor.javaExtensionRegistry().blockMacro("minmax", CukedoctorMinMaxExtension.class);
}
if(System.getProperty(THEME_DISABLE_EXT_KEY) == null){
asciidoctor.javaExtensionRegistry().postprocessor(CukedoctorThemeExtension.class);
}
if(System.getProperty(FOOTER_DISABLE_EXT_KEY) == null){
asciidoctor.javaExtensionRegistry().postprocessor(CukedoctorFooterExtension.class);
}
if(System.getProperty(STYLE_DISABLE_EXT_KEY) == null){
asciidoctor.javaExtensionRegistry().postprocessor(CukedoctorStyleExtension.class);
}
}
示例4: renderFiles
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
private void renderFiles(List<String> inputFiles, ZipOutputStream zip) throws IOException {
Asciidoctor asciidoctor = JRubyAsciidoctor.create();
for (String inputFile : inputFiles) {
String outName = mapInFileToOutFile(inputFile, inExt, outExt);
File out = bazel ? new File(outName) : new File(tmpdir, outName);
if (!bazel) {
out.getParentFile().mkdirs();
}
File input = new File(inputFile);
Options options = createOptions(basedir != null ? basedir : input.getParentFile(), out);
asciidoctor.renderFile(input, options);
if (zip != null) {
zipFile(out, outName, zip);
}
}
}
示例5: test
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
@Test
public void test() throws IOException {
folder.create();
Asciidoctor asciidoctor = Asciidoctor.Factory.create();
asciidoctor.javaExtensionRegistry().block(
SdEditBlockProcessor.SDEDIT_BLOCK_NAME,
SdEditBlockProcessor.class);
asciidoctor.javaExtensionRegistry().blockMacro(
SdEditBlockMacroProcessor.SDEDIT_BLOCK_MACRO_NAME,
SdEditBlockMacroProcessor.class);
File baseDir = new File("src/test/resources");
File adoc = new File(baseDir, "sdinclude.adoc");
File destDir = folder.newFolder();
AttributesBuilder attributes = AttributesBuilder.attributes()
.attribute("outdir", destDir.getAbsolutePath());
OptionsBuilder options = OptionsBuilder.options().safe(SafeMode.UNSAFE)
.mkDirs(true).toDir(destDir).destinationDir(destDir)
.baseDir(baseDir).attributes(attributes);
asciidoctor.convertFile(adoc, options.asMap());
assertTrue(new File(destDir, "sdinclude.html").exists());
assertTrue(new File(destDir, "testdiagram.png").exists());
assertTrue(new File(destDir, "fromblock.svg").exists());
}
示例6: getEngine
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
private Asciidoctor getEngine(Options options) {
try {
lock.readLock().lock();
if (engine==null) {
lock.readLock().unlock();
try {
lock.writeLock().lock();
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) {
engine.requireLibrary(require);
}
}
}
LOGGER.info("Asciidoctor engine initialized.");
}
} finally {
lock.readLock().lock();
lock.writeLock().unlock();
}
}
} finally {
lock.readLock().unlock();
}
return engine;
}
示例7: processHeader
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
@Override
public void processHeader(final ParserContext context) {
Options options = getAsciiDocOptionsAndAttributes(context);
final Asciidoctor asciidoctor = getEngine(options);
DocumentHeader header = asciidoctor.readDocumentHeader(context.getFile());
Map<String, Object> contents = context.getContents();
if (header.getDocumentTitle() != null) {
contents.put("title", header.getDocumentTitle().getCombined());
}
Map<String, Object> attributes = header.getAttributes();
for (String key : attributes.keySet()) {
if (key.startsWith("jbake-")) {
Object val = attributes.get(key);
if (val!=null) {
String pKey = key.substring(6);
contents.put(pKey, val);
}
}
if (key.equals("revdate")) {
if (attributes.get(key) != null && attributes.get(key) instanceof String) {
DateFormat df = new SimpleDateFormat(context.getConfig().getString(Keys.DATE_FORMAT));
Date date = null;
try {
date = df.parse((String)attributes.get(key));
contents.put("date", date);
} catch (ParseException e) {
e.printStackTrace();
}
}
}
if (key.equals("jbake-tags")) {
if (attributes.get(key) != null && attributes.get(key) instanceof String) {
contents.put("tags", ((String) attributes.get(key)).split(","));
}
} else {
contents.put(key, attributes.get(key));
}
}
}
示例8: runAll
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
/**
* generates html and pdf documentation 'inlined' otherwise if we execute them in separated threads
* only the last thread content is rendered (cause they work on the same adoc file)
*
* @return
*/
private Runnable runAll(final List<Feature> features, final DocumentAttributes attrs, final String outputPath) {
return new Runnable() {
@Override
public void run() {
Asciidoctor asciidoctor = null;
try {
/*
* this throws: ERROR: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- jruby/java
* asciidoctor = Asciidoctor.Factory.create();
*/
asciidoctor = Asciidoctor.Factory.create(CukedoctorPublisher.class.getClassLoader());
attrs.backend("html5");
generateDocumentation(features, attrs, outputPath, asciidoctor);
attrs.backend("pdf");
generateDocumentation(features, attrs, outputPath, asciidoctor);
} catch (Exception e) {
logger.println(String.format("Unexpected error on documentation generation, message %s, cause %s", e.getMessage(), e.getCause()));
e.printStackTrace();
} finally {
if (asciidoctor != null) {
asciidoctor.shutdown();
}
}
}
};
}
示例9: generateDocumentation
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
protected synchronized void generateDocumentation(List<Feature> features, DocumentAttributes attrs, String outputPath, Asciidoctor asciidoctor) {
asciidoctor.unregisterAllExtensions();
if (!attrs.getBackend().equalsIgnoreCase("pdf")) {
new CukedoctorExtensionRegistry().register(asciidoctor);
}
CukedoctorConverter converter = Cukedoctor.instance(features, attrs);
String doc = converter.renderDocumentation();
File adocFile = FileUtil.saveFile(outputPath + "/documentation.adoc", doc);
asciidoctor.convertFile(adocFile, OptionsBuilder.options().backend(attrs.getBackend()).safe(SafeMode.UNSAFE).asMap());
}
示例10: render
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
@Override
public String render(final Template template, final Model model) {
Asciidoctor asciidoctor = Asciidoctor.Factory.create();
final String asciidoc = template.getContent().getText();
final String html = asciidoctor.convert(asciidoc, new HashMap<>());
return freemarkerRenderer.renderLayout(template, html, model);
}
示例11: getAsciidoctor
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
/**
* Return an Asciidoctor instance.
*
* Initialization is quite expensive, therefore doing it lazy.
*
* @return The Asciidoctor instance.
*/
private Asciidoctor getAsciidoctor() {
if (cachedAsciidoctor == null) {
LOGGER.debug("Loading Asciidoctor...");
cachedAsciidoctor = Asciidoctor.Factory.create();
}
return cachedAsciidoctor;
}
示例12: get
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
@GET
@Produces(MediaType.TEXT_HTML)
public String get() {
Asciidoctor asciidoctor = Asciidoctor.Factory.create();
try {
return asciidoctor.render("Hello World\n-----------", Collections.emptyMap());
} finally {
asciidoctor.shutdown();
}
}
示例13: initAsciidoctor
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
private void initAsciidoctor(ArquillianDescriptor arquillianDescriptor) {
for (final ExtensionDef extensionDef : arquillianDescriptor.getExtensions()) {
if (extensionDef.getExtensionName().startsWith("asciidoctor")) {
String gemPath = get(extensionDef.getExtensionProperties(), "gemPath", "");
Asciidoctor asciidoctor = asciidoctorMap.get(gemPath);
if(asciidoctor == null){
asciidoctor = Asciidoctor.Factory.create((File.separatorChar == '\\') ? gemPath.replaceAll("\\\\", "/") : gemPath);
asciidoctorMap.put(gemPath,asciidoctor);
}
}
}
}
示例14: register
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
@Override
public void register(final Asciidoctor asciidoctor) {
final JavaExtensionRegistry registry = asciidoctor.javaExtensionRegistry();
for (final String name : extensionNames) {
register(registry, configuration.get("extension." + name + ".class"), configuration.get("extension." + name + ".block"));
}
}
示例15: register
import org.asciidoctor.Asciidoctor; //导入依赖的package包/类
@Override
public void register(Asciidoctor asciidoctor) {
RubyExtensionRegistry rubyExtensionRegistry = asciidoctor
.rubyExtensionRegistry();
rubyExtensionRegistry
.loadClass(
this.getClass()
.getResourceAsStream(
"gherkinblockmacro.rb"))
.blockMacro("gherkin", "GherkinBlockMacroProcessor");
}