Skip to content

Commit

Permalink
Adds the ability to include single files as documentation (closes #303).
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Jul 2, 2024
1 parent 1366d3d commit e0440dd
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 17 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- structurizr-dsl: Adds support for element/relationship property expressions (https://github.com/structurizr/java/issues/297).
- structurizr-dsl: Adds a way to specify the implied relationships strategy by a fully qualified class name via `!impliedRelationships`.
- structurizr-dsl: Adds the ability to include single files as documentation (https://github.com/structurizr/java/issues/303).

## 2.1.4 (18th June 2024)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@ private void parse(DslContext context, Documentable documentable, File dslFile,
throw new RuntimeException("Documentation path " + path + " does not exist");
}

if (!path.isDirectory()) {
throw new RuntimeException("Documentation path " + path + " is not a directory");
}

try {
Class documentationImporterClass = context.loadClass(fullyQualifiedClassName, dslFile);
Constructor constructor = documentationImporterClass.getDeclaredConstructor();
DocumentationImporter documentationImporter = (DocumentationImporter)constructor.newInstance();
documentationImporter.importDocumentation(documentable, path);

if (!tokens.includes(FQN_INDEX)) {
if (!tokens.includes(FQN_INDEX) && path.isDirectory()) {
DefaultImageImporter imageImporter = new DefaultImageImporter();
imageImporter.importDocumentation(documentable, path);
}
Expand Down
33 changes: 30 additions & 3 deletions structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.structurizr.dsl;

import com.structurizr.Workspace;
import com.structurizr.documentation.Section;
import com.structurizr.model.*;
import com.structurizr.view.*;
import org.junit.jupiter.api.Test;
Expand All @@ -12,6 +13,7 @@
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -692,9 +694,34 @@ void test_docs() throws Exception {
Container container = softwareSystem.getContainerWithName("Container");
Component component = container.getComponentWithName("Component");

assertEquals(1, parser.getWorkspace().getDocumentation().getSections().size());
assertEquals(1, softwareSystem.getDocumentation().getSections().size());
assertEquals(1, container.getDocumentation().getSections().size());
Collection<Section> sections = parser.getWorkspace().getDocumentation().getSections();
assertEquals(1, sections.size());
assertEquals("""
## Workspace
Content...""", sections.iterator().next().getContent());

sections = softwareSystem.getDocumentation().getSections();
assertEquals(1, sections.size());
assertEquals("""
## Software System
Content...""", sections.iterator().next().getContent());

sections = container.getDocumentation().getSections();
assertEquals(1, sections.size());
assertEquals("""
## Container
Content...""", sections.iterator().next().getContent());

sections = component.getDocumentation().getSections();
assertEquals(1, sections.size());
assertEquals("""
## Component
Content...""", sections.iterator().next().getContent());

assertEquals(1, component.getDocumentation().getSections().size());
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Software System

Content...
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Container

Content...
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Component

Content...
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Workspace

Content...
8 changes: 4 additions & 4 deletions structurizr-dsl/src/test/resources/dsl/docs/workspace.dsl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
workspace {

!docs docs com.structurizr.example.ExampleDocumentationImporter
!docs docs/workspace com.structurizr.example.ExampleDocumentationImporter

model {
user = person "User"
softwareSystem = softwareSystem "Software System" {
!docs docs
!docs docs/softwaresystem

container "Container" {
!docs docs
!docs docs/softwaresystem/container

component "Component" {
!docs docs
!docs docs/softwaresystem/container/component/1.md
}
}
}
Expand Down

0 comments on commit e0440dd

Please sign in to comment.