File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
src/com/potomushto/statik/template/helpers
test/kotlin/com/potomushto/statik/template Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments