From 193af138fe37e837f8f2312e947a0b89c9f5c6e5 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 3 Apr 2021 20:11:52 +0100 Subject: [PATCH] Use non-breaking space in the size column This has the convenient side effect of us no longer needing to exclude the byteunits dependency from minimisation. Signed-off-by: Graham --- all/build.gradle.kts | 2 -- .../org/openrs2/archive/web/ByteUnits.kt | 9 +++++++ .../openrs2/archive/web/ByteUnitsDialect.kt | 11 ++++++++ .../archive/web/ByteUnitsExpressionFactory.kt | 25 +++++++++++++++++++ .../org/openrs2/archive/web/WebServer.kt | 1 + .../archive/templates/caches/index.html | 3 ++- .../archive/templates/caches/show.html | 3 ++- 7 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 archive/src/main/kotlin/org/openrs2/archive/web/ByteUnits.kt create mode 100644 archive/src/main/kotlin/org/openrs2/archive/web/ByteUnitsDialect.kt create mode 100644 archive/src/main/kotlin/org/openrs2/archive/web/ByteUnitsExpressionFactory.kt diff --git a/all/build.gradle.kts b/all/build.gradle.kts index ad001da0b7..f2dbc758da 100644 --- a/all/build.gradle.kts +++ b/all/build.gradle.kts @@ -27,8 +27,6 @@ tasks.shadowJar { archiveFileName.set("openrs2.jar") minimize { - // currently only invoked with reflection in Thymeleaf templates - exclude(dependency("com.jakewharton.byteunits:byteunits")) exclude(dependency("org.jetbrains.kotlin:kotlin-reflect")) } } diff --git a/archive/src/main/kotlin/org/openrs2/archive/web/ByteUnits.kt b/archive/src/main/kotlin/org/openrs2/archive/web/ByteUnits.kt new file mode 100644 index 0000000000..9255dc54b6 --- /dev/null +++ b/archive/src/main/kotlin/org/openrs2/archive/web/ByteUnits.kt @@ -0,0 +1,9 @@ +package org.openrs2.archive.web + +import com.jakewharton.byteunits.BinaryByteUnit + +public object ByteUnits { + public fun format(value: Long): String { + return BinaryByteUnit.format(value).replace(" ", "\u00A0") + } +} diff --git a/archive/src/main/kotlin/org/openrs2/archive/web/ByteUnitsDialect.kt b/archive/src/main/kotlin/org/openrs2/archive/web/ByteUnitsDialect.kt new file mode 100644 index 0000000000..a8a7f9d207 --- /dev/null +++ b/archive/src/main/kotlin/org/openrs2/archive/web/ByteUnitsDialect.kt @@ -0,0 +1,11 @@ +package org.openrs2.archive.web + +import org.thymeleaf.dialect.AbstractDialect +import org.thymeleaf.dialect.IExpressionObjectDialect +import org.thymeleaf.expression.IExpressionObjectFactory + +public object ByteUnitsDialect : AbstractDialect("byteunits"), IExpressionObjectDialect { + override fun getExpressionObjectFactory(): IExpressionObjectFactory { + return ByteUnitsExpressionFactory + } +} diff --git a/archive/src/main/kotlin/org/openrs2/archive/web/ByteUnitsExpressionFactory.kt b/archive/src/main/kotlin/org/openrs2/archive/web/ByteUnitsExpressionFactory.kt new file mode 100644 index 0000000000..36ff6892ad --- /dev/null +++ b/archive/src/main/kotlin/org/openrs2/archive/web/ByteUnitsExpressionFactory.kt @@ -0,0 +1,25 @@ +package org.openrs2.archive.web + +import org.thymeleaf.context.IExpressionContext +import org.thymeleaf.expression.IExpressionObjectFactory + +public object ByteUnitsExpressionFactory : IExpressionObjectFactory { + private const val NAME = "byteunits" + private val ALL_NAMES = setOf(NAME) + + override fun getAllExpressionObjectNames(): Set { + return ALL_NAMES + } + + override fun buildObject(context: IExpressionContext, expressionObjectName: String): Any? { + return if (expressionObjectName == NAME) { + ByteUnits + } else { + null + } + } + + override fun isCacheable(expressionObjectName: String): Boolean { + return expressionObjectName == NAME + } +} diff --git a/archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt b/archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt index dd2c67bbc8..af1b01c236 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt @@ -39,6 +39,7 @@ public class WebServer @Inject constructor( } install(Thymeleaf) { + addDialect(ByteUnitsDialect) addDialect(Java8TimeDialect()) setTemplateResolver(ClassLoaderTemplateResolver().apply { diff --git a/archive/src/main/resources/org/openrs2/archive/templates/caches/index.html b/archive/src/main/resources/org/openrs2/archive/templates/caches/index.html index 8e0b628e55..75a3df7082 100644 --- a/archive/src/main/resources/org/openrs2/archive/templates/caches/index.html +++ b/archive/src/main/resources/org/openrs2/archive/templates/caches/index.html @@ -66,7 +66,8 @@ - + Calculating... diff --git a/archive/src/main/resources/org/openrs2/archive/templates/caches/show.html b/archive/src/main/resources/org/openrs2/archive/templates/caches/show.html index e7aa05fa5e..d6aa7f601b 100644 --- a/archive/src/main/resources/org/openrs2/archive/templates/caches/show.html +++ b/archive/src/main/resources/org/openrs2/archive/templates/caches/show.html @@ -67,7 +67,8 @@ Size2 - + + Calculating...