Using and Mastering Cookiecutter Transcripts
Chapter: Creating Cookiecutter templates
Lecture: Helper text via post-generation hooks
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
We've seen that we can use our post generation hook for deleting files, right,
0:05
we had a certain number of files here that we only wanted to keep some of them
0:10
in the situation where we picked up particular color.
0:14
A real world example of this would be a web application
0:17
with different types of templates, Jinja, Chameleon, Mako and so on,
0:20
and you only want to keep the files that correspond to the ones selected,
0:25
by the creator, the person who ran the Cookiecutter template.
0:30
Now we're going to do one final thing here, we're going to display
0:33
some helpful instructions for the user,
0:37
okay, so when we run the Cookiecutter template,
0:40
what we'd love to see is here we've created your project,
0:43
we asked you the questions, and here is a friendly little getting started message
0:47
so we can help people fall into the pit of success.
0:50
These are the next steps you should take, if you feel lost- don't, just do this.
0:54
So I've already pre created a little message here so I am just going to paste it in,
0:58
so we need to somehow get the favorite color
1:01
because my message says welcome to the color project,
1:05
and you choose this color, the world is a rainbow, but mostly,
1:08
it's this colored rainbow, okay, to get started read me,
1:12
obviously you would have different types of messages here,
1:15
but let's say we have this method up top here, that already is getting the color
1:20
let's move this getting the favorite color out, and passed around.
1:24
Like so. Down here, we can pass in this favorite color, there we go,
1:32
it's not really a performance thing, this is actually just a static string,
1:37
it's pre replaced with the color when they selected it,
1:41
but I kind of like having this ability to get in one place and pass it around.
1:45
Alright, so now we should have a nice message when we're done with this.
1:49
Okay, let's create one final template, so again, it's going to be
1:53
cookiecutter cookiecutter_colors, we're going to run this here, and let's see,
1:58
the project is going to be final exam
2:02
and of course our little dependent property here,
2:05
grab that and create this, you creator is going to be me,
2:09
so I'll just put MK it's created on this day, when I recorded it,
2:12
I am feeling yellow again and let's go, what is going to happen,
2:16
it's going to run our hook, it's going to remove the extra files, right,
2:20
the blue and the green, and it's also going to give us that nice message,
2:25
let's see how that works Boom, welcome to the color project, yellow,
2:29
the world is a rainbow, but mostly it's yellow,
2:33
so to get started, you can read the readme, how cool is that,
2:36
this is a super sleek project creation experience.
2:40
I run the little thing and as we'll see later, you can actually run a custom script
2:44
out of your project and it could call this API,
2:47
and all the stuff is happening, and then when we are done,
2:50
we get this nice little message that we just added in our post generation hook.