This function takes a cookiecutter-compatible template directory and resolves template placeholders in both filenames and (for text files) content.
Usage
bake(
template,
output_path,
extra_context = list(),
overwrite = FALSE,
no_input = FALSE
)
Arguments
- template
Template to apply
- output_path
Directory to fill
- extra_context
Context variables to use while populating template
- overwrite
Whether to overwrite existing files
- no_input
Don't prompt for context variables specified in cookiecutter.json
Details
template
Path to the template to apply. This can point to either a directory, or an
archive of the same in .zip
, .tar
or .tar.gz
formats.
output_path
Path of directory to output processed template files into. This will be
filled based on the contents of the template
option.
extra_context
List of template variables to use in filling placeholders. (empty by default)
overwrite
Whether to overwrite existing files. (defaults to false
, and issues a
message)
no_input
Don't prompt the user for variable values specified in cookiecutter.json
.
This removes the need for interaction when applying a template.
Examples
# Extract a demo template
# (this uses a bundled template and extracts information
# into a temporary directory -- you'll have it easier
# because you can insert the paths you want directly)
cookiecutter::bake(
system.file('examples/demo.zip', package = 'cookiecutter'),
fs::path_temp('cookiecutter.demo'),
extra_context = list(
flavor = 'chocolate chip',
hot_beverage = 'coffee'
)
)
#> Please enter a value for flavor [chocolate chip]
#>
#> Please enter a value for topping [chocolate chunks]
#>
#> Please enter a value for hot_beverage [coffee]
#>
#> Rendering "chocolate chip recipe.md"