]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/html/layout.rs
doc: Update modules for containers
[rust.git] / src / librustdoc / html / layout.rs
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+Sans+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>&uarr;</dt>
88                 <dd>Move up in search results</dd>
89                 <dt>&darr;</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 }