-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Include files or directories using the template engine #1517
Comments
Hi @simobasso I've been thinking about this on my morning walk and I've struck upon a solution I think is quite elegant. I propose a new Jinja filter built in to cookiecutter. For the sake of the following I'm naming it The
In this case, if the value Using a filter plus a conditional expression means you could do things like:
where
for multiple conditions. Bonus: applicability in filesIf in the example above the file
then that line would also automatically resolve to the empty string and the import statement would be left out. I think this is an attractively readable alternative to:
(NB: check if the newline would be removed with the filter, as it would for the if-block) The problemTemplating syntax needs to be filename-friendly. I haven't exhaustively considered what is valid for expressions-in-jinja but not in filenames, but it needs guarding against. Perhaps the argument to One solution I'd use in practice would be to set up booleans in cookiecutter.json, like this:
and then just use:
in the template pathnames themselves. I should add that presumably handling the compatibility of template logic and filesystem paths is already a concern for cookiecutter and has been thought out. I haven't investigated the current situation but I don't think adding a new filter would make it worse unless cookiecutter, for example, limits filenames to only plain variables. One possibility is to keep the logic that says a filename that's an empty string means "cookiecutter please ignore this", and then have:
in the A further alternative is to put aside the filter idea, and just add the rule that makes cookiecutter discard trees under empty-string paths and use python logic:
But I'm not sure if that's valid Jinja, I can't remember. NamingI've used Keen to hear your thoughts. |
@HappyEinara, thanks for your proposal, it's exciting. The idea of include directories is great. I'm not sure about the I have an alternative version of the implementation to reach the same results without inserting a new jinja extension, and I really appreciate your feedback about it. I only need few days to formalize it. Thanks |
follow up #1485 (comment) from @HappyEinara
The text was updated successfully, but these errors were encountered: