Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(config) : Allow loading file from classpath, reduce naming of… #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ internal class UploadTest(
internal fun `Data from yaml config file`(@TempDir tempDir: Path) {
val directoryConfig = sampleConfig().copy(tenant = "test1")
directoryConfig.docsDir = tempDir
writeToFile(tempDir.resolve(".text2confl.yml"), directoryConfig)
writeToFile(tempDir.resolve("text2confl.yml"), directoryConfig)

val result = mockk<List<Page>>()
every { converter.convertDir(tempDir) } returns result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlin.io.path.createTempDirectory
import kotlin.io.path.div

/**
* Holder of data that can be put to `.text2confl.yml` configuration file that is located in root directory of directory structure
* Holder of data that can be put to `text2confl.yml` configuration file that is located in root directory of directory structure
*/
data class DirectoryConfig(
val server: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.kotlin.readValue
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import io.github.oshai.kotlinlogging.KotlinLogging
import java.nio.file.Path
import kotlin.io.path.absolute
import kotlin.io.path.exists
import kotlin.io.path.isRegularFile


private val logger = KotlinLogging.logger { }

private val mapper = ObjectMapper(YAMLFactory())
.registerKotlinModule()
.setPropertyNamingStrategy(PropertyNamingStrategies.KEBAB_CASE)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)

private val CONFIG_FILE_NAMES = listOf(".text2confl.yml", ".text2confl.yaml")

private val CONFIG_FILE_NAME = "text2confl.yml"
private val CONFIG_FILE_NAMES = listOf(CONFIG_FILE_NAME)

fun readDirectoryConfig(dirOfFile: Path): DirectoryConfig {
val resolver: (String) -> Path = if (dirOfFile.isRegularFile()) {
Expand All @@ -28,11 +33,27 @@ fun readDirectoryConfig(dirOfFile: Path): DirectoryConfig {
dirOfFile::resolve
}

val directoryConfig = CONFIG_FILE_NAMES.asSequence()
var directoryConfig = CONFIG_FILE_NAMES.asSequence()
.map(resolver)
.filter { it.exists() }
.map { mapper.readValue<DirectoryConfig>(it.toFile()) }
.firstOrNull() ?: DirectoryConfig()
.firstOrNull()


if (directoryConfig == null) {
logger.debug { "No Conf File in $dirOfFile" }
logger.debug { "Try Loading conf from classpath" }

val confFile = DirectoryConfig::class.java.classLoader.getResource(CONFIG_FILE_NAME)
if (confFile != null) {
logger.debug { "Found conf File : " + confFile.file }
directoryConfig = mapper.readValue<DirectoryConfig>(confFile)
} else {
logger.debug { "Create default Directory Config" }
directoryConfig = DirectoryConfig()
}
}

directoryConfig.docsDir = if (dirOfFile.isRegularFile()) dirOfFile.absolute().parent else dirOfFile
return directoryConfig
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import kotlin.io.path.writeText
class DirectoryConfigTest {
@Test
fun `Properly read from file`(@TempDir dir: Path) {
dir.resolve(".text2confl.yml").writeText(
DirectoryConfig::class.java.getResourceAsStream("/data/.text2confl.yml")!!.reader().readText()
dir.resolve("text2confl.yml").writeText(
DirectoryConfig::class.java.getResourceAsStream("/data/text2confl.yml")!!.reader().readText()
)
val config = readDirectoryConfig(dir)

Expand Down
50 changes: 25 additions & 25 deletions docs/configuration-reference.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/storage-formats/asciidoc/diagrams.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ As link:https://docs.asciidoctor.org/diagram-extension/latest/blocks/[official A

With block or macro attributes, you can control name of generated file, file format and diagram-specific features.

Some attributes such as diagram file format can be convenient to configure not on page, but in `.text2confl.yml` file.
Some attributes such as diagram file format can be convenient to configure not on page, but in `text2confl.yml` file.

=== Inlined

Expand All @@ -42,7 +42,7 @@ include::_assets/example.adoc[tag=diagram]

By default, generated diagrams are saved in `.asciidoc` directory under documents root.

This is configurable with the following parameters in `.text2confl.yml` file
This is configurable with the following parameters in `text2confl.yml` file

[source,yaml]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/storage-formats/asciidoc/toc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Example: `+toc::[style=square]+` will generate styled TOC in Confluence
With attributes, you can control only depth of generated TOC.

WARNING: AsciiDoc by default generates TOC with only first 2 levels of sections. Use `:toclevels: N` attribute to control this.
If you want to customize it for all pages do in xref:../../configuration-reference.md[`.text2confl.yml` file]
If you want to customize it for all pages do in xref:../../configuration-reference.md[`text2confl.yml` file]

=== AsciiDoc features that are not supported
Specifying a title for the table of contents using the `toc-title` attribute is currently not supported.
40 changes: 20 additions & 20 deletions docs/storage-formats/markdown/diagrams.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ As every diagram translated to separate page attachment, there are 2 options to

By default, generated diagrams are saved in `.diagrams` directory under documents root.

This is configurable with the following parameters in `.text2confl.yml` file
This is configurable with the following parameters in `text2confl.yml` file

```yaml
markdown:
diagrams:
# parameters here
```

| name | description | default value |
|------------|---------------------------------------------------------------------------------------------------|---------------|
| `base-dir` | Base directory to store diagrams. Relative path is resolved from directory with `.text2confl.yml` | `.diagrams` |
| `temp-dir` | Use random temporary directory instead of `base-dir` | `false` |
| name | description | default value |
|------------|--------------------------------------------------------------------------------------------------|---------------|
| `base-dir` | Base directory to store diagrams. Relative path is resolved from directory with `text2confl.yml` | `.diagrams` |
| `temp-dir` | Use random temporary directory instead of `base-dir` | `false` |

## Formats

Expand All @@ -66,20 +66,20 @@ Supported code-block attributes:

#### Generator configuration

PlantUML parameters can be specified in `.text2confl.yml` file:
PlantUML parameters can be specified in `text2confl.yml` file:

```yaml {title=.text2confl.yml}
```yaml {title=text2confl.yml}
markdown:
diagrams:
plantuml:
# parameters here
```

| name | description | default value |
|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
| `enabled` | Enable PlantUML diagrams support | `true` |
| `executable` | Command name to invoke for plantuml. There is no support for invoking a jar with `java -jar`, so you need to have a wrapper script that will do it and pass all arguments down. Relative path is resolved from directory with `.text2confl.yml` | `platuml` |
| `default-format` | Format to use for generated images. Available options: `svg`, `png` | `png` |
| name | description | default value |
|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
| `enabled` | Enable PlantUML diagrams support | `true` |
| `executable` | Command name to invoke for plantuml. There is no support for invoking a jar with `java -jar`, so you need to have a wrapper script that will do it and pass all arguments down. Relative path is resolved from directory with `text2confl.yml` | `platuml` |
| `default-format` | Format to use for generated images. Available options: `svg`, `png` | `png` |

### Mermaid

Expand Down Expand Up @@ -110,9 +110,9 @@ Supported code-block attributes:

#### Generator configuration

Mermaid parameters can be specified in `.text2confl.yml` file:
Mermaid parameters can be specified in `text2confl.yml` file:

```yaml {title=.text2confl.yml}
```yaml {title=text2confl.yml}
markdown:
diagrams:
mermaid:
Expand All @@ -122,11 +122,11 @@ markdown:
| name | description | default value |
|--------------------|----------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------|
| `enabled` | Enable Mermaid diagrams support | `true` |
| `executable` | Command name to invoke for mermaid. Relative path is resolved from directory with `.text2confl.yml` | `mmdc` |
| `executable` | Command name to invoke for mermaid. Relative path is resolved from directory with `text2confl.yml` | `mmdc` |
| `default-format` | Format to use for generated images. Available options: `svg`, `png` | `png` |
| `config-file` | Mermaid configuration file to pass for every diagram invocation. Relative path is resolved from directory with `.text2confl.yml` | |
| `css-file` | Mermaid css file to pass for every diagram. Relative path is resolved from directory with `.text2confl.yml` | |
| `puppeeter-config` | Mermaid css file to pass for every diagram. Relative path is resolved from directory with `.text2confl.yml` | Value of `T2C_PUPPEETER_CONFIG` env variable |
| `config-file` | Mermaid configuration file to pass for every diagram invocation. Relative path is resolved from directory with `text2confl.yml` | |
| `css-file` | Mermaid css file to pass for every diagram. Relative path is resolved from directory with `text2confl.yml` | |
| `puppeeter-config` | Mermaid css file to pass for every diagram. Relative path is resolved from directory with `text2confl.yml` | Value of `T2C_PUPPEETER_CONFIG` env variable |

### Kroki

Expand Down Expand Up @@ -161,9 +161,9 @@ Supported code-block attributes:

#### Generator configuration

Kroki parameters can be specified in `.text2confl.yml` file:
Kroki parameters can be specified in `text2confl.yml` file:

```yaml {title=.text2confl.yml}
```yaml {title=text2confl.yml}
markdown:
diagrams:
kroki:
Expand Down
7 changes: 3 additions & 4 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ it and will put *root* pages in it.

#### Configuration file

Configuration file is `.text2confl.yml` (or `.text2confl.yaml` if you prefer this extension more) - create it in
documentation root dir.
Configuration file is `text2confl.yml` create it in documentation root dir.

For the start put the following contents:

Expand Down Expand Up @@ -85,7 +84,7 @@ because corresponding documents are present:
│   ├── markdown.md
│   └── markdown.png
├── storage-formats.md
├── .text2confl.yml
├── text2confl.yml
└── user-guide.md
```

Expand Down Expand Up @@ -178,7 +177,7 @@ docker run --rm -it -v ~/.config/text2confl:/root/.config/text2confl:ro -v $PWD:

## Adhoc upload

If you just need to upload one file, or you are fine with providing all the options via command line it is possible to skip creation of `.text2confl.yml` file:
If you just need to upload one file, or you are fine with providing all the options via command line it is possible to skip creation of `text2confl.yml` file:

```shell
text2confl upload --docs . \
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/multitenant.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ To solve this, you have 2 options:

## Configuring multi-tenancy

In `text2confl.yaml` add `tenant` parameter:
In `text2confl.yml` add `tenant` parameter:

```yaml {title="text2confl.yaml}
```yaml {title="text2confl.yml}
tenant: team-a
```

Expand Down
Loading