forked from ash/raku-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-exercise-template.raku
executable file
·106 lines (79 loc) · 2.9 KB
/
new-exercise-template.raku
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env raku
use YAMLish;
my %toc = load-yaml('_data/toc.yaml'.IO.slurp);
for %toc<toc><> -> %part {
for %part<items><> -> %subpart {
for %subpart<items><> -> %section {
if %section<exercises>:exists {
my $section-exercise-url = "%part<url>/%section<url>/exercises";
unless "$section-exercise-url/index.md".IO.f {
note "No index file for [%section<title>]($section-exercise-url)";
index-template(%section<title>, $section-exercise-url);
};
for %section<exercises><> -> %exercise {
my $exercise-url = "$section-exercise-url/%exercise<url>";
unless "$exercise-url/index.md".IO.f {
note "No exercise file for [%section<title> / %exercise<title>]($exercise-url)";
exercise-template(%exercise<title>, $exercise-url, %section<url>, %exercise<url>);
}
unless "$exercise-url/solution/index.md".IO.f {
note "No solution file for [%section<title> / %exercise<title>]($exercise-url)";
solution-template(%exercise<title>, $exercise-url, %section<url>, %exercise<url>);
}
my $filename = %exercise<file> // "%exercise<url>.raku";
unless "exercises/%section<url>/$filename".IO.f {
note "No code file at exercises/%section<url>/$filename";
mkdir "exercises/%section<url>";
"exercises/%section<url>/$filename".IO.spurt: '';
}
}
}
}
}
}
sub index-template($section-title, $section-exercise-url) {
mkdir $section-exercise-url;
"$section-exercise-url/index.md".IO.spurt: qq:to/TMPL/;
---
title: 'Exercises: $section-title'
---
\{% include menu.html %}
\{% include nav.html %}
TMPL
}
sub exercise-template($title, $url, $section-url, $exercise-url) {
mkdir $url;
"$url/index.md".IO.spurt: qq:to/TMPL/;
---
title: 'Exercise: $title'
---
\{% include menu.html %}
## Problem
## Example
```console
\$ raku $exercise-url.raku
```
## Solution
✅ [See the solution](solution)
\{% include nav.html %}
TMPL
}
sub solution-template($title, $url, $section-url, $exercise-url) {
mkdir "$url/solution";
"$url/solution/index.md".IO.spurt: qq:to/TMPL/;
---
title: 'Solution: $title'
---
\{% include menu.html %}
## Code
Here is the solution:
```raku
```
🦋 Find the program in the file [$exercise-url.raku](https://github.com/ash/raku-course/blob/master/exercises/$section-url/$exercise-url.raku).
## Output
```console
\$ raku exercises/$section-url/$exercise-url.raku
```
\{% include nav.html %}
TMPL
}