2013-09-18 22:18:38 -07:00
|
|
|
// Copyright 2013 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::fmt;
|
2013-11-10 22:46:32 -08:00
|
|
|
use std::io;
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2014-06-28 03:35:25 -07:00
|
|
|
use externalfiles::ExternalHtml;
|
|
|
|
|
2013-09-18 22:18:38 -07:00
|
|
|
#[deriving(Clone)]
|
|
|
|
pub struct Layout {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub logo: String,
|
|
|
|
pub favicon: String,
|
2014-06-28 03:35:25 -07:00
|
|
|
pub external_html: ExternalHtml,
|
2014-05-22 16:57:53 -07:00
|
|
|
pub krate: String,
|
2014-06-06 09:12:18 -07:00
|
|
|
pub playground_url: String,
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
|
2013-12-09 23:16:18 -08:00
|
|
|
pub struct Page<'a> {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub title: &'a str,
|
|
|
|
pub ty: &'a str,
|
|
|
|
pub root_path: &'a str,
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
pub fn render<T: fmt::Show, S: fmt::Show>(
|
2013-09-18 22:18:38 -07:00
|
|
|
dst: &mut io::Writer, layout: &Layout, page: &Page, sidebar: &S, t: &T)
|
2014-05-10 14:05:06 -07:00
|
|
|
-> io::IoResult<()>
|
2013-09-18 22:18:38 -07:00
|
|
|
{
|
2013-10-14 21:32:12 +02:00
|
|
|
write!(dst,
|
2014-03-16 18:29:51 -04:00
|
|
|
r##"<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
2013-09-18 22:18:38 -07:00
|
|
|
<head>
|
2014-04-18 11:08:34 +09:00
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
2014-03-20 19:05:22 +01:00
|
|
|
<meta name="description" content="The {krate} library documentation.">
|
|
|
|
|
2013-09-18 22:18:38 -07:00
|
|
|
<title>{title}</title>
|
|
|
|
|
2014-03-16 18:29:51 -04:00
|
|
|
<link rel="stylesheet" type="text/css" href="{root_path}main.css">
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2014-05-28 09:24:28 -07:00
|
|
|
{favicon}
|
2014-06-28 03:35:25 -07:00
|
|
|
{in_header}
|
2013-09-18 22:18:38 -07:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<!--[if lte IE 8]>
|
2014-03-16 18:29:51 -04:00
|
|
|
<div class="warning">
|
2013-09-18 22:18:38 -07:00
|
|
|
This old browser is unsupported and will most likely display funky
|
2013-10-14 21:32:12 +02:00
|
|
|
things.
|
2013-09-18 22:18:38 -07:00
|
|
|
</div>
|
|
|
|
<![endif]-->
|
|
|
|
|
2014-06-28 03:35:25 -07:00
|
|
|
{before_content}
|
|
|
|
|
2014-03-16 18:29:51 -04:00
|
|
|
<section class="sidebar">
|
2014-05-28 09:24:28 -07:00
|
|
|
{logo}
|
2013-09-18 22:18:38 -07:00
|
|
|
{sidebar}
|
|
|
|
</section>
|
|
|
|
|
2014-03-16 18:29:51 -04:00
|
|
|
<nav class="sub">
|
|
|
|
<form class="search-form js-only">
|
|
|
|
<div class="search-container">
|
|
|
|
<input class="search-input" name="search"
|
|
|
|
autocomplete="off"
|
2014-06-18 11:25:04 -07:00
|
|
|
placeholder="Click or press 'S' to search, '?' for more options..."
|
2014-04-18 11:08:34 +09:00
|
|
|
type="search">
|
2013-12-07 17:15:12 +01:00
|
|
|
</div>
|
2013-09-18 22:18:38 -07:00
|
|
|
</form>
|
|
|
|
</nav>
|
|
|
|
|
2014-03-16 18:29:51 -04:00
|
|
|
<section id='main' class="content {ty}">{content}</section>
|
|
|
|
<section id='search' class="content hidden"></section>
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2014-03-16 18:29:51 -04:00
|
|
|
<section class="footer"></section>
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2014-03-16 18:29:51 -04:00
|
|
|
<div id="help" class="hidden">
|
|
|
|
<div class="shortcuts">
|
2013-09-18 22:18:38 -07:00
|
|
|
<h1>Keyboard shortcuts</h1>
|
|
|
|
<dl>
|
|
|
|
<dt>?</dt>
|
|
|
|
<dd>Show this help dialog</dd>
|
|
|
|
<dt>S</dt>
|
|
|
|
<dd>Focus the search field</dd>
|
2014-06-18 11:25:04 -07:00
|
|
|
<dt>⇤</dt>
|
2013-09-18 22:18:38 -07:00
|
|
|
<dd>Move up in search results</dd>
|
2014-06-18 11:25:04 -07:00
|
|
|
<dt>⇥</dt>
|
2013-09-18 22:18:38 -07:00
|
|
|
<dd>Move down in search results</dd>
|
2014-06-14 11:03:34 -07:00
|
|
|
<dt>⏎</dt>
|
2013-09-18 22:18:38 -07:00
|
|
|
<dd>Go to active search result</dd>
|
|
|
|
</dl>
|
|
|
|
</div>
|
2014-03-16 18:29:51 -04:00
|
|
|
<div class="infos">
|
2013-09-18 22:18:38 -07:00
|
|
|
<h1>Search tricks</h1>
|
|
|
|
<p>
|
|
|
|
Prefix searches with a type followed by a colon (e.g.
|
|
|
|
<code>fn:</code>) to restrict the search to a given type.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Accepted types are: <code>fn</code>, <code>mod</code>,
|
|
|
|
<code>struct</code> (or <code>str</code>), <code>enum</code>,
|
|
|
|
<code>trait</code>, <code>typedef</code> (or
|
|
|
|
<code>tdef</code>).
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2014-03-16 01:08:56 -07:00
|
|
|
|
2014-06-28 03:35:25 -07:00
|
|
|
{after_content}
|
|
|
|
|
2014-03-16 01:08:56 -07:00
|
|
|
<script>
|
2014-06-06 09:12:18 -07:00
|
|
|
window.rootPath = "{root_path}";
|
|
|
|
window.currentCrate = "{krate}";
|
|
|
|
window.playgroundUrl = "{play_url}";
|
2014-03-16 01:08:56 -07:00
|
|
|
</script>
|
2014-03-16 18:29:51 -04:00
|
|
|
<script src="{root_path}jquery.js"></script>
|
|
|
|
<script src="{root_path}main.js"></script>
|
2014-06-06 09:12:18 -07:00
|
|
|
{play_js}
|
2014-03-16 18:29:51 -04:00
|
|
|
<script async src="{root_path}search-index.js"></script>
|
2013-09-18 22:18:38 -07:00
|
|
|
</body>
|
2014-04-18 11:08:34 +09:00
|
|
|
</html>"##,
|
2013-09-18 22:18:38 -07:00
|
|
|
content = *t,
|
|
|
|
root_path = page.root_path,
|
|
|
|
ty = page.ty,
|
2014-05-28 09:24:28 -07:00
|
|
|
logo = if layout.logo.len() == 0 {
|
|
|
|
"".to_string()
|
|
|
|
} else {
|
|
|
|
format!("<a href='{}{}/index.html'>\
|
|
|
|
<img src='{}' alt='' width='100'></a>",
|
|
|
|
page.root_path, layout.krate,
|
|
|
|
layout.logo)
|
|
|
|
},
|
2013-09-18 22:18:38 -07:00
|
|
|
title = page.title,
|
2014-05-28 09:24:28 -07:00
|
|
|
favicon = if layout.favicon.len() == 0 {
|
|
|
|
"".to_string()
|
|
|
|
} else {
|
|
|
|
format!(r#"<link rel="shortcut icon" href="{}">"#, layout.favicon)
|
|
|
|
},
|
2014-06-28 03:35:25 -07:00
|
|
|
in_header = layout.external_html.in_header,
|
|
|
|
before_content = layout.external_html.before_content,
|
|
|
|
after_content = layout.external_html.after_content,
|
2013-09-18 22:18:38 -07:00
|
|
|
sidebar = *sidebar,
|
2014-02-05 22:15:24 +01:00
|
|
|
krate = layout.krate,
|
2014-06-06 09:12:18 -07:00
|
|
|
play_url = layout.playground_url,
|
|
|
|
play_js = if layout.playground_url.len() == 0 {
|
|
|
|
"".to_string()
|
|
|
|
} else {
|
|
|
|
format!(r#"<script src="{}playpen.js"></script>"#, page.root_path)
|
|
|
|
},
|
2014-01-30 11:30:21 -08:00
|
|
|
)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
|
2014-05-29 13:50:47 -07:00
|
|
|
pub fn redirect(dst: &mut io::Writer, url: &str) -> io::IoResult<()> {
|
|
|
|
write!(dst,
|
|
|
|
r##"<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="refresh" content="0;URL={url}">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
</body>
|
|
|
|
</html>"##,
|
|
|
|
url = url,
|
|
|
|
)
|
|
|
|
}
|