Skip to content

Commit ae4e59e

Browse files
committed
Fix block override
1 parent d2e4341 commit ae4e59e

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/com/potomushto/statik/template/helpers/BlockHelperRegistrar.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class BlockHelperRegistrar : HandlebarsHelperRegistrar {
1515
} ?: return@Helper options.fn(options.context) ?: ""
1616

1717
val overrideContent = blocks?.get(blockName)
18-
?.filter { it.isNotBlank() }
19-
?.takeIf { it.isNotEmpty() }
2018
?.joinToString(separator = "") { it }
2119

2220
if (overrideContent != null) {

test/kotlin/com/potomushto/statik/template/HandlebarsTemplateEngineTest.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,36 @@ class HandlebarsTemplateEngineTest {
188188
assertTrue(normalizedHtml.contains("<main>Fallback</main>"))
189189
}
190190

191+
@Test
192+
fun `block helper allows overriding with empty content`() {
193+
val layout = templatesDir.resolve("layouts/default.hbs")
194+
Files.createDirectories(layout.parent)
195+
Files.writeString(
196+
layout,
197+
"""
198+
<html>
199+
<body>
200+
{{{content}}}
201+
{{#block "footer"}}<footer>Default footer</footer>{{/block}}
202+
</body>
203+
</html>
204+
""".trimIndent()
205+
)
206+
207+
val template = """
208+
<main>{{body}}</main>
209+
{{#content "footer"}}{{/content}}
210+
""".trimIndent()
211+
212+
val html = engine.renderWithLayout(template, mapOf(
213+
"layout" to "default",
214+
"body" to "Page body"
215+
))
216+
217+
val normalizedHtml = html.normalizeQuotes()
218+
assertTrue(normalizedHtml.contains("<main>Page body</main>"))
219+
assertFalse(normalizedHtml.contains("Default footer"))
220+
}
221+
191222
private fun String.normalizeQuotes(): String = this.replace("\\\"", "\"")
192223
}

0 commit comments

Comments
 (0)