hay-kot / scaffold

A cookie cutter alternative with in-project scaffolding for generating components, controllers, or other common code patterns.
https://hay-kot.github.io/scaffold/
MIT License
51 stars 5 forks source link

question: conditional template injection #152

Closed anthonychung14 closed 3 months ago

anthonychung14 commented 3 months ago

I'd like to run an injection only if an input resolves to true. is there a way I can do this now?

hay-kot commented 3 months ago

I don't think this is explicitly supported, I think this would work if you did something like this?

inject:
  - name: "add role to site.yaml"
    path: site.yaml
    at: "# $Scaffold.role_name"
    template: {{ if .Scaffold.some_value }} whatever thing you want {{ end }}

If that doesn't work, I can add this so that when the template evaluates to empty or whitespace we can ignore the inject.

anthonychung14 commented 3 months ago

ahh I see the light. I was originally looking into go generate for my use case, but it looks like this is powered by the text/template. docs are clear on how to do the thing. thank you!