Move template initialization into its own file.

This commit is contained in:
Jacob Hoffman-Andrews
2021-10-08 23:25:54 -07:00
parent 7a938005e1
commit 586a9cea75
4 changed files with 23 additions and 15 deletions

View File

@@ -1,6 +1,5 @@
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::error::Error as StdError;
use std::io;
use std::path::{Path, PathBuf};
use std::rc::Rc;
@@ -16,6 +15,7 @@ use rustc_span::symbol::sym;
use super::cache::{build_index, ExternalLocation};
use super::print_item::{full_path, item_path, print_item};
use super::templates;
use super::write_shared::write_shared;
use super::{
collect_spans_and_sources, print_sidebar, settings, AllTypes, LinkFromSrc, NameDoc, StylePath,
@@ -33,7 +33,6 @@ use crate::formats::FormatRenderer;
use crate::html::escape::Escape;
use crate::html::format::Buffer;
use crate::html::markdown::{self, plain_text_summary, ErrorCodes, IdMap};
use crate::html::static_files::{PAGE, PRINT_ITEM};
use crate::html::{layout, sources};
/// Major driving force in all rustdoc rendering. This contains information
@@ -416,16 +415,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
};
let mut issue_tracker_base_url = None;
let mut include_sources = true;
let mut templates = tera::Tera::default();
templates.add_raw_template("page.html", PAGE).map_err(|e| Error {
file: "page.html".into(),
error: format!("{}: {}", e, e.source().map(|e| e.to_string()).unwrap_or_default()),
})?;
templates.add_raw_template("print_item.html", PRINT_ITEM).map_err(|e| Error {
file: "print_item.html".into(),
error: format!("{}: {}", e, e.source().map(|e| e.to_string()).unwrap_or_default()),
})?;
let templates = templates::load()?;
// Crawl the crate attributes looking for attributes which control how we're
// going to emit HTML