Skip to content

Commit

Permalink
Add developer docs for modifying template
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsiqueira committed Jun 10, 2024
1 parent cb065f3 commit a4fd0cc
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/src/90-contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ Otherwise, say what your proposed solution is and wait for a discussion around i

If your solution involves code (or something that requires running the package locally), check the [developer documentation](90-developer.md).
Otherwise, you can use the GitHub interface directly to create your pull request.

## Additions and modifications to the template

If you have any new idea or think the template needs to be updated or fixed, please search our [issues](https://github.com/abelsiqueira/COPIERTemplate.jl/issues) and if there isn't anything relevant, open a new issue.
89 changes: 89 additions & 0 deletions docs/src/90-developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,92 @@ After that, you only need to wait and verify:
- After the release is create, a "docs" GitHub action will start for the tag.
- After it passes, a deploy action will run.
- After that runs, the [stable docs](https://abelsiqueira.github.io/COPIERTemplate.jl/stable) should be updated. Check them and look for the version number.
## Additions to the templates
!!! info "Suggestions are not here"
This section is aimed at the developer working on a new question, if you have any new idea or think the template needs to be updated or fixed, please search our [issues](https://github.com/abelsiqueira/COPIERTemplate.jl/issues) and if there isn't anything relevant, open a new issue.
### Creating a new question
To create a new question, you have to open the file `copier.yml` in the root.
Find an appropriate place to add the question. Comments help identify the optional sections in the file.
Follow the other questions style and syntax. The gist of it is that you need:
- A `CamelCase` name.
- `when: "{{ AnswerStrategy == 'ask' }}"` if the question is optional.
- A `type`.
- A `help: Short description or title (Longer description and details)`.
- A `default`, if the question is optional.
- To default to `true` if "Recommended" or `false` for "Minimum", use `{{ AnswerStrategy != 'minimum' }}`.
### Dependent sections in a file
To create a section in a file that depends on a variable, first add `.jinja` to the end of the file name and use something like
```jinja
{% if AddSomeStuff %}
...
{% endif %}
```
`AddSomeStuff` is assumed to be boolean here, but you can use other conditions, such as `{% if PackageName == 'Pkg' %}`.
Notice that the empty spaces are included as well, so in some situation you might need to make it less readable.
For instance, the code below will correctly parse into a list of three elements if `AddBob` is false.
```jinja
# Good
- Alice{% if AddBob %}
- Bob{% endif}
- Carlos
- Diana
```
While the code below will parse into two lists of one and two elements, respectively:
```jinja
# Bad
- Alice
{% if AddBob %}- Bob{% endif}
- Carlos
- Diana
```
### Dependent files and directories
To make a file depend on a variable, you can change the name of the file to include the conditional and the `.jinja` extension.
```jinja
{% if AddSomeFile %}some-file.txt{% endif %}.jinja
```
If `AddSomeFile`, then `some-file.txt` will exist.
For directories, you do the same, except that you don't add the `.jinja` extension.
```jinja
{% if AddGitHubTemplates %}ISSUE_TEMPLATE{% endif %}
```
### Using answers
To use the answers of a question outside of a conditional, you can use `{{ SomeValue }}`.
This will translate to the value of `SomeValue` as answered by the user.
For instance
```jinja
whoami() = "Hi, I'm package {{ PackageName }}.jl"
```
This also works on file names and in the `copier.yml` file.
### Raw tag and avoiding clashes in GitHub workflow files
Since the GitHub workflow also uses `{` and `}` for their commands, we want to enclose them using the `{% raw %}...{% endraw %}` tag:
```jinja
os: {% raw %}%{{ matrix.os }}{% endraw %}
```

0 comments on commit a4fd0cc

Please sign in to comment.