Skip to content

Commit 2579419

Browse files
authored
Rollup merge of #108784 - clubby789:askama-sidebar, r=jsha,GuillaumeGomez
rustdoc: Migrate sidebar rendering to Askama cc #108757 Renders the sidebar for documentation using an Askama template
2 parents 949c553 + 2f166d1 commit 2579419

File tree

4 files changed

+616
-644
lines changed

4 files changed

+616
-644
lines changed

src/librustdoc/html/render/context.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ use super::print_item::{full_path, item_path, print_item};
1717
use super::search_index::build_index;
1818
use super::write_shared::write_shared;
1919
use super::{
20-
collect_spans_and_sources, print_sidebar, scrape_examples_help, sidebar_module_like, AllTypes,
21-
LinkFromSrc, StylePath,
20+
collect_spans_and_sources, scrape_examples_help,
21+
sidebar::print_sidebar,
22+
sidebar::{sidebar_module_like, Sidebar},
23+
AllTypes, LinkFromSrc, StylePath,
2224
};
23-
2425
use crate::clean::{self, types::ExternalLocation, ExternalCrate};
2526
use crate::config::{ModuleSorting, RenderOptions};
2627
use crate::docfs::{DocFS, PathError};
@@ -35,6 +36,7 @@ use crate::html::url_parts_builder::UrlPartsBuilder;
3536
use crate::html::{layout, sources, static_files};
3637
use crate::scrape_examples::AllCallLocations;
3738
use crate::try_err;
39+
use askama::Template;
3840

3941
/// Major driving force in all rustdoc rendering. This contains information
4042
/// about where in the tree-like hierarchy rendering is occurring and controls
@@ -600,15 +602,18 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
600602
};
601603
let all = shared.all.replace(AllTypes::new());
602604
let mut sidebar = Buffer::html();
603-
write!(sidebar, "<h2 class=\"location\"><a href=\"#\">Crate {}</a></h2>", crate_name);
604-
605-
let mut items = Buffer::html();
606-
sidebar_module_like(&mut items, all.item_sections());
607-
if !items.is_empty() {
608-
sidebar.push_str("<div class=\"sidebar-elems\">");
609-
sidebar.push_buffer(items);
610-
sidebar.push_str("</div>");
611-
}
605+
606+
let blocks = sidebar_module_like(all.item_sections());
607+
let bar = Sidebar {
608+
title_prefix: "Crate ",
609+
title: crate_name.as_str(),
610+
is_crate: false,
611+
version: "",
612+
blocks: vec![blocks],
613+
path: String::new(),
614+
};
615+
616+
bar.render_into(&mut sidebar).unwrap();
612617

613618
let v = layout::render(
614619
&shared.layout,

0 commit comments

Comments
 (0)