diff options
author | Norbert Preining <norbert@preining.info> | 2020-08-10 03:03:10 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-08-10 03:03:10 +0000 |
commit | 37ce19e9251a5b38afadffc633acc6b03f03cc48 (patch) | |
tree | 84d132ceef053e85a0fe70c7ad65bcea0e38c7ca /support/texplate/source | |
parent | 68df63effba2e77fb0218b91a6722821355885cd (diff) |
CTAN sync 202008100303
Diffstat (limited to 'support/texplate/source')
4 files changed, 39 insertions, 4 deletions
diff --git a/support/texplate/source/main/kotlin/org/islandoftex/texplate/TemplateProcessing.kt b/support/texplate/source/main/kotlin/org/islandoftex/texplate/TemplateProcessing.kt index 659a0df631..213971612a 100644 --- a/support/texplate/source/main/kotlin/org/islandoftex/texplate/TemplateProcessing.kt +++ b/support/texplate/source/main/kotlin/org/islandoftex/texplate/TemplateProcessing.kt @@ -207,11 +207,11 @@ class TemplateProcessing : Callable<Int> { /** * Ensures the first parameter is not null, or sets it to the second one. * - * @param <T> The type. + * @param T The type. * @param first First parameter. * @param second Second parameter. * @return Either the first or the second one. - </T> */ + */ private fun <T> ensure(first: T, second: T): T { return if (!has(first)) second else first } diff --git a/support/texplate/source/main/kotlin/org/islandoftex/texplate/model/handlers/FileReaderHandler.kt b/support/texplate/source/main/kotlin/org/islandoftex/texplate/model/handlers/FileReaderHandler.kt new file mode 100644 index 0000000000..4153dc48c0 --- /dev/null +++ b/support/texplate/source/main/kotlin/org/islandoftex/texplate/model/handlers/FileReaderHandler.kt @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: BSD-3-Clause +package org.islandoftex.texplate.model.handlers + +import java.io.File + +/** + * Implements a file reader handler. + * + * @version 1.0.3 + * @since 1.0.3 + */ +class FileReaderHandler : Handler { + + /** + * Applies the conversion to the string. + * + * @param string The string denoting a file. + * @return A list of strings from the file. + */ + override fun apply(string: String?): Any? { + return string?.let { + val file = File(string) + if (file.exists() && file.isFile) + file.readLines() + else null + } ?: emptyList<String>() + } +} diff --git a/support/texplate/source/main/kotlin/org/islandoftex/texplate/util/HandlerUtils.kt b/support/texplate/source/main/kotlin/org/islandoftex/texplate/util/HandlerUtils.kt index 44eebb2b69..9f6c65d8e6 100644 --- a/support/texplate/source/main/kotlin/org/islandoftex/texplate/util/HandlerUtils.kt +++ b/support/texplate/source/main/kotlin/org/islandoftex/texplate/util/HandlerUtils.kt @@ -3,6 +3,7 @@ package org.islandoftex.texplate.util import org.islandoftex.texplate.model.handlers.BooleanHandler import org.islandoftex.texplate.model.handlers.CSVListHandler +import org.islandoftex.texplate.model.handlers.FileReaderHandler import org.islandoftex.texplate.model.handlers.Handler /** @@ -20,6 +21,7 @@ object HandlerUtils { @JvmStatic val handlers: Map<String, Handler> = mapOf( "to-csv-list" to CSVListHandler(), - "to-boolean" to BooleanHandler() + "to-boolean" to BooleanHandler(), + "to-string-list-from-file" to FileReaderHandler() ) } diff --git a/support/texplate/source/main/kotlin/org/islandoftex/texplate/util/PathUtils.kt b/support/texplate/source/main/kotlin/org/islandoftex/texplate/util/PathUtils.kt index 3a74603557..d0212769ec 100644 --- a/support/texplate/source/main/kotlin/org/islandoftex/texplate/util/PathUtils.kt +++ b/support/texplate/source/main/kotlin/org/islandoftex/texplate/util/PathUtils.kt @@ -39,7 +39,12 @@ object PathUtils { @JvmStatic @Throws(FileNotFoundException::class) fun getTemplatePath(name: String): Path { - // the file has to be a TOML format, so we add the extension + // if the name represents an existing TOML file, we assume the user wants this + // file + if (name.endsWith(".toml") && Files.exists(Paths.get(name))) + return Paths.get(name) + // if not, then we test for the file in texplate's search path + // it has to be in TOML format and without extension val fullName = "$name.toml" // the first reference is based on the user template path resolved with the // file name |