Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ These properties allow you to customize the behavior and content of the files an

You can use template variables in your configuration file by enclosing them in `{{@` and `@}}`. For example, `{{@ project_name @}}` will be replaced with the value of the `project_name` variable at runtime. If this are not set when running the script, it will prompt you to enter the value interactively.

If you need to define blocks you can use starting block notation `{%@` and end block notation `%@}`.
If you need to define blocks you can use starting block notation `{%@` and end block notation `@%}`.

To define comments you can use the comment start notation `{#@` and end comment notation `@#}`.

Expand Down Expand Up @@ -141,7 +141,7 @@ You can also use it with Terraform provider repositories, for example `{{@ "hash

##### `slugify`

This filter converts a string into a slug. It takes an optional argument to specify the separator character (default is `-`).
This filter converts a string into a slug. It takes no arguments: the value is lowercased, runs of whitespace become a single hyphen, and any character that is not `a-z`, `0-9`, or `-` is removed.

```yaml
files:
Expand All @@ -152,6 +152,14 @@ files:
slugify project_name: {{@ project_name | slugify @}}
```

Note that underscores are removed rather than converted, so `My_Project` becomes `myproject`. To produce a different separator, chain Jinja2's built-in `replace` filter:

```yaml
files:
- src/{{@ project_name | slugify | replace("-", "_") @}}/__init__.py:
content: ""
```

##### `default_branch`

This filter fetches the default branch name of a GitHub repository. It takes the repository name as an argument.
Expand All @@ -161,5 +169,5 @@ files:
- README.md:
content: |
# MyProject
Default branch: {{@ "httpdss/struct" | default_branch @}}
Default branch: {{@ "httpdss/structkit" | default_branch @}}
```
37 changes: 32 additions & 5 deletions docs/template-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ files:
For control structures, use block notation:

- Start block: `{%@`
- End block: `%@}`
- End block: `@%}`

```yaml
files:
Expand Down Expand Up @@ -188,6 +188,12 @@ files:
generated_at: {{@ now() @}}
```

!!! warning "`uuid()` and `now()` are non-deterministic"
A file containing either produces different content on every run, so it always
appears in `structkit generate --dry-run --diff` output. That removes the diff's
value as a drift check. Confine them to files marked `skip_if_exists: true`, or
avoid them in anything you regenerate.

### `env(name, default="")` (global)

Read an environment variable with an optional default.
Expand All @@ -210,6 +216,19 @@ files:
{{@ read_file("INTRO.md") @}}
```

### `current_repo()` (global)

Return `owner/repo` for the Git repository in the current working directory, read from
`remote.origin.url`. Both HTTPS and SSH remotes are supported; a non-GitHub remote
returns an error string.

```yaml
files:
- README.md:
content: |
[![CI](https://github.com/{{@ current_repo() @}}/actions/workflows/ci.yml/badge.svg)](https://github.com/{{@ current_repo() @}}/actions)
```

### `to_yaml` / `from_yaml` (filters)

Serialize and parse YAML.
Expand All @@ -228,13 +247,13 @@ files:

### `to_json` / `from_json` (filters)

Serialize and parse JSON.
Serialize and parse JSON. to_json accepts an optional indent argument.

```yaml
files:
- data.json:
content: |
{{@ some_dict | to_json @}}
{{@ some_dict | to_json(indent=2) @}}
```

```yaml
Expand Down Expand Up @@ -282,7 +301,15 @@ files:
server_name {{@ project_name | slugify @}};
```

**Options**: Optional separator character (default: `-`)
**Options**: None. The value is lowercased, runs of whitespace become a single hyphen, and any character that is not `a-z`, `0-9`, or `-` is removed.

Note that underscores are removed rather than converted, so `My_Project` becomes `myproject`. To produce a different separator, chain Jinja2's built-in `replace` filter:

```yaml
files:
- src/{{@ project_name | slugify | replace("-", "_") @}}/__init__.py:
content: ""
```

### `default_branch`

Expand All @@ -294,7 +321,7 @@ files:
content: |
on:
push:
branches: [ {{@ "httpdss/struct" | default_branch @}} ]
branches: [ {{@ "httpdss/structkit" | default_branch @}} ]
```

## The `with` Clause
Expand Down
Loading