Skip to content

Commit e2a9414

Browse files
authored
feat(template): add ICON_BUILDER constant to TemplateConstants.Fragment (#327)
* feat(template): add ICON_BUILDER constant to TemplateConstants.Fragment Resolves #258. Adds `const val ICON_BUILDER = "icon_builder"` to the `Fragment` object in `TemplateConstants.kt` and updates the two test sites that were using the hardcoded literal as a fragments-map key to reference the new constant: - TemplateEmitterTest.kt (fragments = mapOf(...)) - PlaceholderResolverTest.kt (fragments = mapOf(...)) Docs/TOML occurrences of "icon_builder" are left untouched: those are user-facing TOML keys or placeholder strings inside templates (e.g. ${template:icon_builder}), not Kotlin fragment-lookup references. * feat(template): also use Fragment.ICON_BUILDER in TemplateEditorSchema Per @rafaeltonholo review on #327 - replaces the remaining "icon_builder" string literals in the website's TemplateEditorSchema.kt with TemplateConstants.Fragment.ICON_BUILDER, keeping the website in lockstep with the core Fragment constant rename. Only the two fragment-map usages were changed; the definitions.imports key stays as a TOML schema string since it's a user-facing TOML key, not a Fragment reference. Relying on CI for detekt/build verification - local JVM toolchain not wired up on this machine. --------- Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
1 parent e0d963d commit e2a9414

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

svg-to-compose/src/commonMain/kotlin/dev/tonholo/s2c/emitter/template/TemplateConstants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ object TemplateConstants {
2323
object Fragment {
2424
const val PATH_BUILDER = "path_builder"
2525
const val GROUP_BUILDER = "group_builder"
26+
const val ICON_BUILDER = "icon_builder"
2627
const val CHUNK_FUNCTION_NAME = "chunk_function_name"
2728
const val CHUNK_FUNCTION_DEFINITION = "chunk_function_definition"
2829
}

svg-to-compose/src/commonTest/kotlin/dev/tonholo/s2c/emitter/template/TemplateEmitterTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class TemplateEmitterTest {
9393
$$" ${template:icon_builder} {$\n ${icon:body}$\n }$\n}",
9494
),
9595
fragments = mapOf(
96-
"icon_builder" to $$"${def:builder}(name = ${icon:name})",
96+
TemplateConstants.Fragment.ICON_BUILDER to $$"${def:builder}(name = ${icon:name})",
9797
),
9898
)
9999
val fallback = ImageVectorEmitter(noOpLogger, formatConfig)

svg-to-compose/src/commonTest/kotlin/dev/tonholo/s2c/emitter/template/resolver/PlaceholderResolverTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.tonholo.s2c.emitter.template.resolver
22

3+
import dev.tonholo.s2c.emitter.template.TemplateConstants
34
import dev.tonholo.s2c.emitter.template.TemplateContext
45
import kotlin.test.Test
56
import kotlin.test.assertContains
@@ -66,7 +67,7 @@ class PlaceholderResolverTest {
6667
fun `resolves template namespace with fragment`() {
6768
val ctx = createContext(
6869
iconVars = mapOf("name" to "TestIcon"),
69-
fragments = mapOf("icon_builder" to $$"Builder(name = ${icon:name})"),
70+
fragments = mapOf(TemplateConstants.Fragment.ICON_BUILDER to $$"Builder(name = ${icon:name})"),
7071
)
7172
val result = PlaceholderResolver.resolve($$"${template:icon_builder}", ctx)
7273
assertEquals("Builder(name = TestIcon)", result)

website/site/src/jsMain/kotlin/dev/tonholo/s2c/website/components/organisms/playground/template/TemplateEditorSchema.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private fun buildIconTemplateInsertValue(): String {
206206
val body = iconPlaceholder(TemplateConstants.IconVar.BODY)
207207
val builder = placeholder(
208208
TemplateConstants.Namespace.TEMPLATE,
209-
"icon_builder",
209+
TemplateConstants.Fragment.ICON_BUILDER,
210210
)
211211

212212
// language=TOML
@@ -255,9 +255,9 @@ private fun buildFragmentKeys(): List<TomlKeyInfo> {
255255
insertValue = "${frag.GROUP_BUILDER} = \"group(rotate = $groupRotate)\"",
256256
),
257257
TomlKeyInfo(
258-
key = "icon_builder",
258+
key = frag.ICON_BUILDER,
259259
description = $$"Icon builder fragment. Placeholders: ${$${ns.DEFINITIONS}:*}, ${$${ns.ICON}:*}.",
260-
insertValue = "icon_builder = \"$defBuilder(name = \\\"$iconName\\\")\"",
260+
insertValue = "${frag.ICON_BUILDER} = \"$defBuilder(name = \\\"$iconName\\\")\"",
261261
),
262262
TomlKeyInfo(
263263
key = frag.CHUNK_FUNCTION_NAME,

0 commit comments

Comments
 (0)