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.
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.
13 use std::path::PathBuf;
15 use externalfiles::ExternalHtml;
21 pub external_html: ExternalHtml,
27 pub css_class: &'a str,
28 pub root_path: &'a str,
29 pub description: &'a str,
30 pub keywords: &'a str,
31 pub resource_suffix: &'a str,
34 pub fn render<T: fmt::Display, S: fmt::Display>(
35 dst: &mut io::Write, layout: &Layout, page: &Page, sidebar: &S, t: &T,
36 css_file_extension: bool, themes: &[PathBuf])
43 <meta charset="utf-8">
44 <meta name="viewport" content="width=device-width, initial-scale=1.0">
45 <meta name="generator" content="rustdoc">
46 <meta name="description" content="{description}">
47 <meta name="keywords" content="{keywords}">
49 <title>{title}</title>
51 <link rel="stylesheet" type="text/css" href="{root_path}normalize{suffix}.css">
52 <link rel="stylesheet" type="text/css" href="{root_path}rustdoc{suffix}.css"
55 <link rel="stylesheet" type="text/css" href="{root_path}dark{suffix}.css">
56 <link rel="stylesheet" type="text/css" href="{root_path}main{suffix}.css" id="themeStyle">
57 <script src="{root_path}storage{suffix}.js"></script>
63 <body class="rustdoc {css_class}">
66 This old browser is unsupported and will most likely display funky
74 <div class="sidebar-menu">☰</div>
79 <div class="theme-picker">
80 <button id="theme-picker" aria-label="Pick another theme!">
81 <img src="{root_path}brush{suffix}.svg" width="18" alt="Pick another theme!">
83 <div id="theme-choices"></div>
85 <script src="{root_path}theme{suffix}.js"></script>
87 <form class="search-form js-only">
88 <div class="search-container">
89 <input class="search-input" name="search"
91 placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
97 <section id='main' class="content">{content}</section>
98 <section id='search' class="content hidden"></section>
100 <section class="footer"></section>
102 <aside id="help" class="hidden">
104 <h1 class="hidden">Help</h1>
106 <div class="shortcuts">
107 <h2>Keyboard Shortcuts</h2>
110 <dt><kbd>?</kbd></dt>
111 <dd>Show this help dialog</dd>
112 <dt><kbd>S</kbd></dt>
113 <dd>Focus the search field</dd>
114 <dt><kbd>↑</kbd></dt>
115 <dd>Move up in search results</dd>
116 <dt><kbd>↓</kbd></dt>
117 <dd>Move down in search results</dd>
118 <dt><kbd>↹</kbd></dt>
120 <dt><kbd>⏎</kbd></dt>
121 <dd>Go to active search result</dd>
122 <dt><kbd>+</kbd></dt>
123 <dd>Expand all sections</dd>
124 <dt><kbd>-</kbd></dt>
125 <dd>Collapse all sections</dd>
130 <h2>Search Tricks</h2>
133 Prefix searches with a type followed by a colon (e.g.
134 <code>fn:</code>) to restrict the search to a given type.
138 Accepted types are: <code>fn</code>, <code>mod</code>,
139 <code>struct</code>, <code>enum</code>,
140 <code>trait</code>, <code>type</code>, <code>macro</code>,
141 and <code>const</code>.
145 Search functions by type signature (e.g.
146 <code>vec -> usize</code> or <code>* -> vec</code>)
155 window.rootPath = "{root_path}";
156 window.currentCrate = "{krate}";
158 <script src="{root_path}main{suffix}.js"></script>
159 <script defer src="{root_path}search-index.js"></script>
162 css_extension = if css_file_extension {
163 format!("<link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}theme{suffix}.css\">",
164 root_path = page.root_path,
165 suffix=page.resource_suffix)
170 root_path = page.root_path,
171 css_class = page.css_class,
172 logo = if layout.logo.is_empty() {
175 format!("<a href='{}{}/index.html'>\
176 <img src='{}' alt='logo' width='100'></a>",
177 page.root_path, layout.krate,
181 description = page.description,
182 keywords = page.keywords,
183 favicon = if layout.favicon.is_empty() {
186 format!(r#"<link rel="shortcut icon" href="{}">"#, layout.favicon)
188 in_header = layout.external_html.in_header,
189 before_content = layout.external_html.before_content,
190 after_content = layout.external_html.after_content,
192 krate = layout.krate,
193 themes = themes.iter()
194 .filter_map(|t| t.file_stem())
195 .filter_map(|t| t.to_str())
196 .map(|t| format!(r#"<link rel="stylesheet" type="text/css" href="{}{}">"#,
198 t.replace(".css", &format!("{}.css", page.resource_suffix))))
199 .collect::<String>(),
200 suffix=page.resource_suffix,
204 pub fn redirect(dst: &mut io::Write, url: &str) -> io::Result<()> {
205 // <script> triggers a redirect before refresh, so this is fine.
210 <meta http-equiv="refresh" content="0;URL={url}">
213 <p>Redirecting to <a href="{url}">{url}</a>...</p>
214 <script>location.replace("{url}" + location.search + location.hash);</script>