Skip to content

Commit 0d3025d

Browse files
committed
GH-968 - Improve Application Module Canvas rendering.
1 parent cb3f503 commit 0d3025d

File tree

1 file changed

+19
-22
lines changed
  • spring-modulith-docs/src/main/java/org/springframework/modulith/docs

1 file changed

+19
-22
lines changed

spring-modulith-docs/src/main/java/org/springframework/modulith/docs/Asciidoctor.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Asciidoctor {
5353

5454
private static String PLACEHOLDER = \\_(ツ)_/¯";
5555
private static final Pattern JAVADOC_CODE = Pattern.compile("\\{\\@(link|code|literal)\\s*(.*?)\\}");
56+
private static final Pattern LINE_BREAKS = Pattern.compile("\\<\\s*br\\s*\\>");
5657
private static final Logger LOG = LoggerFactory.getLogger(Asciidoctor.class);
5758

5859
private static final Optional<DocumentationSource> DOC_SOURCE = getSpringModulithDocsSource()
@@ -190,6 +191,10 @@ public String renderPublishedEvents(ApplicationModule module) {
190191

191192
for (EventType eventType : events) {
192193

194+
if (!module.isExposed(eventType.getType())) {
195+
continue;
196+
}
197+
193198
var documentation = docSource.flatMap(it -> it.getDocumentation(eventType.getType()))
194199
.map(" -- "::concat);
195200

@@ -310,28 +315,6 @@ private static String toTypeAndMethod(String type, Optional<String> methodSignat
310315
}
311316

312317
private String toInlineCode(ArchitecturallyEvidentType type) {
313-
314-
var javaType = type.getType();
315-
var code = toInlineCode(javaType);
316-
317-
if (type.isEventListener()) {
318-
319-
if (!docSource.isPresent()) {
320-
321-
var referenceTypes = type.getReferenceTypes();
322-
323-
return "%s listening to %s".formatted( //
324-
toInlineCode(javaType), //
325-
toInlineCode(referenceTypes));
326-
}
327-
328-
String header = "%s listening to:".formatted(withDocumentation(code, javaType) + System.lineSeparator());
329-
330-
return header + type.getReferenceMethods()
331-
.map(it -> renderReferenceMethod(it, 1))
332-
.collect(joining(System.lineSeparator()));
333-
}
334-
335318
return withDocumentation(toInlineCode(type.getType()), type.getType());
336319
}
337320

@@ -342,6 +325,15 @@ private String renderReferenceMethod(ReferenceMethod it, int level) {
342325
() -> "Method %s must have at least one parameter!".formatted(method));
343326

344327
var parameterType = method.getRawParameterTypes().get(0);
328+
329+
var typeExposed = modules.getModuleByType(parameterType)
330+
.map(module -> module.isExposed(parameterType))
331+
.orElse(true);
332+
333+
if (!typeExposed) {
334+
return "";
335+
}
336+
345337
var isAsync = it.isAsync() ? "(async) " : "";
346338
var indent = "*".repeat(level + 1);
347339

@@ -389,6 +381,11 @@ public String toAsciidoctor(String source) {
389381
source = source.replace(matcher.group(), toInlineCode(type));
390382
}
391383

384+
source = source.replaceAll("<p>\\s*", System.lineSeparator() + "+" + System.lineSeparator());
385+
source = source.replace("</p>", "");
386+
387+
source = LINE_BREAKS.matcher(source).replaceAll(System.lineSeparator());
388+
392389
return source;
393390
}
394391

0 commit comments

Comments
 (0)