https://kotlinlang.org logo
Title
n

Nikky

03/02/2021, 4:08 PM
https://docs.fritz2.dev/StylingDSL.html this seems to be not allowed in kotlin syntax? 2 trailing lambda blocks seems to not be allowed
b

Big Chungus

03/02/2021, 4:33 PM
You're right, that's why you need to add first lambda into brackets
({})
While we're on the topic, I think styling DSL would be much more readable with some minor adjustments Consider this:
fun RenderContext.headerImage(srcUrl: String, alternativeText: String) {
    (::img.styled {
        boxShadow { flat }
        radius { large }
        width(sm = { small }, md = { smaller })
    }) {
        src(srcUrl)
        alt(alternativeText)
    }
}
VS reimagined:
fun RenderContext.headerImage(srcUrl: String, alternativeText: String) {
    img.styled({
        boxShadow { flat }
        radius { large }
        width(sm = { small }, md = { smaller })
    }) {
        src(srcUrl)
        alt(alternativeText)
    }
}
or even forget inline styles and just have optional style arguments in existing DSLs:
fun RenderContext.headerImage(srcUrl: String, alternativeText: String) {
    img(style = {
        boxShadow { flat }
        radius { large }
        width(sm = { small }, md = { smaller })
    }) {
        src(srcUrl)
        alt(alternativeText)
    }
}

// OR with builder to allow reusable styles as well
fun RenderContext.headerImage(srcUrl: String, alternativeText: String) {
    img(style = styleOf({
        boxShadow { flat }
        radius { large }
        width(sm = { small }, md = { smaller })
    })) {
        src(srcUrl)
        alt(alternativeText)
    }
}
j

Jan Weidenhaupt

03/02/2021, 7:01 PM
@Big Chungus Can you give us an issue on github for it? Than we can discuss there a possible rework of our styling API 😉 https://github.com/jwstegemann/fritz2/issues Thanks!
b

Big Chungus

03/02/2021, 7:15 PM
Sure, will do first thing tomorrow