Skip to content

Commit 5bd4869

Browse files
committed
---
yaml --- r: 11614 b: refs/heads/master c: 1d826b7 h: refs/heads/master v: v3
1 parent 7e2934b commit 5bd4869

File tree

2 files changed

+76
-24
lines changed

2 files changed

+76
-24
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: 0e3cee747af58a48038347e88c5fc05799a8e8b5
2+
refs/heads/master: 1d826b735c30a89bfe3aac8acbcda4efc8b5286f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustdoc/markdown_writer.rs

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn markdown_writer(
5454
config: config::config,
5555
page: doc::page
5656
) -> writer {
57-
let filename = make_filename(config, "md", page);
57+
let filename = make_filename(config, page);
5858
generic_writer {|markdown|
5959
write_file(filename, markdown);
6060
}
@@ -66,7 +66,7 @@ fn pandoc_writer(
6666
) -> writer {
6767
assert option::is_some(config.pandoc_cmd);
6868
let pandoc_cmd = option::get(config.pandoc_cmd);
69-
let filename = make_filename(config, "html", page);
69+
let filename = make_filename(config, page);
7070

7171
let pandoc_args = [
7272
"--standalone",
@@ -131,47 +131,99 @@ fn generic_writer(process: fn~(markdown: str)) -> writer {
131131

132132
fn make_filename(
133133
config: config::config,
134-
ext: str,
135-
_page: doc::page
134+
page: doc::page
136135
) -> str {
137136
import std::fs;
138-
let cratefile = fs::basename(config.input_crate);
139-
let cratename = tuple::first(fs::splitext(cratefile));
140-
fs::connect(config.output_dir, cratename + "." + ext)
141-
}
142-
143-
fn write_file(path: str, s: str) {
144-
import std::io;
145-
import std::io::writer_util;
146137

147-
alt io::file_writer(path, [io::create, io::truncate]) {
148-
result::ok(writer) {
149-
writer.write_str(s);
150-
}
151-
result::err(e) { fail e }
152-
}
138+
let filename = {
139+
alt page {
140+
doc::cratepage(doc) {
141+
if config.output_format == config::pandoc_html &&
142+
config.output_style == config::doc_per_mod {
143+
"index"
144+
} else {
145+
assert doc.topmod.name() != "";
146+
doc.topmod.name()
147+
}
148+
}
149+
doc::itempage(doc) {
150+
str::connect(doc.path() + [doc.name()], "_")
151+
}
152+
}
153+
};
154+
let ext = alt config.output_format {
155+
config::markdown { "md" }
156+
config::pandoc_html { "html" }
157+
};
158+
fs::connect(config.output_dir, filename + "." + ext)
153159
}
154160

155161
#[test]
156162
fn should_use_markdown_file_name_based_off_crate() {
157163
let config = {
158-
output_dir: "output/dir"
164+
output_dir: "output/dir",
165+
output_format: config::markdown,
166+
output_style: config::doc_per_crate
159167
with config::default_config("input/test.rc")
160168
};
161-
let doc = test::mk_doc("");
169+
let doc = test::mk_doc("test", "");
162170
let page = doc::cratepage(doc.cratedoc());
163-
assert make_filename(config, "md", page) == "output/dir/test.md";
171+
let filename = make_filename(config, page);
172+
assert filename == "output/dir/test.md";
173+
}
174+
175+
#[test]
176+
fn should_name_html_crate_file_name_index_html_when_doc_per_mod() {
177+
let config = {
178+
output_dir: "output/dir",
179+
output_format: config::pandoc_html,
180+
output_style: config::doc_per_mod
181+
with config::default_config("input/test.rc")
182+
};
183+
let doc = test::mk_doc("", "");
184+
let page = doc::cratepage(doc.cratedoc());
185+
let filename = make_filename(config, page);
186+
assert filename == "output/dir/index.html";
187+
}
188+
189+
#[test]
190+
fn should_name_mod_file_names_by_path() {
191+
let config = {
192+
output_dir: "output/dir",
193+
output_format: config::pandoc_html,
194+
output_style: config::doc_per_mod
195+
with config::default_config("input/test.rc")
196+
};
197+
let doc = test::mk_doc("", "mod a { mod b { } }");
198+
let modb = doc.cratemod().mods()[0].mods()[0];
199+
let page = doc::itempage(doc::modtag(modb));
200+
let filename = make_filename(config, page);
201+
assert filename == "output/dir/a_b.html";
164202
}
165203

166204
#[cfg(test)]
167205
mod test {
168-
fn mk_doc(source: str) -> doc::doc {
206+
fn mk_doc(name: str, source: str) -> doc::doc {
169207
astsrv::from_str(source) {|srv|
170-
extract::from_srv(srv, "")
208+
let doc = extract::from_srv(srv, name);
209+
let doc = path_pass::mk_pass().f(srv, doc);
210+
doc
171211
}
172212
}
173213
}
174214

215+
fn write_file(path: str, s: str) {
216+
import std::io;
217+
import std::io::writer_util;
218+
219+
alt io::file_writer(path, [io::create, io::truncate]) {
220+
result::ok(writer) {
221+
writer.write_str(s);
222+
}
223+
result::err(e) { fail e }
224+
}
225+
}
226+
175227
fn future_writer_factory(
176228
) -> (writer_factory, comm::port<(doc::page, str)>) {
177229
let markdown_po = comm::port();

0 commit comments

Comments
 (0)