@Test public void snippetsAttributeFromConvertArgumentIsNotOverridden() { Options options = new Options(); options.setAttributes(new Attributes("snippets=custom projectdir=../../..")); String converted = Asciidoctor.Factory.create().convert("{snippets}", options); assertThat(converted).contains("custom"); }
@Test public void snippetsAttributeIsSet() { Options options = new Options(); options.setAttributes(new Attributes("projectdir=../../..")); String converted = Asciidoctor.Factory.create().convert("{snippets}", options); assertThat(converted) .contains("build" + File.separatorChar + "generated-snippets"); }
@Override public void init() throws ServletException { asciidoctor = Asciidoctor.Factory.create(); }
private Asciidoctor getAsciidoctor() { if (asciidoctor == null) { asciidoctor = create(); } return asciidoctor; }
public void beforeTestCreateUnsharedAsciidoctorInstance(@Observes(precedence = 5) Before before) { if (isUnsharedInstanceRequired(before.getTestClass().getJavaClass(), Asciidoctor.class) || isUnsharedInstanceRequired(before.getTestMethod(), Asciidoctor.class)) { scopedAsciidoctor.get().setUnsharedAsciidoctor( Asciidoctor.Factory.create()); } }
public void beforeTestClassCreateSharedAsciidoctorInstance(@Observes(precedence = -100) BeforeClass beforeClass) { if (isSharedInstanceRequired(beforeClass.getTestClass().getJavaClass(), Asciidoctor.class)) { scopedAsciidoctor.get().setSharedAsciidoctor( Asciidoctor.Factory.create()); } }
@Override public Asciidoctor call() throws Exception { return Asciidoctor.Factory.create(); } });
/** * Return the pre-configured {@link Asciidoctor} instance. * * @return The {@link Asciidoctor} instance. */ public static Asciidoctor getAsciidoctor() { Asciidoctor asciidoctor = Asciidoctor.Factory.create(); asciidoctor.requireLibrary(ASCIIDOCTOR_DIAGRAM); LOGGER.debug("Loaded Asciidoctor " + asciidoctor.asciidoctorVersion()); return asciidoctor; }
private Asciidoctor getAsciidoctor() { if (asciidoctor == null) { asciidoctor = create(); } return asciidoctor; }
private Asciidoctor getAsciidoctor() { if (asciidoctor == null) { asciidoctor = create(); } return asciidoctor; }
@Test public void destroyAsciidoctorInstance() { //tag::shutdown[] Asciidoctor asciidoctor = Asciidoctor.Factory.create(); asciidoctor.shutdown(); //end::shutdown[] } }
@Test public void should_not_have_gempath_in_ruby_env_when_created_with_null_gempath() { // Given: Our environment is polluted (Cannot set these env vars here, so just check that gradle has set them correctly) assertThat(System.getenv("GEM_PATH"), notNullValue()); assertThat(System.getenv("GEM_HOME"), notNullValue()); // When: A new Asciidoctor instance is created passing in a null GEM_PATH Asciidoctor asciidoctor = Asciidoctor.Factory.create((String) null); // Then: The org.jruby.JRuby instance does not see this variable Ruby rubyRuntime = JRubyRuntimeContext.get(asciidoctor); assertThat(rubyRuntime.evalScriptlet("ENV['GEM_PATH']"), is(rubyRuntime.getNil())); assertThat(rubyRuntime.evalScriptlet("ENV['GEM_HOME']"), is(rubyRuntime.getNil())); }
@Test public void ruby_postprocessor_should_be_registered() { final String rubyExtPath = classpath.getResource("ruby-extensions").getAbsolutePath(); final Asciidoctor asciidoctor = Asciidoctor.Factory.create(singletonList(rubyExtPath)); asciidoctor.rubyExtensionRegistry() .requireLibrary("xml-entity-postprocessor.rb") .postprocessor("XmlEntityPostprocessor"); String content = asciidoctor.convert( "Read §2 and it'll all be clear.", options().toFile(false).get()); assertThat(content, containsString("Read §2 and it'll all be clear.")); }
@Test public void should_have_gempath_in_ruby_env_when_created_with_default_create() { // Given: Our environment is polluted (Cannot set these env vars here, so just check that gradle has set them correctly) assertThat(System.getenv("GEM_PATH"), notNullValue()); assertThat(System.getenv("GEM_HOME"), notNullValue()); // When: A new Asciidoctor instance is created passing in no GEM_PATH Asciidoctor asciidoctor = Asciidoctor.Factory.create(); // Then: The org.jruby.JRuby instance sees this variable Ruby rubyRuntime = JRubyRuntimeContext.get(asciidoctor); assertThat(rubyRuntime.evalScriptlet("ENV['GEM_PATH']"), is(rubyRuntime.getNil())); assertThat(rubyRuntime.evalScriptlet("ENV['GEM_HOME']"), is(rubyRuntime.getNil())); }
@Test public void createAsciidoctorInstance() { //tag::create[] Asciidoctor asciidoctor = Asciidoctor.Factory.create(); //end::create[] assertThat(asciidoctor, notNullValue()); }
public static void main(String[] args) { Asciidoctor asciidoctor = Asciidoctor.Factory.create(); // <1> asciidoctor.convertFile( // <2> new File(args[0]), OptionsBuilder.options() // <3> .toFile(true) .safe(SafeMode.UNSAFE)); } }
public void beforeTestCreateUnsharedAsciidoctorInstance(@Observes(precedence = 5) Before before) { if (isUnsharedInstanceRequired(before.getTestClass().getJavaClass(), Asciidoctor.class) || isUnsharedInstanceRequired(before.getTestMethod(), Asciidoctor.class)) { scopedAsciidoctor.get().setUnsharedAsciidoctor( Asciidoctor.Factory.create()); } }
public void beforeTestClassCreateSharedAsciidoctorInstance(@Observes(precedence = -100) BeforeClass beforeClass) { if (isSharedInstanceRequired(beforeClass.getTestClass().getJavaClass(), Asciidoctor.class)) { scopedAsciidoctor.get().setSharedAsciidoctor( Asciidoctor.Factory.create()); } }
@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"); }