Search in sources :

Example 1 with StructuralNode

use of org.asciidoctor.ast.StructuralNode in project drools by kiegroup.

the class ADocFEELExamplesTest method processBlock.

private void processBlock(StructuralNode block) {
    List<StructuralNode> blocks = block.getBlocks();
    for (int i = 0; i < blocks.size(); i++) {
        final StructuralNode currentBlock = blocks.get(i);
        if (currentBlock instanceof StructuralNode) {
            if (currentBlock instanceof DescriptionList) {
                DescriptionList descriptionList = (DescriptionList) currentBlock;
                for (DescriptionListEntry dle : descriptionList.getItems()) {
                    ListItem description = dle.getDescription();
                    processBlock(description);
                }
            } else if ("listing".equals(currentBlock.getContext())) {
                Block b = (Block) currentBlock;
                List<String> lines = b.getLines();
                LOG.trace("{}", lines);
                LOG.trace("{}", b.getAttributes());
                if (b.getAttribute("language", "unknown").equals("FEEL")) {
                    for (String line : lines) {
                        LOG.info("checking DOC {}", line);
                        Object FEELResult = feel.evaluate(line);
                        Assert.assertThat(line, FEELResult, Matchers.is(true));
                    }
                } else {
                    LOG.trace("This block is not FEEL true predicate snippets: {}", b);
                }
            } else {
                processBlock(currentBlock);
            }
        }
    }
}
Also used : StructuralNode(org.asciidoctor.ast.StructuralNode) DescriptionListEntry(org.asciidoctor.ast.DescriptionListEntry) DescriptionList(org.asciidoctor.ast.DescriptionList) Block(org.asciidoctor.ast.Block) DescriptionList(org.asciidoctor.ast.DescriptionList) ArrayList(java.util.ArrayList) List(java.util.List) ListItem(org.asciidoctor.ast.ListItem)

Example 2 with StructuralNode

use of org.asciidoctor.ast.StructuralNode in project jqa-core-framework by buschmais.

the class ExecutablesTest method plantuml.

@Test
void plantuml() throws Exception {
    RuleSet ruleSet = RuleSetTestHelper.readRuleSet("/executables.adoc", RuleConfiguration.DEFAULT);
    Concept concept = verifyConceptExecutable(ruleSet, "test:PlantUML", SourceExecutable.class, StructuralNode.class, "plantuml");
    StructuralNode abstractBlock = (StructuralNode) concept.getExecutable().getSource();
    String imagesDirectoryAttribute = (String) abstractBlock.getDocument().getAttributes().get(AsciidoctorFactory.ATTRIBUTE_IMAGES_OUT_DIR);
    assertThat(imagesDirectoryAttribute, notNullValue());
    File imagesOutDir = new File(imagesDirectoryAttribute);
    assertThat(imagesOutDir.exists(), equalTo(true));
    String fileName = (String) abstractBlock.getAttributes().get("target");
    assertThat(fileName, notNullValue());
    File diagramFile = new File(imagesOutDir, fileName);
    assertThat("Expected file " + diagramFile + " does not exist.", diagramFile.exists(), equalTo(true));
    String diagramMetadata = new MetadataTag(diagramFile, "plantuml").getData();
    assertThat(diagramMetadata, containsString("@startuml"));
    assertThat(diagramMetadata, containsString("@enduml"));
}
Also used : StructuralNode(org.asciidoctor.ast.StructuralNode) MetadataTag(net.sourceforge.plantuml.png.MetadataTag) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 3 with StructuralNode

use of org.asciidoctor.ast.StructuralNode in project jqa-core-framework by buschmais.

the class DocumentParser method parse.

private void parse(Collection<?> blocks, Map<String, StructuralNode> conceptBlocks, Map<String, StructuralNode> constraintBlocks, Map<String, StructuralNode> groupBlocks) {
    if (blocks != null) {
        for (Object element : blocks) {
            if (element instanceof StructuralNode && !(element instanceof DescriptionListEntry)) {
                StructuralNode block = (StructuralNode) element;
                String role = block.getRole();
                if (role != null) {
                    String id = (String) block.getAttribute(ID);
                    if (ROLE_CONCEPT.equalsIgnoreCase(role)) {
                        conceptBlocks.put(id, block);
                    } else if (ROLE_CONSTRAINT.equalsIgnoreCase(role)) {
                        constraintBlocks.put(id, block);
                    } else if (ROLE_GROUP.equalsIgnoreCase(role)) {
                        groupBlocks.put(id, block);
                    }
                }
                parse(block.getBlocks(), conceptBlocks, constraintBlocks, groupBlocks);
            } else if (element instanceof Collection<?>) {
                parse((Collection<?>) element);
            }
        }
    }
}
Also used : StructuralNode(org.asciidoctor.ast.StructuralNode) DescriptionListEntry(org.asciidoctor.ast.DescriptionListEntry) Collection(java.util.Collection) ToString(lombok.ToString)

Aggregations

StructuralNode (org.asciidoctor.ast.StructuralNode)3 DescriptionListEntry (org.asciidoctor.ast.DescriptionListEntry)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 ToString (lombok.ToString)1 MetadataTag (net.sourceforge.plantuml.png.MetadataTag)1 Block (org.asciidoctor.ast.Block)1 DescriptionList (org.asciidoctor.ast.DescriptionList)1 ListItem (org.asciidoctor.ast.ListItem)1 Test (org.junit.jupiter.api.Test)1