Skip to content

Commit

Permalink
🎨 Reformat readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Krupinski committed Feb 9, 2024
1 parent a0fd2d4 commit 3243c5c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Rybak

_/ˈrɨ.bak/_

Directory-tree generator library.

## Synopsis

Rybak is an extension of template engines, which instead of rendering a single file or string, renders a whole directory.
Rybak is an extension of template engines, which instead of rendering a single file or string, renders a whole
directory.

In a way it's similar to [Cookiecutter](https://pypi.org/project/cookiecutter/) or [Copier](https://pypi.org/project/copier/), but while these programs are designed specifically for generating
In a way it's similar to [Cookiecutter](https://pypi.org/project/cookiecutter/)
or [Copier](https://pypi.org/project/copier/), but while these programs are designed specifically for generating
software projects, while Rybak is a library for generating arbitrary directory tree structures.

Rybak template is a directory consisting of template files.
Expand Down Expand Up @@ -39,23 +42,25 @@ render(
JinjaAdapter(loader=FileSystemLoader('template_root')),
{'likes': {
'Alice': 'Bob',
'Bob': 'Charlie',
'Charlie': 'cats',
'Bob': 'Charlie',
'Charlie': 'cats',
}},
Path('target_root'),
)
```

- `template_root`:
is the directory containing template files, in this case Jinja templates. Templates can be used in file content, file names and directory names.
is the directory containing template files, in this case Jinja templates. Templates can be used in file content, file
names and directory names.

- `model`:
is the data structure used by the template. You can use here whatever the template accepts.

### Single template multiple data

Template files can be applied to collections of items.
In order to do so, a special function is made available, `loop_over` that iterates over a passed collection. The function can only be used in templates in file names.
In order to do so, a special function is made available, `loop_over` that iterates over a passed collection. The
function can only be used in templates in file names.

`loop_over` returns the element of the collection, so that it can be used to render name.

Expand All @@ -75,7 +80,8 @@ would produce three files: Alice, Bob and Charlie.

The current item is also available during rendering the file contents, as model variable `item`.

Of course, we might want different value in the file name and its content. For that we can manipulate the `loop_over`s result:
Of course, we might want different value in the file name and its content. For that we can manipulate the `loop_over`s
result:

model:

Expand Down Expand Up @@ -107,11 +113,13 @@ likes = [
]
```

In this case the file name template simplifies to `{{loop_over(likes).name}}` and the content template to `{{item.likes}}`.
In this case the file name template simplifies to `{{loop_over(likes).name}}` and the content template
to `{{item.likes}}`.

## Installation

Rybak templates can work with either of Jinja, Mako or Torado; so typically you need to install Rybak and one of those libraries.
Rybak templates can work with either of Jinja, Mako or Torado; so typically you need to install Rybak and one of those
libraries.

installing `rybak[jinja]` or `rybak[mako]` will handle this.

Expand Down

0 comments on commit 3243c5c

Please sign in to comment.