Using and Mastering Cookiecutter Transcripts
Chapter: Creating Cookiecutter templates
Lecture: Template extensions

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Remember this cool Cookiecutter template.
0:05 It has some really interesting things we entered a project name
0:07 and it generate the slug, and it also asks for the release statement,
0:10 it said wait, that's today, this is actually when I ran it,
0:13 now this is when I wrote the slide, but whatever,
0:15 this is the date generated as the project or as the template is executed
0:20 to generate a project, so this is not actually a part of Cookiecutter,
0:24 this capability does not exist in Jinja2 either, in fact,
0:28 what this is is an extension to Jinja2 itself
0:32 which we can plug in to Cookiecutter, let's see how that works.
0:35 Over here, we have a list of extensions for Jinja,
0:38 you can see it talks about how to add them,
0:41 some internationalization stuff, expressions, loops, with statements,
0:44 auto escaping extensions, and in fact, there is a whole API to write your own,
0:48 and some people have, so if we go over to GitHub
0:52 and do a search for Jinja2 extension,
0:54 you can see there is at least 25 of them on GitHub,
0:57 so some about time, this one we're actually going to use,
1:00 some about Markdown, some about highlighting code,
1:03 and some about Jinja and some about Django here, things like that.
1:06 So these extensions are really helpful,
1:09 and we can use them inside of Cookiecutter.
1:12 Unfortunately, the way they get sort of setup is not super amazing,
1:15 in order to use these extensions, you basically have to
1:19 install the system, so let's give this a shot and see how it works.
1:22 So over here, let's look at this first, so what I have done is
1:25 I have put the syntax to generate a year month day expression
1:33 based on, right, so here you can say I'm in a run
1:37 now I'm going to feed it this local time operator here
1:41 and this is the extension stuff, so if I try to run this, this is not built in anywhere,
1:45 this is an extension that actually comes off of a place called PyPi,
1:50 the package manager for Python, it's not on my system,
1:53 I can go and try to run it, and it will say no, no, we cannot do this,
1:57 there is no module named jinja2_time, if I type pip list, you'll see yeah,
2:03 there is Jinja but there is no Jinja time.
2:07 So here is the bummer deal, if I want to do this,
2:11 if I want to actually have access to these extensions, here is the thing,
2:15 I have to outside of Cookiecutter pip install jinja2-time
2:21 I'm just going to go and download that, put it in my system,
2:24 and now if I pip list you can see Jinja2-time
2:28 Okay so that is step 1, the other thing to do is something
2:31 that we can do for the users, right, we need to come down here
2:34 and say we're going to have an _extensions,
2:37 I believe that's a list, with the proper assignment there,
2:41 okay, it looks like we're missing a coma up here but,
2:44 we've got our extensions and our extension is jinja2-time
2:48 and now we're using it right here,
2:50 notice there is some of these things are underscore that apply
2:53 to Cookiecutter that are not themselves prompt,
2:56 it obviously won't ask us what extension do we want here,
2:59 so let's try this, alright, so let's give this a shot, oh woops,
3:02 I still made a mistake here, I need actually not quite like this,
3:04 I need the .TimeExtension
3:07 There we go, okay, try again, excellent, it looks like it's working, right,
3:11 so my project will be timed project, and it's going to say time-project, beautiful,
3:17 I'll take that, the creator, I still got to work on this, it's me,
3:21 created on look at that, that is today.
3:25 So that comes out of our now extension,
3:28 and because we've installed jinja2-time
3:31 as a package and then over here, we've imported the .TimeExtension,
3:36 then we're good to go and I think created right now makes a lot of sense,
3:39 and you know what, I am feeling like cyan, boom, done.
3:42 Now, I don't actually put this value into our files,
3:45 we didn't reference cookiecutter.created_on
3:48 but if we wanted to it would be the value of that string right there.