Skip to content

Commit 72cede9

Browse files
authored
Merge pull request #13 from databio/dev
v1
2 parents 97c0530 + 62e5913 commit 72cede9

42 files changed

Lines changed: 912 additions & 536 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

demo/md_template.jinja

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,3 @@ This is a jinja template. You can write plain markdown text into the template li
44

55
## YAML data
66

7-
You can also refer to variables in the yaml files, using syntax like this:
8-
9-
{% raw %}
10-
{{ number_of_things }}
11-
{{ name_of_person }}
12-
{% endraw %}
13-
14-
Which renders like this:
15-
16-
{{ number_of_things }}
17-
{{ name_of_person }}
18-
19-
## Markdown data
20-
21-
You can refer to *content* in the markdown data with the `.content` attribute, using the name you put in the config file {% raw %}{{ some_text_data.content }}{% endraw %}, which renders like this:
22-
23-
```
24-
{{ some_text_data.content }}
25-
```
26-
27-
28-
You can also refer to the yaml metadata in your markdown files, using {% raw %}{{ some_text_data.metadata.text_property }}{% endraw %}:
29-
30-
```
31-
{{ some_text_data.metadata.text_property }}
32-
```

demo/rendered.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ This is a jinja template. You can write plain markdown text into the template li
77
You can also refer to variables in the yaml files, using syntax like this:
88

99

10-
15
11-
The sundance kid
10+
{{ number_of_things }}
11+
{{ name_of_person }}
1212

1313

1414
Which renders like this:
@@ -18,9 +18,7 @@ The sundance kid
1818

1919
## Markdown data
2020

21-
You can refer to *content* in the markdown data with the `.content` attribute, using the name you put in the config file # Text content
22-
23-
Here is some text, which renders like this:
21+
You can refer to *content* in the markdown data with the `.content` attribute, using the name you put in the config file {{ some_text_data }}, which renders like this:
2422

2523
```
2624
# Text content
@@ -29,8 +27,8 @@ Here is some text
2927
```
3028

3129

32-
You can also refer to the yaml metadata in your markdown files, using text_property_value:
30+
You can also refer to the yaml metadata in your markdown files, using {{ _local_frontmatter.some_text_data.text_property }}:
3331

3432
```
35-
text_property_value
33+
3634
```

demo_book/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Variable variables for book demo
2+
3+
This folder contains an example of how to write a generic jinja template, and encode the contents within data variables in the config file.
4+
5+
There are three examples that produce the same output, which can be produced using these commands:
6+
7+
```
8+
mm -c book_basic/_markmeld.yaml default -p
9+
10+
mm -c book_var1/_markmeld.yaml default -p
11+
12+
mm -c book_var2/_markmeld.yaml default -p
13+
14+
```
15+
16+
17+
## Book basic
18+
19+
This encodes the chapters directly in the `jinja` template. It's simple, but it's not re-usable.
20+
21+
## Book var1
22+
23+
This method uses the `_md` array, and indexes into it with `data.variables` specified in the `_markmeld.yaml` file. This uses a jinja template that is reusable.
24+
25+
## Book var2 (recommended)
26+
27+
This way extracts the chapters out of the `_markmeld.yaml` config file into a standalone yaml file. This is the most flexible way, since both the `jinja` template can be reused, and the `target` could also be imported and re-used with a different `chapters.yaml` file.
28+
29+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
targets:
2+
default:
3+
jinja_template: book.jinja
4+
output_file: "demo_output.txt"
5+
command: cat > {output_file}
6+
data:
7+
md_files:
8+
intro: ../md/01-intro.md
9+
credit: ../md/02-credit.md
10+
savings: ../md/03-savings.md

demo_book/book_basic/book.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{ intro }}
2+
{{ credit }}
3+
{{ savings }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Introduction
2+
3+
This is my introduction chapter
4+
5+
...
6+
# Credit
7+
8+
This is chapter 2 on credit.
9+
10+
...
11+
# Chapter 3: Savings
12+
13+
This is chapter 3 on savings.
14+
15+
...

demo_book/book_var1/_markmeld.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
targets:
2+
default:
3+
jinja_template: book.jinja
4+
output_file: "demo_output.txt"
5+
command: cat > {output_file}
6+
data:
7+
md_files:
8+
intro: ../md/01-intro.md
9+
credit: ../md/02-credit.md
10+
savings: ../md/03-savings.md
11+
variables:
12+
chapters:
13+
- intro
14+
- credit
15+
- savings

demo_book/book_var1/book.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{% for chapter in chapters %}{{ _md[chapter] }}
2+
{% endfor %}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Introduction
2+
3+
This is my introduction chapter
4+
5+
...
6+
# Credit
7+
8+
This is chapter 2 on credit.
9+
10+
...
11+
# Chapter 3: Savings
12+
13+
This is chapter 3 on savings.
14+
15+
...

demo_book/book_var2/_markmeld.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
targets:
2+
default:
3+
jinja_template: book.jinja
4+
output_file: "demo_output.txt"
5+
command: cat > {output_file}
6+
data:
7+
md_globs:
8+
- ../md/*.md
9+
yaml_files:
10+
chapters: chapters.yaml

0 commit comments

Comments
 (0)