diff options
| author | bors <bors@rust-lang.org> | 2022-01-13 00:29:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-01-13 00:29:34 +0000 |
| commit | e916815d21e37af5cd85f9eb67cda155d7129fff (patch) | |
| tree | f3a0e11f2f7b560154d81fc022308ded90370d4f /src/librustdoc/html/render | |
| parent | 124555a69e5f65173ec7840000eb8e953d046740 (diff) | |
| parent | ef96d573bff12330080d22f12cad96b818ea5da7 (diff) | |
| download | rust-e916815d21e37af5cd85f9eb67cda155d7129fff.tar.gz rust-e916815d21e37af5cd85f9eb67cda155d7129fff.zip | |
Auto merge of #92526 - djc:rustdoc-askama, r=jsha
Migrate rustdoc from Tera to Askama See #84419. Should probably get a benchmarking run to verify if it has the intended effect on rustdoc performance. cc `@jsha` `@jyn514.`
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/context.rs | 12 | ||||
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 1 | ||||
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 17 | ||||
| -rw-r--r-- | src/librustdoc/html/render/templates.rs | 20 | ||||
| -rw-r--r-- | src/librustdoc/html/render/write_shared.rs | 9 |
5 files changed, 7 insertions, 52 deletions
diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 40453de8405..4f3455a9208 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -15,7 +15,6 @@ use rustc_span::symbol::sym; use super::print_item::{full_path, item_path, print_item}; use super::search_index::build_index; -use super::templates; use super::write_shared::write_shared; use super::{ collect_spans_and_sources, print_sidebar, settings, AllTypes, LinkFromSrc, NameDoc, StylePath, @@ -118,8 +117,6 @@ crate struct SharedContext<'tcx> { /// the crate. redirections: Option<RefCell<FxHashMap<String, String>>>, - pub(crate) templates: tera::Tera, - /// Correspondance map used to link types used in the source code pages to allow to click on /// links to jump to the type's definition. crate span_correspondance_map: FxHashMap<rustc_span::Span, LinkFromSrc>, @@ -218,11 +215,10 @@ impl<'tcx> Context<'tcx> { if !self.render_redirect_pages { layout::render( - &self.shared.templates, &self.shared.layout, &page, |buf: &mut _| print_sidebar(self, it, buf), - |buf: &mut _| print_item(self, &self.shared.templates, it, buf, &page), + |buf: &mut _| print_item(self, it, buf, &page), &self.shared.style_files, ) } else { @@ -391,7 +387,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { extension_css, resource_suffix, static_root_path, - generate_search_filter, unstable_features, generate_redirect_map, show_type_layout, @@ -421,12 +416,10 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { default_settings, krate: krate.name(tcx).to_string(), css_file_extension: extension_css, - generate_search_filter, scrape_examples_extension: !call_locations.is_empty(), }; let mut issue_tracker_base_url = None; let mut include_sources = true; - let templates = templates::load()?; // Crawl the crate attributes looking for attributes which control how we're // going to emit HTML @@ -481,7 +474,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { errors: receiver, redirections: if generate_redirect_map { Some(Default::default()) } else { None }, show_type_layout, - templates, span_correspondance_map: matches, cache, call_locations, @@ -577,7 +569,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { }; let all = self.shared.all.replace(AllTypes::new()); let v = layout::render( - &self.shared.templates, &self.shared.layout, &page, sidebar, @@ -599,7 +590,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { .map(StylePath::basename) .collect::<Result<_, Error>>()?; let v = layout::render( - &self.shared.templates, &self.shared.layout, &page, sidebar, diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index d63df4e4130..dda74904931 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -31,7 +31,6 @@ mod tests; mod context; mod print_item; mod span_map; -mod templates; mod write_shared; crate use self::context::*; diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 4f7bb39213b..11426cb6571 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -32,7 +32,7 @@ use crate::html::highlight; use crate::html::layout::Page; use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine}; -use serde::Serialize; +use askama::Template; const ITEM_TABLE_OPEN: &str = "<div class=\"item-table\">"; const ITEM_TABLE_CLOSE: &str = "</div>"; @@ -40,13 +40,13 @@ const ITEM_TABLE_ROW_OPEN: &str = "<div class=\"item-row\">"; const ITEM_TABLE_ROW_CLOSE: &str = "</div>"; // A component in a `use` path, like `string` in std::string::ToString -#[derive(Serialize)] struct PathComponent<'a> { path: String, name: &'a str, } -#[derive(Serialize)] +#[derive(Template)] +#[template(path = "print_item.html")] struct ItemVars<'a> { page: &'a Page<'a>, static_root_path: &'a str, @@ -58,13 +58,7 @@ struct ItemVars<'a> { src_href: Option<&'a str>, } -pub(super) fn print_item( - cx: &Context<'_>, - templates: &tera::Tera, - item: &clean::Item, - buf: &mut Buffer, - page: &Page<'_>, -) { +pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer, page: &Page<'_>) { debug_assert!(!item.is_stripped()); let typ = match *item.kind { clean::ModuleItem(_) => { @@ -143,8 +137,7 @@ pub(super) fn print_item( src_href: src_href.as_deref(), }; - let teractx = tera::Context::from_serialize(item_vars).unwrap(); - let heading = templates.render("print_item.html", &teractx).unwrap(); + let heading = item_vars.render().unwrap(); buf.write_str(&heading); match *item.kind { diff --git a/src/librustdoc/html/render/templates.rs b/src/librustdoc/html/render/templates.rs deleted file mode 100644 index d1f18239447..00000000000 --- a/src/librustdoc/html/render/templates.rs +++ /dev/null @@ -1,20 +0,0 @@ -use std::error::Error as StdError; - -use crate::error::Error; - -pub(crate) fn load() -> Result<tera::Tera, Error> { - let mut templates = tera::Tera::default(); - - macro_rules! include_template { - ($file:literal, $fullpath:literal) => { - templates.add_raw_template($file, include_str!($fullpath)).map_err(|e| Error { - file: $file.into(), - error: format!("{}: {}", e, e.source().map(|e| e.to_string()).unwrap_or_default()), - })? - }; - } - - include_template!("page.html", "../templates/page.html"); - include_template!("print_item.html", "../templates/print_item.html"); - Ok(templates) -} diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index 563f4ae7385..2e763dbd8fe 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -494,14 +494,7 @@ pub(super) fn write_shared( }) .collect::<String>() ); - let v = layout::render( - &cx.shared.templates, - &cx.shared.layout, - &page, - "", - content, - &cx.shared.style_files, - ); + let v = layout::render(&cx.shared.layout, &page, "", content, &cx.shared.style_files); cx.shared.fs.write(dst, v)?; } } |
