Skip to content

Commit

Permalink
GH-969 - Improve Application Module Canvas rendering.
Browse files Browse the repository at this point in the history
  • Loading branch information
odrotbohm committed Nov 25, 2024
1 parent cadcb31 commit 283e350
Showing 1 changed file with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Asciidoctor {

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

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

for (EventType eventType : events) {

if (!module.isExposed(eventType.getType())) {
continue;
}

var documentation = docSource.flatMap(it -> it.getDocumentation(eventType.getType()))
.map(" -- "::concat);

Expand Down Expand Up @@ -310,28 +315,6 @@ private static String toTypeAndMethod(String type, Optional<String> methodSignat
}

private String toInlineCode(ArchitecturallyEvidentType type) {

var javaType = type.getType();
var code = toInlineCode(javaType);

if (type.isEventListener()) {

if (!docSource.isPresent()) {

var referenceTypes = type.getReferenceTypes();

return "%s listening to %s".formatted( //
toInlineCode(javaType), //
toInlineCode(referenceTypes));
}

String header = "%s listening to:".formatted(withDocumentation(code, javaType) + System.lineSeparator());

return header + type.getReferenceMethods()
.map(it -> renderReferenceMethod(it, 1))
.collect(joining(System.lineSeparator()));
}

return withDocumentation(toInlineCode(type.getType()), type.getType());
}

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

var parameterType = method.getRawParameterTypes().get(0);

var typeExposed = modules.getModuleByType(parameterType)
.map(module -> module.isExposed(parameterType))
.orElse(true);

if (!typeExposed) {
return "";
}

var isAsync = it.isAsync() ? "(async) " : "";
var indent = "*".repeat(level + 1);

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

source = source.replaceAll("<p>\\s*", System.lineSeparator() + "+" + System.lineSeparator());
source = source.replace("</p>", "");

source = LINE_BREAKS.matcher(source).replaceAll(System.lineSeparator());

return source;
}

Expand Down

0 comments on commit 283e350

Please sign in to comment.