-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Implement cargo project templates #1747
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
Conversation
Project templates allow users to define custom templates which can be used to scaffold projects. These templates consists of a directory of files, each of which will be treated as a mustache template. Example: cargo new myproject --template=http://github.com/someone/nickel-template This would download the template called 'nickel-template' to ~/.cargo/templates/nickel-template. Each file in that directory would then be compiled and rendered to the new project directory created by cargo. Once the template is downloaded, future uses can just reference it by name: cargo new webapp --template nickel-template Certain files will be ignored in template directories. These are namely files which mustache will not be able to compile. Image files, for example are all ignored. Closes issue rust-lang#396
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
Also to note, this converts the standard |
It's also a bit rough around the edges. Let me know where you think I can improve it! |
src/cargo/sources/git/utils.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, I meant to revert the changes to this file, will update!
Whoa, nice! I'm quite excited to see some progress on this front :) Some thoughts of mine:
I think it'd also be worth looking into other package managers to see what they do here. For example how does this compare to bundler's template integration (or is it Rails that has templates over there?). Also cc @wycats, I'm sure you'll have many opinions on this! |
Also cc @rust-lang/tools, you'll probably all in general be interested in this. |
@alexcrichton thanks for the comments! I figured this would spark some discussion, but wanted to get an initial draft done to kickstart it.
I know that Django has support for project templates, but I'll check out a few similar solutions and see how they approach it. I'll update this PR as I go. Looking forward to more feedback! |
I chatted with @wycats on IRC and he mentioned that handlebars may be more appropriate as a templating language (I'm personally unfamiliar with both), but I just want to make sure that we consider other possibilities. I'm also not 100% sure about what to do on the update front, so I'm curious what other projects do in this regard. To match cargo's existing behavior then |
I'm obviously biased about Handlebars, but it's basically 98% compatible with Mustache but also supports helpers exposed by the host language. In contrast, Mustache supports loops and conditionals. |
☔ The latest upstream changes (presumably #1748) made this pull request unmergeable. Please resolve the merge conflicts. |
Having the template download/update commands be separate from the project initialization command makes more sense to me. It feels weird to first specify a URL with |
Sorry for the delay on updating this, working on tests at the moment, then switching over the handlebars per the comments from @wycats. Hopefully get that part done in the next few days! Another possibility for managing templates would be to just not store them at all. Just download the one you want, scaffold the project, then remove the template. Next time you want it, repeat the process. Just s thought... |
So, just did some digging into how the It downloads templates to a temporary directory, which will get removed after use. You can also point it at a local folder, which obviously won't download anything. This is a better approach I think. It means that templates won't go out of date, because you need to re-download them every time you want them. If you find yourself re-using a template multiple times then you can download it yourself and point cargo at that each time instead. This changes the responsibility for managing the templates to the user, rather than cargo itself. What do you think of that approach? |
Sounds like a good idea to me! |
Closing due to inactivity, but feel free to reopen with a rebase and comments addressed! |
This was closed due to inactivity. It's almost a year old so I expect rebasing is not an option. Are there any other options for resurrecting it? It's a really useful project! |
Yeah unfortunately this'll need to go through a rebase or start from scratch. |
Resubmission of templating PR (#1747) This is a manual rebase of the older #1747 PR which was basically unrebasable due to the time it's been dormant.. This implements templating for Cargo and is basically the work of Greg Chapple (@gchp). I'd love for this feature to move forward since it's really tedious to create all the directories (e.g. `src/bin`) and copy paste docopt examples which I then edit. Then implement the `main` program to delegate to the subcommands in `src/bin`, etc.
Project templates allow users to define custom templates which can be
used to scaffold projects. These templates consists of a directory of
files, each of which will be treated as a mustache template.
Example:
This would download the template called 'nickel-template' to
~/.cargo/templates/nickel-template. Each file in that directory would
then be compiled and rendered to the new project directory created by
cargo. Once the template is downloaded, future uses can just reference
it by name:
Certain files will be ignored in template directories. These are namely
files which mustache will not be able to compile. Image files, for
example are all ignored.
Closes issue #396