Skip to content
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

Possibility of "if" in templates? #5

Closed
buehler opened this issue Mar 16, 2016 · 6 comments
Closed

Possibility of "if" in templates? #5

buehler opened this issue Mar 16, 2016 · 6 comments
Milestone

Comments

@buehler
Copy link

buehler commented Mar 16, 2016

Hey @tmrts

I'm really tempted to use boilr, but one critical feature is missing. I need the possibility to create a condition in the questions. Nothing very complicated, but still. I had the idea of implementing it on my own, but there are so many libraries and tools out there, I didn't want to make "just another templater".

So I found your boilr.

Do you think it would be possible to add an if condition to the project.json?

Like:

{
    "AppName": "Demo",
    "ExpertMode": [
        true,
        false
    ],
    "FolderName": {
        "value": "Demo",
        "condition": "ExpertMode"
    }
}

Only ask the question about the FolderName if the answer to ExpertMode is evaluated truthly.

Cheers
Chris

@tmrts
Copy link
Owner

tmrts commented Mar 16, 2016

Chris thank you for trying out boilr.

What you need is already implemented and can be used as such:

{
    "ExpertMode": false,
}

Default value of ExpertMode will be false and the user will see a boolean prompt for true/false.

In template usage:

{{ If ExpertMode }}
....
{{ end }}

For more information please take a look at the wiki pages.
It explains the templating features of boilr.

For creating templates check this page.

@buehler
Copy link
Author

buehler commented Mar 16, 2016

There is a little misunderstanding 😉

I don't want to use {{ If ExpertMode }} in the templates. Its the initial questioning of the user that I'm interested in.

So if I define my condition stuff, the user gets asked about this question only if the condition is true.

project.json:

{
    "AppName": "Demo",
    "ExpertMode": false,
    "FolderName": {
        "value": "Demo",
        "condition": "ExpertMode"
    }
}

Example workflows:
1.)

  • boilr template use demo .
  • User gets asked: Please choose a value for "AppName"
  • User gets asked: Please choose a value for "ExpertMode"
  • User selects "false".
  • Template engine does its magic.

2.)

  • boilr template use demo .
  • User gets asked: Please choose a value for "AppName"
  • User gets asked: Please choose a value for "ExpertMode"
  • User selects "true".
  • User gets asked: Please choose a value for "FolderName"
  • Template engine does its magic.

Cheers

@tmrts
Copy link
Owner

tmrts commented Mar 16, 2016

Gotcha I see what you mean 👍

I can make an enhancement as such:

{
    "AppName": "Demo",
    "ExpertMode": {
        "FolderName": "Demo",
        "RepoNumber: 5,
    }
}

The workflow:

  1. Prompt for AppName
  2. Confirmation prompt for ExpertMode
  3. If ExpertMode enabled, Prompt for the fields inside. Else, use default values of those.

I'll stew on this a bit more to get a good idea of pros/cons, but the feature is a good one and I'll work on it. Final usage might be a bit different

Thanks for bringing this up, I was thinking about this earlier, but got sidetracked and forgot.

@buehler
Copy link
Author

buehler commented Mar 16, 2016

Cool! 👍
Yea that's exactly what I meant. This would be awesome!

And to be a little "challenging": in the same changes, would it be possible to add variables to the default values? i.e. run the default variables through go-templates first.

Like:

"AppName": "Demo",
"FolderName": "{{AppName}}"

If this is possible (and easy) too, it would be as awesome as any other template engine! 😉

Well, maybe I'll find the time to implement this one on my own and send you a PR, we'll see.

@tmrts
Copy link
Owner

tmrts commented Mar 16, 2016

Thanks for another good suggestion. I'll see what I can do, but It'd be a good idea to move this suggestion to a new issue just so it doesn't get lost.

I welcome any contribution, however at this stage adoption and feedback is more important to me. So, you are already making big contributions thank you 👍 .

@hoangmirs
Copy link

Hi @tmrts
After the changes in 7b973fc, can I use the following project configuration?

{
    "AppName": "Demo",
    "ExpertMode": {
        "FolderName": "Demo",
        "RepoNumber: 5,
    }
}

I tried but it did not work, could you tell me how to use it?
Thank you

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

No branches or pull requests

3 participants