Skip to content

Commit b989f7d

Browse files
committed
Add "lowercase" option to the replace derivation method
I'm sneaking this in without bumping the format version as this I don't expect custom repo templates to exist at this point, and this behavior is kind of unexpected in the first place
1 parent 0fcf7a7 commit b989f7d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/main/kotlin/creator/custom/derivation/ReplacePropertyDerivation.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ class ReplacePropertyDerivation(
2828
val regex: Regex,
2929
val replacement: String,
3030
val maxLength: Int?,
31+
val lowercase: Boolean,
3132
) : PreparedDerivation {
3233

3334
override fun derive(parentValues: List<Any?>): Any? {
3435
val projectName = parentValues.first() as? String
3536
?: return null
3637

37-
val sanitized = projectName.lowercase().replace(regex, replacement)
38+
var sanitized = projectName
39+
if (lowercase) {
40+
sanitized = sanitized.lowercase()
41+
}
42+
43+
sanitized = sanitized.replace(regex, replacement)
3844
if (maxLength != null && sanitized.length > maxLength) {
3945
return sanitized.substring(0, maxLength)
4046
}
@@ -88,7 +94,8 @@ class ReplacePropertyDerivation(
8894
}
8995

9096
val maxLength = (derivation.parameters["maxLength"] as? Number)?.toInt()
91-
return ReplacePropertyDerivation(regex, replacement, maxLength)
97+
val lowercase = derivation.parameters["lowercase"] as? Boolean == true
98+
return ReplacePropertyDerivation(regex, replacement, maxLength, lowercase)
9299
}
93100
}
94101
}

src/test/kotlin/creator/StringCreatorPropertyTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class StringCreatorPropertyTest : CreatorTemplateProcessorTestBase() {
7474
"parameters": {
7575
"regex": "[^a-z0-9-_]+",
7676
"replacement": "_",
77-
"maxLength": 32
77+
"maxLength": 32,
78+
"lowercase": true
7879
}
7980
}
8081
}

0 commit comments

Comments
 (0)