summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/support
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2020-08-09 21:30:23 +0000
committerKarl Berry <karl@freefriends.org>2020-08-09 21:30:23 +0000
commita72bb3da0196aa7d1523552bac37e36c68fea4a7 (patch)
tree83ab2f29f7ae2b73a3c7ac79421d733c53bbfd2c /Master/texmf-dist/source/support
parent7aa248c8cb1dc61fcc302191f7fcbae48e40afe4 (diff)
texplate (9aug20)
git-svn-id: svn://tug.org/texlive/trunk@56083 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/support')
-rw-r--r--Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/TemplateProcessing.kt4
-rw-r--r--Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/model/handlers/FileReaderHandler.kt28
-rw-r--r--Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/util/HandlerUtils.kt4
-rw-r--r--Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/util/PathUtils.kt7
4 files changed, 39 insertions, 4 deletions
diff --git a/Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/TemplateProcessing.kt b/Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/TemplateProcessing.kt
index 659a0df6316..213971612a6 100644
--- a/Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/TemplateProcessing.kt
+++ b/Master/texmf-dist/source/support/texplate/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/Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/model/handlers/FileReaderHandler.kt b/Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/model/handlers/FileReaderHandler.kt
new file mode 100644
index 00000000000..4153dc48c09
--- /dev/null
+++ b/Master/texmf-dist/source/support/texplate/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/Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/util/HandlerUtils.kt b/Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/util/HandlerUtils.kt
index 44eebb2b690..9f6c65d8e65 100644
--- a/Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/util/HandlerUtils.kt
+++ b/Master/texmf-dist/source/support/texplate/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/Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/util/PathUtils.kt b/Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/util/PathUtils.kt
index 3a746035574..d0212769ec7 100644
--- a/Master/texmf-dist/source/support/texplate/main/kotlin/org/islandoftex/texplate/util/PathUtils.kt
+++ b/Master/texmf-dist/source/support/texplate/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