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 <gpe@openrs2.org>
Graham 4 years ago
parent 9be1a54b76
commit 193af138fe
  1. 2
      all/build.gradle.kts
  2. 9
      archive/src/main/kotlin/org/openrs2/archive/web/ByteUnits.kt
  3. 11
      archive/src/main/kotlin/org/openrs2/archive/web/ByteUnitsDialect.kt
  4. 25
      archive/src/main/kotlin/org/openrs2/archive/web/ByteUnitsExpressionFactory.kt
  5. 1
      archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt
  6. 3
      archive/src/main/resources/org/openrs2/archive/templates/caches/index.html
  7. 3
      archive/src/main/resources/org/openrs2/archive/templates/caches/show.html

@ -27,8 +27,6 @@ tasks.shadowJar {
archiveFileName.set("openrs2.jar") archiveFileName.set("openrs2.jar")
minimize { minimize {
// currently only invoked with reflection in Thymeleaf templates
exclude(dependency("com.jakewharton.byteunits:byteunits"))
exclude(dependency("org.jetbrains.kotlin:kotlin-reflect")) exclude(dependency("org.jetbrains.kotlin:kotlin-reflect"))
} }
} }

@ -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")
}
}

@ -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
}
}

@ -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<String> {
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
}
}

@ -39,6 +39,7 @@ public class WebServer @Inject constructor(
} }
install(Thymeleaf) { install(Thymeleaf) {
addDialect(ByteUnitsDialect)
addDialect(Java8TimeDialect()) addDialect(Java8TimeDialect())
setTemplateResolver(ClassLoaderTemplateResolver().apply { setTemplateResolver(ClassLoaderTemplateResolver().apply {

@ -66,7 +66,8 @@
<span <span
th:text="${cache.stats}? '(' + ${#numbers.formatPercent(cache.stats.validKeysFraction, 1, 2)} + ')'"></span> th:text="${cache.stats}? '(' + ${#numbers.formatPercent(cache.stats.validKeysFraction, 1, 2)} + ')'"></span>
</td> </td>
<td th:text="${cache.stats}? ${@com.jakewharton.byteunits.BinaryByteUnit@format(cache.stats.size)} : 'Calculating...'" <!--/*@thymesVar id="#byteunits" type="org.openrs2.archive.web.ByteUnits"*/-->
<td th:text="${cache.stats}? ${#byteunits.format(cache.stats.size)} : 'Calculating...'"
class="text-right">Calculating... class="text-right">Calculating...
</td> </td>
<td> <td>

@ -67,7 +67,8 @@
</tr> </tr>
<tr class="thead-dark"> <tr class="thead-dark">
<th>Size<sup><a href="/caches#size">2</a></sup></th> <th>Size<sup><a href="/caches#size">2</a></sup></th>
<td th:text="${cache.stats}? ${@com.jakewharton.byteunits.BinaryByteUnit@format(cache.stats.size)} : 'Calculating...'"> <!--/*@thymesVar id="#byteunits" type="org.openrs2.archive.web.ByteUnits"*/-->
<td th:text="${cache.stats}? ${#byteunits.format(cache.stats.size)} : 'Calculating...'">
Calculating... Calculating...
</td> </td>
</tr> </tr>

Loading…
Cancel
Save