Package: cut-out-cookies
A jinja2 extension for optionally including files in cookiecutter templatesIt's a well known and documented issue that cookiecutter does not support
conditionally included files and directories. Seethis post on github.This package unlocks that feature with simple jinja2 filters that can be
applied to:optional file inclusionoptional directory inclusionoptional inclusion of blocks within templatesoptional inclusion of in-line textSetupThis assumes that you have cookiecutter installed already and have a project
that you are building into a template. This also assumes you are managing
your environment in your preferred way.First, installcut-out-cookies:$pipinstallcut-out-cookiesIf you are using poetry, pipenv, flit, etc you will need to convert the
command for your setup.Add the extension to yourcookiecutter.jsonfile like so:{"full_name":"Tucker Beck","email":"tucker.beck@gmail.com","project_name":"Sugar Cookies Project","version":"0.1.0","_extensions":["cutout.Stencil"]}The only important line here is where the extension is being added. The
reset is just for example context.Next, you should add some 'patterns' to yourcookiecutter.jsonthat you
will use to 'decorate' your optional cookies with:{"full_name":"Tucker Beck","email":"tucker.beck@gmail.com","project_name":"Sugar Cookies Project","version":"0.1.0","_extensions":["cutout.Stencil"],"include_sprinkles":false,"include_frosting":false}This indicates that, by default, any cookies decorated with 'sprinkles' or
'frosting' should not be included in the generated project. The user will
now be prompted if they want to include the optional features 'sprinkles'
and 'frosting'Finally, due tothis issue on the cookiecutter github repoyou will need to install a post-gen project hook to cleanup the directories
that you intend to omit. Add ahooksdirectory in your template with a
file calledpost_gen_project.py. That file needs to contain this:fromcutoutimportcleanupcleanup()That's it. You should be ready to make some cookies now!Using cut-out-cookies stencilsFor a case study, let's suppose you are building a project stencil called
'Sugar Cookies' that starts out looking like this:sugar-cookies/
├── cookiecutter.json
└── {{cookiecutter.project_name}}
    └── README.mdOptionally including a fileTo indicate that a file should only be included if a certain pattern is
included, you use thestencilfilter in its template filename.Let's create a file called 'tasty.py' that should only be included if the
'sprinkles' pattern is applied. To do that, we'll apply thestencilfilter like so:examples/
├── cookiecutter.json
└── {{cookiecutter.project_name}}
    ├── README.md
    └── {{'tasty.py'|stencil('sprinkles')}}Now if theinclude_sprinklessetting is enabled in cookiecutter, the rendered
project will have a file calledtasty.py. If it is not enabled, thetasty.pysource file will be omitted altogetherOptionally including a directoryTo indicate that a directory should only be included if a certain pattern is
included, you use thestencil_pathfilter in its name. Unfortunately, thestencilfilter cannot be used for directories due tothis issue. Thestencil_pathcauses non-matching directories to be Prefixed with a special
flag value ('OBSCURATA_LAMINA_INTERRASILIS'). Then, a post-gen hook can be used
to remove these directories.  This approach is a bit of a hack, but until the
mentioned issue is fixed, we've tried to make it as painless as possible by
including acleanupfunction that can be easily added to apost_gen_projecthook.Let's create a diretory called 'batch' that should only be included if the
'frosting' pattern is included. To do that, we'll apply thestencil_pathfilter
like so:examples/
├── cookiecutter.json
├── hooks/
│   └── post_gen_project.py
└── {{cookiecutter.project_name}}
    ├── README.md
    └── {{'batch'|stencil_path('frosting')}}
        ├── star_shaped.py
        └── heart_shaped.pyNow if theinclude_frostingsetting is enabled in cookiecutter, the rendered
project will have a directory calledbatchthat includes two file calledstar_shaped.pyandheart_shaped.py. If it is not enabled, the directory will
be named 'OBSCURATA_LAMINA_INTERRASILIS--batch' in the generated project. If you
have thepost_gen_projecthook defined like this:fromcutoutimportcleanupcleanup()Then the non-matching directories will be removed after project generation.Optionally include a block of textTo indicate that a block of text should only be included if a cerain pattern
is included, you use thestencilfilter block like so:This text will always be included
{%- filter stencil('glitter') }
This text will only be inlcuded if the glitter pattern is included in the
cookiecutter config
{% endfilter %}Optionally include text inlineTo indicate that a bit  of in-line text should only be included if a cerain pattern
is included, you use thestencilfilter like so:This text includes {{ 'whipped cream' | stencil('creamy') }} frostingThe text above will only include 'whipped cream' if thecreamypattern in included