Comments (9)
I have somewhat run into a need for this as I have a template with some repeated, complicated Jinja templating that I don't want to make into one explicit Jinja plugin that people have to depend on so as to not gain a dependency on my template. It would be great if from some hook I could directly manipulate the Jinja context to inject my own items and plugins.
from cookiecutter.
Okay, cool. π
I've used jinja2 assignments to help with that, but as you say, it doesn't work across multiple files.
Thanks for the feedback, I'll take it into consideration when we design a plugin system.
from cookiecutter.
You mention Danny's secret key plugin, but it appears the plugin itself is a secret? :-) I'd love to see it - secret key generation (and other similar extensions) would be quite nice.
from cookiecutter.
Is anyone opposed to setuptools entry points for handling this?
I'm going to assume the most natural place to something like this is for users to write their own Jinja2 Extensions so the custom tags can be used in their templating.
At first glance it doesn't seem too difficult to implement, I'd be happy to give it a go. Would pretty much just need to load everything in generate_files
and set the extensions=[...]
in the Jinja Environment initialization.
The other problem is Jinja Extensions are not exactly straight forward if you haven't done them before. Maybe start off with just simple Jinja Extenions, and then slowly over time add some CC helpers to make authoring them a little more straight forward in common cases?
from cookiecutter.
See Pull Request #103
from cookiecutter.
Hi @brettcannon! π
Would your "own items and plugins" have any dependencies (other than what is already required by cookiecutter itself)?
from cookiecutter.
Nope. Honestly I just want a way to add more items programmatically after the user has entered their info.
To put this in concrete terms, I'm doing {{ cookiecutter.python_version|replace('.', '')|truncate(2, end='') }}
across two files in multiple places (setting a variable when I can, but I'm still doing it multiple files), so I would rather do that manipulation in my pre-hook in Python code and store the result in the cookiecutter
object so I could then access it from the Jinja code. So no dependencies at all since it's just straight-forward string manipulation that would be easier in Python than Jinja.
from cookiecutter.
I think this falls under the same category as #848. Assigning the Requires Sponsorship label until we have sponsorship for this project.
from cookiecutter.
@jensens @pydanny @ssbarnea This issue is 10 years old. I recommend closing the issue.
from cookiecutter.
Related Issues (20)
- Reporting LGPL license in some dependency HOT 2
- Installing a template without manually copying it HOT 4
- Nested Config Files: New format for "template" key
- Know about current context in hooks HOT 5
- Add isort to pre-commit config HOT 2
- Add Python 3.12 support
- Reduce complexity of cookiecutter.prompt.prompt_for_config
- CanΒ΄t paste more than 1024 characters for a variable HOT 1
- Support requirements.txt for template hooks HOT 1
- Cookiecutter fails to get config if the .cookiecutterrc is an empty file HOT 1
- Cookiecutter Setup Issue HOT 2
- Private variables are not exposed for rendering HOT 2
- CI: tox -e safety broken due to major release 3 of safety
- Unable to Access `collections.OrderedDict` Variables in `cookiecutter.json` despite proper Key Definition HOT 4
- Query: Conditional prompts in cookiecutter.json
- Adding value to nested dicts broken after 2.2.0 HOT 2
- The documentation could show a cookiecutter.json rewrite pre-prompt example HOT 3
- Whitespace control behavior different in v2.6.0 HOT 2
- Feature-Request: Templates in context variables should support boolean values HOT 8
- Feature-Request: Use inheritance with nested configuration HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cookiecutter.