-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor of AST traversal method (#944)
* Solve limitations in the current method used to traverse the AST. The new method does not look externally (outside of NodeProcessors) but instead injects NodeSinker into the NodeProcessors so each one decides if further traversal needs to happen. This has simplified the code notably, and removes the need for specific dependency injection. * Changes in how HTML content is generated: * Empty document no longer generated empty <h1></h1> * Empty literal no longer generated empty <pre></pre> * Sections are now wrapped around <div> elements for better organization.
- Loading branch information
1 parent
4bbd255
commit 912de34
Showing
34 changed files
with
485 additions
and
430 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
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
66 changes: 66 additions & 0 deletions
66
...octor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/NodeSinker.java
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,66 @@ | ||
package org.asciidoctor.maven.site.parser; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.apache.maven.doxia.sink.Sink; | ||
import org.asciidoctor.ast.StructuralNode; | ||
import org.asciidoctor.maven.site.parser.processors.DescriptionListNodeProcessor; | ||
import org.asciidoctor.maven.site.parser.processors.DocumentNodeProcessor; | ||
import org.asciidoctor.maven.site.parser.processors.ImageNodeProcessor; | ||
import org.asciidoctor.maven.site.parser.processors.ListItemNodeProcessor; | ||
import org.asciidoctor.maven.site.parser.processors.ListingNodeProcessor; | ||
import org.asciidoctor.maven.site.parser.processors.LiteralNodeProcessor; | ||
import org.asciidoctor.maven.site.parser.processors.NoOpNodeProcessor; | ||
import org.asciidoctor.maven.site.parser.processors.OrderedListNodeProcessor; | ||
import org.asciidoctor.maven.site.parser.processors.ParagraphNodeProcessor; | ||
import org.asciidoctor.maven.site.parser.processors.PreambleNodeProcessor; | ||
import org.asciidoctor.maven.site.parser.processors.SectionNodeProcessor; | ||
import org.asciidoctor.maven.site.parser.processors.TableNodeProcessor; | ||
import org.asciidoctor.maven.site.parser.processors.UnorderedListNodeProcessor; | ||
|
||
/** | ||
* Factory and repository for NodeProcessors. | ||
* | ||
* @author abelsromero | ||
* @since 3.1.0 | ||
*/ | ||
public class NodeSinker { | ||
|
||
private final List<NodeProcessor> nodeProcessors; | ||
|
||
private final NodeProcessor noOpProcessor; | ||
|
||
public NodeSinker(Sink sink) { | ||
nodeProcessors = Arrays.asList( | ||
new DescriptionListNodeProcessor(sink, this), | ||
new DocumentNodeProcessor(sink, this), | ||
new ImageNodeProcessor(sink, this), | ||
new ListItemNodeProcessor(sink, this), | ||
new ListingNodeProcessor(sink, this), | ||
new ListingNodeProcessor(sink, this), | ||
new LiteralNodeProcessor(sink, this), | ||
new OrderedListNodeProcessor(sink, this), | ||
new ParagraphNodeProcessor(sink, this), | ||
new PreambleNodeProcessor(sink, this), | ||
new SectionNodeProcessor(sink, this), | ||
new TableNodeProcessor(sink, this), | ||
new UnorderedListNodeProcessor(sink, this) | ||
); | ||
noOpProcessor = new NoOpNodeProcessor(sink, this); | ||
} | ||
|
||
/** | ||
* Returns first NodeProcessor that can treat the node. | ||
**/ | ||
private NodeProcessor get(StructuralNode node) { | ||
return nodeProcessors.stream() | ||
.filter(nodeProcessor -> nodeProcessor.applies(node)) | ||
.findFirst() | ||
.orElse(noOpProcessor); | ||
} | ||
|
||
public void sink(StructuralNode node) { | ||
get(node).process(node); | ||
} | ||
} |
99 changes: 0 additions & 99 deletions
99
...ctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/NodesSinker.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.