Skip to content

Commit

Permalink
Merge pull request #580 from robertpanzer/fix-579-multiple-calls-incl…
Browse files Browse the repository at this point in the history
…udeprocessorinstance

Fixes #579. Allow to render more than one time with one processor ins…
  • Loading branch information
robertpanzer authored Oct 9, 2017
2 parents 0d1f568 + 47da24b commit a64e049
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args) throws
RubyHashUtil.convertMapToRubyHashWithSymbols(getRuntime(), getProcessor().getConfig())},
Block.NULL_BLOCK);
// The extension config in the Java extension is just a view on the @config member of the Ruby part
getProcessor().setConfig(new RubyHashMapDecorator((RubyHash)getInstanceVariable(MEMBER_NAME_CONFIG)));
getProcessor().updateConfig(new RubyHashMapDecorator((RubyHash)getInstanceVariable(MEMBER_NAME_CONFIG)));
} else {
// First create only the instance passing in the name
String macroName = RubyUtils.rubyToJava(getRuntime(), args[0], String.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject options) throws
RubyHashUtil.convertMapToRubyHashWithSymbols(getRuntime(), getProcessor().getConfig())},
Block.NULL_BLOCK);
// The extension config in the Java extension is just a view on the @config member of the Ruby part
getProcessor().setConfig(new RubyHashMapDecorator((RubyHash) getInstanceVariable(MEMBER_NAME_CONFIG)));
getProcessor().updateConfig(new RubyHashMapDecorator((RubyHash) getInstanceVariable(MEMBER_NAME_CONFIG)));
} else {
// First create only the instance passing in the block name
setProcessor(instantiateProcessor(new HashMap<String, Object>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject options) throws
RubyHashUtil.convertMapToRubyHashWithSymbols(getRuntime(), getProcessor().getConfig())},
Block.NULL_BLOCK);
// The extension config in the Java extension is just a view on the @config member of the Ruby part
getProcessor().setConfig(new RubyHashMapDecorator((RubyHash) getInstanceVariable(MEMBER_NAME_CONFIG)));
getProcessor().updateConfig(new RubyHashMapDecorator((RubyHash) getInstanceVariable(MEMBER_NAME_CONFIG)));
} else {
// First create only the instance passing in the block name
setProcessor(instantiateProcessor(new HashMap<String, Object>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args) throws
Block.NULL_BLOCK);
// The Ruby initialize method may have changed the config, therefore copy it back
// because the accessor is routed to the Java Processor.config
getProcessor().setConfig(new RubyHashMapDecorator((RubyHash) getInstanceVariable(MEMBER_NAME_CONFIG)));
getProcessor().updateConfig(new RubyHashMapDecorator((RubyHash) getInstanceVariable(MEMBER_NAME_CONFIG)));
} else {
String macroName = RubyUtils.rubyToJava(getRuntime(), args[0], String.class);
// First create only the instance passing in the block name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject options) throws
RubyHashUtil.convertMapToRubyHashWithSymbols(getRuntime(), getProcessor().getConfig())},
Block.NULL_BLOCK);
// The extension config in the Java extension is just a view on the @config member of the Ruby part
getProcessor().setConfig(new RubyHashMapDecorator((RubyHash) getInstanceVariable(MEMBER_NAME_CONFIG)));
getProcessor().updateConfig(new RubyHashMapDecorator((RubyHash) getInstanceVariable(MEMBER_NAME_CONFIG)));
} else {
// First create only the instance passing in the block name
setProcessor(instantiateProcessor(new HashMap<String, Object>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject options) throws
RubyHashUtil.convertMapToRubyHashWithSymbols(getRuntime(), getProcessor().getConfig())},
Block.NULL_BLOCK);
// The extension config in the Java extension is just a view on the @config member of the Ruby part
getProcessor().setConfig(new RubyHashMapDecorator((RubyHash) getInstanceVariable(MEMBER_NAME_CONFIG)));
getProcessor().updateConfig(new RubyHashMapDecorator((RubyHash) getInstanceVariable(MEMBER_NAME_CONFIG)));
} else {
// First create only the instance passing in the block name
setProcessor(instantiateProcessor(new HashMap<String, Object>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,52 @@ public void a_block_processor_instance_should_be_executed_twice()
}
}

@Test
public void a_include_processor_class_should_be_executed_twice()
throws IOException {

TestHttpServer.start(Collections.singletonMap("http://example.com/asciidoctorclass.rb", classpath.getResource("org/asciidoctor/internal/asciidoctorclass.rb")));

JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry();

javaExtensionRegistry.includeProcessor(UriIncludeProcessor.class);

for (int i = 0; i < 2; i++){
String content = asciidoctor.renderFile(
classpath.getResource("sample-with-uri-include.ad"),
options().toFile(false).get());

org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");

Element contentElement = doc.getElementsByAttributeValue("class", "language-ruby").first();

assertThat(contentElement.text(), startsWith("module AsciidoctorJ"));
}
}

@Test
public void a_include_processor_instance_should_be_executed_twice()
throws IOException {

TestHttpServer.start(Collections.singletonMap("http://example.com/asciidoctorclass.rb", classpath.getResource("org/asciidoctor/internal/asciidoctorclass.rb")));

JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry();

javaExtensionRegistry.includeProcessor(new UriIncludeProcessor(new HashMap<String, Object>()));

for (int i = 0; i < 2; i++){
String content = asciidoctor.renderFile(
classpath.getResource("sample-with-uri-include.ad"),
options().toFile(false).get());

org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");

Element contentElement = doc.getElementsByAttributeValue("class", "language-ruby").first();

assertThat(contentElement.text(), startsWith("module AsciidoctorJ"));
}
}

@Test
public void a_block_processor_should_be_executed_when_registered_listing_block_is_found_in_document() throws IOException {

Expand Down

0 comments on commit a64e049

Please sign in to comment.