-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Ignore bin/ directory produced by Eclipse. * Recursively convert nested maps to ruby hashes. * Convert nested Java maps to Ruby hashes by assuming the keys are strings. * Return null if the inner document of a table cell is nil. * Add getter for @content_model variable of AbstractBlock. * Add test for content_model getter on StructuralNode. * Add test case for accessing the inner document of table cells that do not have an inner document. * Add test case for avoiding a ClassCastException when accessing the attributes of a block that was previously created by a block processor. * Formatting. * Fix a few code style problems.
- Loading branch information
1 parent
07fed40
commit 543ad9d
Showing
8 changed files
with
196 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
bin/ | ||
build/ | ||
target/ | ||
.classpath | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...org/asciidoctor/extension/WhenABlockProcessorCreatesABlockThatATreeProcessorVisits.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.asciidoctor.extension | ||
|
||
import org.asciidoctor.Asciidoctor | ||
import org.asciidoctor.OptionsBuilder | ||
import org.asciidoctor.SafeMode | ||
import org.asciidoctor.ast.Block | ||
import org.asciidoctor.ast.ContentModel | ||
import org.asciidoctor.ast.Document | ||
import org.asciidoctor.ast.StructuralNode | ||
import org.jboss.arquillian.spock.ArquillianSputnik | ||
import org.jboss.arquillian.test.api.ArquillianResource | ||
import org.junit.runner.RunWith | ||
|
||
import spock.lang.Specification | ||
|
||
@RunWith(ArquillianSputnik) | ||
class WhenABlockProcessorCreatesABlockThatATreeProcessorVisits extends Specification { | ||
|
||
@Name('tst') | ||
@Contexts(Contexts.CONTEXT_OPEN) | ||
@ContentModel(ContentModel.COMPOUND) | ||
static class BlockCreator extends BlockProcessor { | ||
|
||
@Override | ||
Object process(StructuralNode parent, Reader reader, Map<String, Object> attributes) { | ||
List<String> output = new LinkedList<>() | ||
output.add('line 1') | ||
output.add('line 2') | ||
|
||
attributes.put('name', 'value') | ||
|
||
createBlock(parent, 'open', output, attributes) | ||
} | ||
} | ||
|
||
static class BlockVisitor extends Treeprocessor { | ||
|
||
@Override | ||
Document process(Document document) { | ||
recurse(document) | ||
document | ||
} | ||
|
||
private void recurse(StructuralNode node) { | ||
// Accessing the attributes of a block that was previously created by a block processor | ||
// causes a ClassCastException in ContentNodeImpl#getAttributes since the value returned | ||
// from the AbstractNode in the JRuby AST is an instance of MapJavaProxy, which does not | ||
// conform to RubyHash. | ||
Map<String, Object> attributes = node.getAttributes() | ||
|
||
// To silence Codenarc. We must access the attributes to provoke the error. | ||
attributes = new HashMap<String, Object>(attributes) | ||
|
||
for (Block block : node.getBlocks()) { | ||
recurse(block) | ||
} | ||
} | ||
} | ||
|
||
@ArquillianResource | ||
private Asciidoctor asciidoctor | ||
|
||
private static final String DOCUMENT = ''' | ||
= Block and Tree Processor Interaction Test | ||
[tst] | ||
-- | ||
This will be ignored | ||
-- | ||
''' | ||
|
||
def "execution should not throw class cast exception"() { | ||
|
||
given: | ||
asciidoctor.javaExtensionRegistry().block(BlockCreator) | ||
asciidoctor.javaExtensionRegistry().treeprocessor(BlockVisitor) | ||
|
||
when: | ||
asciidoctor.convert(DOCUMENT, OptionsBuilder.options().safe(SafeMode.SAFE).toFile(false).headerFooter(true)) | ||
|
||
then: | ||
notThrown(ClassCastException) | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters