This project would like to give you more custom options for your AsciiDoc files, and it would like to extend your experience with new features.
The project is built with Java 11 and with the latest (2.5.7) AsciidoctorJ dependency.
The following new macros are available by this project:
-
JavaSourceIncludeProcessor
: With the help of this include macro you can include specific sections (fields, methods) of your Java source code, and you do not have to pollute your source code with tag markers.
Usage:
include::javasource[source='<path-to-java-source>', (1)
method='<name-of-the-method-to-extract>', field='<name-of-the-field-to-extract>', (2)
withJavaDoc='true|false', (3)
spaceSize='<space-size>' (4)
lineLength='<maximum-line-length>' (5)
]
-
Path to the source code.
-
The name of the method or field to be extracted.
-
If the JavaDoc is needed, specify it with true
-
If the final extracted code should be reformatted with different space indentation size specify it.
-
If the source code is too long with that breaks can be applied - Unfortunately the Roaster dependency’s formatter is not working properly, so use it with caution.
A few examples
class UserService {
private static final Logger LOGGER = LoggerFactory.getLogger(UserService.class);
private final UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
/**
* Creates a new user based on the incoming stuff.
*/
public final User createUser(String username, String password) {
LOGGER.info("Creating new user with username:[{}]", username);
userRepository.save(new User(username, password));
}
protected void deleteUser(String username) {
LOGGER.info("Deleting user with username:[{}]", username);
userRepository.deleteByUsername(username);
}
/**
* Disables the incoming user.
* @param user user to disable.
*/
void disableUser(User user) {
LOGGER.info("Disabling user with username:[{}]", user.username);
if (user.enabled == true) {
user.enabled = false;
userRepository.save(user);
} else {
logUnableToDisableUser();
}
}
private static void logUnableToDisableUser() {
LOGGER.info("Unable to disable disabled user");
}
}
include::javasource[source={docdir}/UserService.java,method='disableUser']
include::javasource[source={docdir}/UserService.java,method='disableUser',withJavaDoc='true']
include::javasource[source={docdir}/UserService.java,field='LOGGER']
Check the following file for a full showcase.
📎
|
Because the requested source code is being formatted with Roaster’s Eclipse formatter it can happen that the final code does not look the same as the original. |
In case you are using the AsciidoctorJ Maven plugin the setup is the following:
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>${asciidoctor-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.rodnansol</groupId>
<artifactId>asciidoctorj-extensions</artifactId>
<version>${asciidoctorj-extensions.version}</version>
</dependency>
</dependencies>
</plugin>
If you are using the AsciiDoc IDEA plugin and you would like to utilize the extension in your IDE too you have 2 options
Run the following script in your project’s root folder, and it will create a hidden folder called .asciidoctor/lib
and it will place the shaded JAR into this folder. It will extend your .gitignore
file to make sure you are not committing any binary to your remote repository.
``
This method requires you to search the IDEA’s plugin folder and place the shaded jar into this.
For example, if you installed your IDEA with Toolbox on Linux then the path can be the following: ~/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/223.8214.52.plugins/asciidoctor-intellij-plugin/lib/
#!/bin/bash
wget https://repo1.maven.org/maven2/org/rodnansol/asciidoctorj-extensions/maven-metadata.xml -O /tmp/asciidoctorj-extensions-maven-metadata.xml -q
LATEST_VERSION=($(grep -oP '(?<=latest>)[^<]+' "/tmp/asciidoctorj-extensions-maven-metadata.xml"))
JAR_FILE=.asciidoctor/lib/asciidoctorj-extensions-${LATEST_VERSION}-shaded.jar
wget https://repo1.maven.org/maven2/org/rodnansol/asciidoctorj-extensions/${LATEST_VERSION}/asciidoctorj-extensions-${LATEST_VERSION}-shaded.jar -O asciidoctorj-extensions-${LATEST_VERSION}-shaded.jar