-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(core): Custom files per alias entries about their usage #9 - Custom usage files for alias entries, with that the usage of the script can be detailed within code format as it will be rendered as a bash code
- Loading branch information
1 parent
4383d5f
commit 61db1a7
Showing
20 changed files
with
287 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
== Aliases | ||
|
||
=== hello | ||
[source, bash] | ||
---- | ||
jbang hello <scriptOrFile> | ||
---- | ||
|
||
[sidebar] | ||
Script that says hello back for each argument | ||
|
||
[source, bash] | ||
---- | ||
This is a usage file, that will be rendered below the `hello` alias entry. | ||
!%$&@ So you want to use this script? !%$&@ | ||
< Let me show you how you can use it. > | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This is a usage file, that will be rendered below the `hello` alias entry. | ||
|
||
!%$&@ So you want to use this script? !%$&@ | ||
|
||
< Let me show you how you can use it. > |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ent-generator-core/src/main/java/org/rodnansol/document/DocumentGenerationProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.rodnansol.document; | ||
|
||
import io.smallrye.config.ConfigMapping; | ||
|
||
/** | ||
* Document generation properties. | ||
* | ||
* @author nandorholozsnyak | ||
* @since 0.2.0 | ||
*/ | ||
@ConfigMapping(prefix = "app.document") | ||
public interface DocumentGenerationProperties { | ||
|
||
/** | ||
* Get the current working directory. | ||
*/ | ||
String currentWorkingDirectory(); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...-document-generator-core/src/main/java/org/rodnansol/handlebars/CustomUsageConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.rodnansol.handlebars; | ||
|
||
/** | ||
* Constants for the custom usage sections. | ||
* | ||
* @author nandorholozsnyak | ||
* @since 0.2.0 | ||
*/ | ||
class CustomUsageConstants { | ||
|
||
public static final String EXTENSION = ".txt"; | ||
|
||
private CustomUsageConstants(){} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...cument-generator-core/src/main/java/org/rodnansol/handlebars/CustomUsageRenderHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.rodnansol.handlebars; | ||
|
||
import com.github.jknack.handlebars.Helper; | ||
import com.github.jknack.handlebars.Options; | ||
import org.rodnansol.document.DocumentGenerationProperties; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* Helper that renders the file at the given path built by the current working directory and by the value of the context to the document. | ||
* <p> | ||
* Usage: | ||
* {@code | ||
* {{#render_custom_usage alias-name}}{{/render_custom_usage}} | ||
* } | ||
* | ||
* @author nandorholozsnyak | ||
* @since 0.2.0 | ||
*/ | ||
class CustomUsageRenderHelper implements Helper<String> { | ||
|
||
private final DocumentGenerationProperties documentGenerationProperties; | ||
|
||
public CustomUsageRenderHelper(DocumentGenerationProperties documentGenerationProperties) { | ||
this.documentGenerationProperties = documentGenerationProperties; | ||
} | ||
|
||
@Override | ||
public Object apply(String context, Options options) throws IOException { | ||
byte[] bytes = Files.readAllBytes(Path.of(getPath(context))); | ||
return new String(bytes, StandardCharsets.UTF_8); | ||
} | ||
|
||
private String getPath(String context) { | ||
return documentGenerationProperties.currentWorkingDirectory() + "/" + context + CustomUsageConstants.EXTENSION; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...-document-generator-core/src/main/java/org/rodnansol/handlebars/HasCustomUsageHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.rodnansol.handlebars; | ||
|
||
import com.github.jknack.handlebars.Helper; | ||
import com.github.jknack.handlebars.Options; | ||
import org.rodnansol.document.DocumentGenerationProperties; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* Helper that checks if a file exits at the given path built by the current working directory and by the value of the context. | ||
* <p> | ||
* Usage: | ||
* {@code | ||
* {{# has_custom_usage alias-name}} | ||
* {{/has_custom_usage}} | ||
* } | ||
* | ||
* @author nandorholozsnyak | ||
* @since 0.2.0 | ||
*/ | ||
class HasCustomUsageHelper implements Helper<String> { | ||
|
||
private final DocumentGenerationProperties documentGenerationProperties; | ||
|
||
public HasCustomUsageHelper(DocumentGenerationProperties documentGenerationProperties) { | ||
this.documentGenerationProperties = documentGenerationProperties; | ||
} | ||
|
||
@Override | ||
public Object apply(String context, Options options) throws IOException { | ||
return Files.exists(Path.of(getPath(context))) ? options.fn(context) : options.inverse(context); | ||
} | ||
|
||
private String getPath(String context) { | ||
return documentGenerationProperties.currentWorkingDirectory() + "/" + context + CustomUsageConstants.EXTENSION; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.