Skip to content

Commit 94e70bd

Browse files
committed
organize into folders (why didn't i think of this sooner?)
1 parent b7f8614 commit 94e70bd

Some content is hidden

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

80 files changed

+227
-220
lines changed

api.md

+63-63

glossary.md

+5-5

lang.md renamed to language.md

+9-9

tools/tocgen.rb

+42-35
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,62 @@
33
## By Alison Sanderson. Attribution is encouraged, though not required.
44
## <https://creativecommons.org/publicdomain/zero/1.0/legalcode>
55
## TOCGen: Generates inter-file TOCs.
6+
## Example usage:
7+
## tools/tocgen.rb
68

7-
$d = Dir["*.md"]
9+
def emit_filtered_file_toc file_matcher
10+
links = []
11+
files = ALL_MD_FILES.map do |p| p.match file_matcher end.compact
812

9-
def filter_emit r
10-
res = []
11-
for m in $d.map{|p| p.match r}.compact
12-
res << "* [#{m[1]}](#{m[0]})"
13-
end
14-
res.join ?\n
13+
for md_file in files
14+
links << "* [#{md_file[1]}](#{md_file[0]})"
15+
end
16+
17+
links.sort.join ?\n
1518
end
1619

17-
def find_toc_areas f
18-
re = /^(<!-- inter-toc\s*([^\s]+)\s*-->)(?:.|\n)*?(<!-- end -->)/i
19-
f.to_enum(:scan, re).map{$~}
20+
TOC_REGEX = /^(<!-- inter-toc\s*([^\s]+)?\s*-->)(?:.|\n)*?(<!-- end -->)/i
21+
def find_inter_toc_areas file
22+
file.to_enum(:scan, TOC_REGEX).map do $~ end
2023
end
2124

22-
def filter_toc_areas f
23-
o = String.new
24-
lof = 0
25-
for area in find_toc_areas f
26-
of = area.offset 0
27-
o << f[lof...of[0]]
28-
o << area[1]
29-
o << "\n\n"
30-
o << filter_emit(yield area[2])
31-
o << "\n\n"
32-
o << area[3]
33-
lof = of[1]
34-
end
35-
o << f[lof..-1]
36-
o
25+
def filter_toc_areas file
26+
content = ""
27+
last_offset = 0
28+
29+
for area in find_inter_toc_areas file
30+
offset = area.offset 0
31+
content << file[last_offset...offset[0]]
32+
content << area[1]
33+
content << "\n\n"
34+
content << emit_filtered_file_toc(yield area[2])
35+
content << "\n\n"
36+
content << area[3]
37+
last_offset = offset[1]
38+
end
39+
40+
content << file[last_offset..-1]
41+
content
3742
end
3843

39-
def rewrite fnam
40-
f = File.read fnam
41-
o = yield f
42-
File.write fnam, o
44+
def rewrite filename
45+
file = File.read filename
46+
output = yield file
47+
File.write filename, output
4348
end
4449

45-
rewrite "api.md" do |f|
46-
filter_toc_areas f do |a| /api-#{a}-(\w+).md/ end
50+
ALL_MD_FILES = Dir["{api,glossary,language}/**/*.md"]
51+
52+
rewrite "api.md" do |file|
53+
filter_toc_areas file do |folder| /api\/#{folder}\/(\w+).md/ end
4754
end
4855

49-
rewrite "glossary.md" do |f|
50-
filter_toc_areas f do |a| /glossary-(\w+).md/ end
56+
rewrite "glossary.md" do |file|
57+
filter_toc_areas file do |_| /glossary\/(\w+).md/ end
5158
end
5259

53-
rewrite "lang.md" do |f|
54-
filter_toc_areas f do |a| /lang-(\w+).md/ end
60+
rewrite "language.md" do |file|
61+
filter_toc_areas file do |_| /language\/(\w+).md/ end
5562
end
5663

5764
## EOF

0 commit comments

Comments
 (0)