Skip to content

Commit 559df01

Browse files
committed
---
yaml --- r: 11676 b: refs/heads/master c: a4ff220 h: refs/heads/master v: v3
1 parent 7c61800 commit 559df01

File tree

5 files changed

+92
-27
lines changed

5 files changed

+92
-27
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 801b02b25d6ba310ca8a4ee3a319d09a5c57062d
2+
refs/heads/master: a4ff220133128f7d4467f3919db579e7b50850c4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustdoc/markdown_index_pass.rs

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,68 @@
22

33
export mk_pass;
44

5-
fn mk_pass() -> pass {
5+
fn mk_pass(config: config::config) -> pass {
66
{
77
name: "markdown_index",
8-
f: run
8+
f: fn~(srv: astsrv::srv, doc: doc::doc) -> doc::doc {
9+
run(srv, doc, config)
10+
}
911
}
1012
}
1113

12-
fn run(_srv: astsrv::srv, doc: doc::doc) -> doc::doc {
14+
fn run(
15+
_srv: astsrv::srv,
16+
doc: doc::doc,
17+
config: config::config
18+
) -> doc::doc {
1319
let fold = fold::fold({
1420
fold_mod: fold_mod
15-
with *fold::default_any_fold(())
21+
with *fold::default_any_fold(config)
1622
});
1723
fold.fold_doc(fold, doc)
1824
}
1925

20-
fn fold_mod(fold: fold::fold<()>, doc: doc::moddoc) -> doc::moddoc {
26+
fn fold_mod(
27+
fold: fold::fold<config::config>,
28+
doc: doc::moddoc
29+
) -> doc::moddoc {
2130

2231
let doc = fold::default_any_fold_mod(fold, doc);
2332

2433
{
25-
index: some(build_index(doc))
34+
index: some(build_index(doc, fold.ctxt))
2635
with doc
2736
}
2837
}
2938

30-
fn build_index(doc: doc::moddoc) -> doc::index {
39+
fn build_index(
40+
doc: doc::moddoc,
41+
config: config::config
42+
) -> doc::index {
3143
{
32-
entries: par::anymap(doc.items, item_to_entry)
44+
entries: par::anymap(doc.items) {|item|
45+
item_to_entry(item, config)
46+
}
3347
}
3448
}
3549

36-
fn item_to_entry(doc: doc::itemtag) -> doc::index_entry {
50+
fn item_to_entry(
51+
doc: doc::itemtag,
52+
config: config::config
53+
) -> doc::index_entry {
54+
let link = alt doc {
55+
doc::modtag(_) if config.output_style == config::doc_per_mod {
56+
markdown_writer::make_filename(config, doc::itempage(doc))
57+
}
58+
_ {
59+
"#" + pandoc_header_id(markdown_pass::header_text(doc))
60+
}
61+
};
62+
3763
{
3864
kind: markdown_pass::header_kind(doc),
3965
name: markdown_pass::header_name(doc),
40-
link: pandoc_header_id(markdown_pass::header_text(doc))
66+
link: link
4167
}
4268
}
4369

@@ -67,26 +93,51 @@ fn pandoc_header_id(header: str) -> str {
6793

6894
#[test]
6995
fn should_index_mod_contents() {
70-
let doc = test::mk_doc("mod a { } fn b() { }");
96+
let doc = test::mk_doc(
97+
config::doc_per_crate,
98+
"mod a { } fn b() { }"
99+
);
100+
assert option::get(doc.cratemod().index).entries[0] == {
101+
kind: "Module",
102+
name: "a",
103+
link: "#module-a"
104+
};
105+
assert option::get(doc.cratemod().index).entries[1] == {
106+
kind: "Function",
107+
name: "b",
108+
link: "#function-b"
109+
};
110+
}
111+
112+
#[test]
113+
fn should_index_mod_contents_multi_page() {
114+
let doc = test::mk_doc(
115+
config::doc_per_mod,
116+
"mod a { } fn b() { }"
117+
);
71118
assert option::get(doc.cratemod().index).entries[0] == {
72119
kind: "Module",
73120
name: "a",
74-
link: "module-a"
121+
link: "a.html"
75122
};
76123
assert option::get(doc.cratemod().index).entries[1] == {
77124
kind: "Function",
78125
name: "b",
79-
link: "function-b"
126+
link: "#function-b"
80127
};
81128
}
82129

83130
#[cfg(test)]
84131
mod test {
85-
fn mk_doc(source: str) -> doc::doc {
132+
fn mk_doc(output_style: config::output_style, source: str) -> doc::doc {
86133
astsrv::from_str(source) {|srv|
134+
let config = {
135+
output_style: output_style
136+
with config::default_config("whatever")
137+
};
87138
let doc = extract::from_srv(srv, "");
88139
let doc = path_pass::mk_pass().f(srv, doc);
89-
run(srv, doc)
140+
run(srv, doc, config)
90141
}
91142
}
92143
}

trunk/src/rustdoc/markdown_pass.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn write_index(ctxt: ctxt, index: doc::index) {
283283
for entry in index.entries {
284284
let header = header_text_(entry.kind, entry.name);
285285
let id = entry.link;
286-
ctxt.w.write_line(#fmt("* [%s](#%s)", header, id));
286+
ctxt.w.write_line(#fmt("* [%s](%s)", header, id));
287287
}
288288
ctxt.w.write_line("");
289289
}
@@ -954,6 +954,12 @@ mod test {
954954

955955
fn create_doc_srv(source: str) -> (astsrv::srv, doc::doc) {
956956
astsrv::from_str(source) {|srv|
957+
958+
let config = {
959+
output_style: config::doc_per_crate
960+
with config::default_config("whatever")
961+
};
962+
957963
let doc = extract::from_srv(srv, "");
958964
#debug("doc (extract): %?", doc);
959965
let doc = tystr_pass::mk_pass().f(srv, doc);
@@ -962,7 +968,7 @@ mod test {
962968
#debug("doc (path): %?", doc);
963969
let doc = attr_pass::mk_pass().f(srv, doc);
964970
#debug("doc (attr): %?", doc);
965-
let doc = markdown_index_pass::mk_pass().f(srv, doc);
971+
let doc = markdown_index_pass::mk_pass(config).f(srv, doc);
966972
#debug("doc (index): %?", doc);
967973
(srv, doc)
968974
}

trunk/src/rustdoc/markdown_writer.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export writer_factory;
44
export writer_util;
55
export make_writer_factory;
66
export future_writer_factory;
7+
export make_filename;
78

89
enum writeinstr {
910
write(str),
@@ -54,7 +55,7 @@ fn markdown_writer(
5455
config: config::config,
5556
page: doc::page
5657
) -> writer {
57-
let filename = make_filename(config, page);
58+
let filename = make_local_filename(config, page);
5859
generic_writer {|markdown|
5960
write_file(filename, markdown);
6061
}
@@ -66,7 +67,7 @@ fn pandoc_writer(
6667
) -> writer {
6768
assert option::is_some(config.pandoc_cmd);
6869
let pandoc_cmd = option::get(config.pandoc_cmd);
69-
let filename = make_filename(config, page);
70+
let filename = make_local_filename(config, page);
7071

7172
let pandoc_args = [
7273
"--standalone",
@@ -159,12 +160,18 @@ fn generic_writer(process: fn~(markdown: str)) -> writer {
159160
}
160161
}
161162

162-
fn make_filename(
163+
fn make_local_filename(
163164
config: config::config,
164165
page: doc::page
165166
) -> str {
166-
import std::fs;
167+
let filename = make_filename(config, page);
168+
std::fs::connect(config.output_dir, filename)
169+
}
167170

171+
fn make_filename(
172+
config: config::config,
173+
page: doc::page
174+
) -> str {
168175
let filename = {
169176
alt page {
170177
doc::cratepage(doc) {
@@ -185,7 +192,8 @@ fn make_filename(
185192
config::markdown { "md" }
186193
config::pandoc_html { "html" }
187194
};
188-
fs::connect(config.output_dir, filename + "." + ext)
195+
196+
filename + "." + ext
189197
}
190198

191199
#[test]
@@ -198,7 +206,7 @@ fn should_use_markdown_file_name_based_off_crate() {
198206
};
199207
let doc = test::mk_doc("test", "");
200208
let page = doc::cratepage(doc.cratedoc());
201-
let filename = make_filename(config, page);
209+
let filename = make_local_filename(config, page);
202210
assert filename == "output/dir/test.md";
203211
}
204212

@@ -212,7 +220,7 @@ fn should_name_html_crate_file_name_index_html_when_doc_per_mod() {
212220
};
213221
let doc = test::mk_doc("", "");
214222
let page = doc::cratepage(doc.cratedoc());
215-
let filename = make_filename(config, page);
223+
let filename = make_local_filename(config, page);
216224
assert filename == "output/dir/index.html";
217225
}
218226

@@ -227,7 +235,7 @@ fn should_name_mod_file_names_by_path() {
227235
let doc = test::mk_doc("", "mod a { mod b { } }");
228236
let modb = doc.cratemod().mods()[0].mods()[0];
229237
let page = doc::itempage(doc::modtag(modb));
230-
let filename = make_filename(config, page);
238+
let filename = make_local_filename(config, page);
231239
assert filename == "output/dir/a_b.html";
232240
}
233241

trunk/src/rustdoc/rustdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn run(config: config::config) {
151151
unindent_pass::mk_pass(),
152152
sort_item_name_pass::mk_pass(),
153153
sort_item_type_pass::mk_pass(),
154-
markdown_index_pass::mk_pass(),
154+
markdown_index_pass::mk_pass(config),
155155
page_pass::mk_pass(config.output_style),
156156
markdown_pass::mk_pass(
157157
markdown_writer::make_writer_factory(config)

0 commit comments

Comments
 (0)