Skip to content

DSL Support #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Dogacel opened this issue Aug 10, 2024 · 2 comments
Open

DSL Support #42

Dogacel opened this issue Aug 10, 2024 · 2 comments

Comments

@Dogacel
Copy link

Dogacel commented Aug 10, 2024

I think it makes sense to optionally generate DSLs as well. I was thinking about storing my k8s configuration on kotlin DSL, found about this codegen however it only generates kotlin, halfway there.

@pwall567
Copy link
Owner

I don't what DSL you're referring to here. The code generator creates Kotlin and Java output, and it also produces Typescript interfaces (although with much more limited feature coverage).

But the output is all controlled by Mustache templates, so if you want to generate some other form of code you can provide your own templates.

This is not well documented, but if you create a template and parse it using the above-linked Mustache processor, you can then supply it to the code generator:

        val codeGenerator = CodeGenerator()
        codeGenerator.template = customTemplate

The "context object" for the template is a Target object, and you may need to investigate the source of this class, or examine the existing templates (in src/main/resources) to discover the properties you need to take part in template expansion.

I'm sorry if this is not very helpful, but your requirement is not what I had considered a primary use case for the code generator.

@Dogacel
Copy link
Author

Dogacel commented Aug 13, 2024

@pwall567

https://kotlinlang.org/docs/type-safe-builders.html

This is what I meant.

    html {
        head {
            title {+"XML encoding with Kotlin"}
        }
        body {
            h1 {+"XML encoding with Kotlin"}
            p  {+"this format can be used as an alternative markup to XML"}

            // an element with attributes and text content
            a(href = "https://kotlinlang.org") {+"Kotlin"}

            // mixed content
            p {
                +"This is some"
                b {+"mixed"}
                +"text. For more see the"
                a(href = "https://kotlinlang.org") {+"Kotlin"}
                +"project"
            }
            p {+"some text"}

            // content generated by
            p {
                for (arg in args)
                    +arg
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants