Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow external html in rustdoc for crates.
Updated documentation to reflect md->html. Modularized external file loading.
- Loading branch information
Showing
8 changed files
with
143 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use std::{io, str}; | ||
|
||
#[deriving(Clone)] | ||
pub struct ExternalHtml{ | ||
pub in_header: String, | ||
pub before_content: String, | ||
pub after_content: String | ||
} | ||
|
||
impl ExternalHtml { | ||
pub fn load(in_header: &[String], before_content: &[String], after_content: &[String]) | ||
-> Option<ExternalHtml> { | ||
match (load_external_files(in_header), | ||
load_external_files(before_content), | ||
load_external_files(after_content)) { | ||
(Some(ih), Some(bc), Some(ac)) => Some(ExternalHtml { | ||
in_header: ih, | ||
before_content: bc, | ||
after_content: ac | ||
}), | ||
_ => None | ||
} | ||
} | ||
} | ||
|
||
pub fn load_string(input: &Path) -> io::IoResult<Option<String>> { | ||
let mut f = try!(io::File::open(input)); | ||
let d = try!(f.read_to_end()); | ||
Ok(str::from_utf8(d.as_slice()).map(|s| s.to_string())) | ||
} | ||
|
||
macro_rules! load_or_return { | ||
($input: expr, $cant_read: expr, $not_utf8: expr) => { | ||
{ | ||
let input = Path::new($input); | ||
match ::externalfiles::load_string(&input) { | ||
Err(e) => { | ||
let _ = writeln!(&mut io::stderr(), | ||
"error reading `{}`: {}", input.display(), e); | ||
return $cant_read; | ||
} | ||
Ok(None) => { | ||
let _ = writeln!(&mut io::stderr(), | ||
"error reading `{}`: not UTF-8", input.display()); | ||
return $not_utf8; | ||
} | ||
Ok(Some(s)) => s | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn load_external_files(names: &[String]) -> Option<String> { | ||
let mut out = String::new(); | ||
for name in names.iter() { | ||
out.push_str(load_or_return!(name.as_slice(), None, None).as_slice()); | ||
out.push_char('\n'); | ||
} | ||
Some(out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
63afc08
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from huonw
at zzmp@63afc08
63afc08
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging zzmp/rust/feat/markdown-in-crate-documentation = 63afc08 into auto
63afc08
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zzmp/rust/feat/markdown-in-crate-documentation = 63afc08 merged ok, testing candidate = 2735c7b
63afc08
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/108
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/109
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/109
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/109
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/112
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/113
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/112
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/118
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/113
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/112
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/115
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/113
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/112
63afc08
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = 2735c7b