4
0
Fork 0
mirror of https://github.com/Anvilcraft/modpacktools synced 2024-11-17 23:41:55 +01:00

improve CustomToml.kt

CreateModlist.kt will now read CSS from resources instead of from string in code
This commit is contained in:
LordMZTE 2020-07-27 23:20:34 +02:00
parent b9d14f7f1f
commit 1653478a92
4 changed files with 39 additions and 30 deletions

View file

@ -1,6 +1,7 @@
package ley.anvil.modpacktools.commands
import j2html.TagCreator.*
import j2html.utils.CSSMin.compressCss
import ley.anvil.addonscript.maven.ArtifactDestination
import ley.anvil.addonscript.wrapper.ASWrapper
import ley.anvil.addonscript.wrapper.MetaData
@ -12,8 +13,10 @@ import ley.anvil.modpacktools.command.ICommand
import ley.anvil.modpacktools.command.LoadCommand
import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVPrinter
import org.apache.commons.io.IOUtils
import java.io.File
import java.io.FileWriter
import java.nio.charset.StandardCharsets
@LoadCommand
object CreateModlist : ICommand {
@ -61,30 +64,7 @@ object CreateModlist : ICommand {
head(
style(
//Fancy css!
"""
a:link {
color: #ff5555;
}
a:visited {
color: #cc55cc;
}
body {
background-color: #333333;
color: #ffffff
}
.img {
width:100px;
}
td {
border: #999999 3px;
border-style: solid;
}
.description {
width: 100%
}
"""
//trim unnecessary chars
.trimIndent().filter {it != '\n'}
compressCss(IOUtils.toString(ClassLoader.getSystemResourceAsStream("commands/createmodlist/style.css"), StandardCharsets.UTF_8))
)
),
body(

View file

@ -1,17 +1,14 @@
package ley.anvil.modpacktools.util
import com.moandjiezana.toml.Toml
import kotlin.reflect.full.functions
import kotlin.reflect.jvm.isAccessible
class CustomToml : Toml() {
companion object {
@JvmStatic
fun Toml.get(key: String): Any? {
//Getting Around things being private for no reason 101 (dont look :P)
val getFunc = this::class.functions.reduce {a, b -> if(b.name == "get") b else a}
getFunc.isAccessible = true
return getFunc.call(this, key)
val getFunc by lazy {Toml::class.getFun("get")}
return getFunc?.call(this, key)
}
}

View file

@ -14,6 +14,10 @@ import java.io.FileReader
import java.io.IOException
import java.net.URI
import java.net.URL
import kotlin.reflect.KClass
import kotlin.reflect.KFunction
import kotlin.reflect.full.functions
import kotlin.reflect.jvm.isAccessible
/**
* Reads a Json File
@ -87,4 +91,12 @@ fun URL.sanitize(): URL? {
} catch(e: Exception) {
null
}
}
}
/**
* gets a function from the receiver and makes it accessible
*
* @param name the name of the function to get
* @receiver the class to get the function from
*/
fun KClass<*>.getFun(name: String): KFunction<*>? = this.functions.find {it.name == name}?.apply {isAccessible = true}

View file

@ -0,0 +1,20 @@
a:link {
color: #ff5555;
}
a:visited {
color: #cc55cc;
}
body {
background-color: #333333;
color: #ffffff
}
.img {
width:100px;
}
td {
border: #999999 3px;
border-style: solid;
}
.description {
width: 100%
}