feat: Publicize resource utility functions

This commit adds the functions to the public API
This commit is contained in:
oSumAtrIX 2023-08-25 00:04:07 +02:00
parent 47eac14f03
commit 20aff26784
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4

View file

@ -8,14 +8,15 @@ import org.w3c.dom.Node
import java.nio.file.Files
import java.nio.file.StandardCopyOption
internal object ResourceUtils {
@Suppress("MemberVisibilityCanBePrivate")
object ResourceUtils {
/**
* Merge strings. This manages [StringResource]s automatically.
*
* @param host The hosting xml resource. Needs to be a valid strings.xml resource.
*/
internal fun ResourceContext.mergeStrings(host: String) {
fun ResourceContext.mergeStrings(host: String) {
this.iterateXmlNodeChildren(host, "resources") {
// TODO: figure out why this is needed
if (!it.hasAttributes()) return@iterateXmlNodeChildren
@ -32,10 +33,11 @@ internal object ResourceUtils {
/**
* Copy resources from the current class loader to the resource directory.
*
* @param sourceResourceDirectory The source resource directory name.
* @param resources The resources to copy.
*/
internal fun ResourceContext.copyResources(sourceResourceDirectory: String, vararg resources: ResourceGroup) {
fun ResourceContext.copyResources(sourceResourceDirectory: String, vararg resources: ResourceGroup) {
val classLoader = ResourceUtils.javaClass.classLoader
val targetResourceDirectory = this["res"]
@ -55,7 +57,7 @@ internal object ResourceUtils {
* @param resourceDirectoryName The name of the directory of the resource.
* @param resources A list of resource names.
*/
internal class ResourceGroup(val resourceDirectoryName: String, vararg val resources: String)
class ResourceGroup(val resourceDirectoryName: String, vararg val resources: String)
/**
* Iterate through the children of a node by its tag.
@ -63,7 +65,7 @@ internal object ResourceUtils {
* @param targetTag The target xml node.
* @param callback The callback to call when iterating over the nodes.
*/
internal fun ResourceContext.iterateXmlNodeChildren(
fun ResourceContext.iterateXmlNodeChildren(
resource: String,
targetTag: String,
callback: (node: Node) -> Unit