1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use std::fmt;
12 use std::io;
13
14 #[deriving(Clone)]
15 pub struct Layout {
16 pub logo: ~str,
17 pub favicon: ~str,
18 pub krate: ~str,
19 }
20
21 pub struct Page<'a> {
22 pub title: &'a str,
23 pub ty: &'a str,
24 pub root_path: &'a str,
25 }
26
27 pub fn render<T: fmt::Show, S: fmt::Show>(
28 dst: &mut io::Writer, layout: &Layout, page: &Page, sidebar: &S, t: &T)
29 -> fmt::Result
30 {
31 write!(dst,
32 r##"<!DOCTYPE html>
33 <html lang="en">
34 <head>
35 <meta charset="utf-8">
36 <meta name="viewport" content="width=device-width, initial-scale=1.0">
37 <meta name="description" content="The {krate} library documentation.">
38
39 <title>{title}</title>
40
41 <link href='http://fonts.googleapis.com/css?family=Source+Code+Pro:400,600'
42 rel='stylesheet' type='text/css'>
43 <link rel="stylesheet" type="text/css" href="{root_path}main.css">
44
45 {favicon, select, none{} other{<link rel="shortcut icon" href="#">}}
46 </head>
47 <body>
48 <!--[if lte IE 8]>
49 <div class="warning">
50 This old browser is unsupported and will most likely display funky
51 things.
52 </div>
53 <![endif]-->
54
55 <section class="sidebar">
56 {logo, select, none{} other{
57 <a href='{root_path}{krate}/index.html'><img src='#' alt='' width='100'></a>
58 }}
59
60 {sidebar}
61 </section>
62
63 <nav class="sub">
64 <form class="search-form js-only">
65 <div class="search-container">
66 <input class="search-input" name="search"
67 autocomplete="off"
68 placeholder="Search documentation..."
69 type="search">
70 </div>
71 </form>
72 </nav>
73
74 <section id='main' class="content {ty}">{content}</section>
75 <section id='search' class="content hidden"></section>
76
77 <section class="footer"></section>
78
79 <div id="help" class="hidden">
80 <div class="shortcuts">
81 <h1>Keyboard shortcuts</h1>
82 <dl>
83 <dt>?</dt>
84 <dd>Show this help dialog</dd>
85 <dt>S</dt>
86 <dd>Focus the search field</dd>
87 <dt>↑</dt>
88 <dd>Move up in search results</dd>
89 <dt>↓</dt>
90 <dd>Move down in search results</dd>
91 <dt>&\#9166;</dt>
92 <dd>Go to active search result</dd>
93 </dl>
94 </div>
95 <div class="infos">
96 <h1>Search tricks</h1>
97 <p>
98 Prefix searches with a type followed by a colon (e.g.
99 <code>fn:</code>) to restrict the search to a given type.
100 </p>
101 <p>
102 Accepted types are: <code>fn</code>, <code>mod</code>,
103 <code>struct</code> (or <code>str</code>), <code>enum</code>,
104 <code>trait</code>, <code>typedef</code> (or
105 <code>tdef</code>).
106 </p>
107 </div>
108 </div>
109
110 <script>
111 var rootPath = "{root_path}";
112 var currentCrate = "{krate}";
113 </script>
114 <script src="{root_path}jquery.js"></script>
115 <script src="{root_path}main.js"></script>
116 <script async src="{root_path}search-index.js"></script>
117 </body>
118 </html>"##,
119 content = *t,
120 root_path = page.root_path,
121 ty = page.ty,
122 logo = nonestr(layout.logo),
123 title = page.title,
124 favicon = nonestr(layout.favicon),
125 sidebar = *sidebar,
126 krate = layout.krate,
127 )
128 }
129
130 fn nonestr<'a>(s: &'a str) -> &'a str {
131 if s == "" { "none" } else { s }
132 }
librustdoc/html/layout.rs:129:1-129:1 -fn- definition:
fn nonestr<'a>(s: &'a str) -> &'a str {
if s == "" { "none" } else { s }
}
references:- 2121: ty = page.ty,
122: logo = nonestr(layout.logo),
123: title = page.title,
124: favicon = nonestr(layout.favicon),
125: sidebar = *sidebar,
librustdoc/html/layout.rs:26:1-26:1 -fn- definition:
pub fn render<T: fmt::Show, S: fmt::Show>(
dst: &mut io::Writer, layout: &Layout, page: &Page, sidebar: &S, t: &T)
-> fmt::Result
references:- 2librustdoc/html/render.rs:
561: };
562: try!(layout::render(&mut w as &mut Writer, &self.cx.layout,
563: &page, &(""), &Source(contents)));
--
881: let mut writer = BufferedWriter::new(w);
882: try!(layout::render(&mut writer as &mut Writer, &cx.layout, &page,
883: &Sidebar{ cx: cx, item: it },
librustdoc/html/layout.rs:20:1-20:1 -struct- definition:
pub struct Page<'a> {
pub title: &'a str,
pub ty: &'a str,
references:- 3librustdoc/html/render.rs:
869: title.push_str(" - Rust");
870: let page = layout::Page {
871: ty: shortty(it).to_static_str(),
librustdoc/html/layout.rs:
27: pub fn render<T: fmt::Show, S: fmt::Show>(
28: dst: &mut io::Writer, layout: &Layout, page: &Page, sidebar: &S, t: &T)
29: -> fmt::Result
librustdoc/html/render.rs:
556: let title = format!("{} -- source", cur.filename_display());
557: let page = layout::Page {
558: title: title,
librustdoc/html/layout.rs:14:19-14:19 -struct- definition:
pub struct Layout {
pub logo: ~str,
pub favicon: ~str,
references:- 7librustdoc/html/render.rs:
214: sidebar: HashMap::new(),
215: layout: layout::Layout {
216: logo: "".to_owned(),
librustdoc/html/layout.rs:
15: pub struct Layout {
--
27: pub fn render<T: fmt::Show, S: fmt::Show>(
28: dst: &mut io::Writer, layout: &Layout, page: &Page, sidebar: &S, t: &T)
29: -> fmt::Result
librustdoc/html/render.rs:
80: /// creation of the context (contains info like the favicon)
81: pub layout: layout::Layout,
82: /// This map is a list of what should be displayed on the sidebar of the
librustdoc/html/layout.rs:
15: pub struct Layout {