layout::render takes Print instead of fmt::Display
This commit is contained in:
parent
d5f147086b
commit
3f0e77f19c
4 changed files with 15 additions and 11 deletions
|
@ -99,7 +99,11 @@ impl Buffer {
|
||||||
self.into_inner()
|
self.into_inner()
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn display<T: fmt::Display>(&mut self, t: T) {
|
crate fn with_formatter<T: FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result>(&mut self, t: T) {
|
||||||
|
self.from_display(display_fn(move |f| (t)(f)));
|
||||||
|
}
|
||||||
|
|
||||||
|
crate fn from_display<T: std::fmt::Display>(&mut self, t: T) {
|
||||||
if self.for_html {
|
if self.for_html {
|
||||||
write!(self, "{}", t);
|
write!(self, "{}", t);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use std::fmt;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::externalfiles::ExternalHtml;
|
use crate::externalfiles::ExternalHtml;
|
||||||
|
@ -31,11 +30,11 @@ pub struct Page<'a> {
|
||||||
pub static_extra_scripts: &'a [&'a str],
|
pub static_extra_scripts: &'a [&'a str],
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render<T: fmt::Display, S: Print>(
|
pub fn render<T: Print, S: Print>(
|
||||||
layout: &Layout,
|
layout: &Layout,
|
||||||
page: &Page<'_>,
|
page: &Page<'_>,
|
||||||
sidebar: S,
|
sidebar: S,
|
||||||
t: &T,
|
t: T,
|
||||||
themes: &[PathBuf],
|
themes: &[PathBuf],
|
||||||
) -> String {
|
) -> String {
|
||||||
let static_root_path = page.static_root_path.unwrap_or(page.root_path);
|
let static_root_path = page.static_root_path.unwrap_or(page.root_path);
|
||||||
|
@ -175,7 +174,7 @@ pub fn render<T: fmt::Display, S: Print>(
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
},
|
},
|
||||||
content = *t,
|
content = Buffer::html().to_display(t),
|
||||||
static_root_path = static_root_path,
|
static_root_path = static_root_path,
|
||||||
root_path = page.root_path,
|
root_path = page.root_path,
|
||||||
css_class = page.css_class,
|
css_class = page.css_class,
|
||||||
|
|
|
@ -65,7 +65,7 @@ use crate::docfs::{DocFS, ErrorStorage, PathError};
|
||||||
use crate::doctree;
|
use crate::doctree;
|
||||||
use crate::fold::DocFolder;
|
use crate::fold::DocFolder;
|
||||||
use crate::html::escape::Escape;
|
use crate::html::escape::Escape;
|
||||||
use crate::html::format::{Print, Buffer, AsyncSpace, ConstnessSpace};
|
use crate::html::format::{Buffer, AsyncSpace, ConstnessSpace};
|
||||||
use crate::html::format::{GenericBounds, WhereClause, href, AbiSpace, DefaultSpace};
|
use crate::html::format::{GenericBounds, WhereClause, href, AbiSpace, DefaultSpace};
|
||||||
use crate::html::format::{VisSpace, Function, UnsafetySpace, MutableSpace};
|
use crate::html::format::{VisSpace, Function, UnsafetySpace, MutableSpace};
|
||||||
use crate::html::format::fmt_impl_for_trait_page;
|
use crate::html::format::fmt_impl_for_trait_page;
|
||||||
|
@ -1172,7 +1172,7 @@ themePicker.onblur = handleThemeButtonsBlur;
|
||||||
})
|
})
|
||||||
.collect::<String>());
|
.collect::<String>());
|
||||||
let v = layout::render(&cx.shared.layout,
|
let v = layout::render(&cx.shared.layout,
|
||||||
&page, "", &content,
|
&page, "", content,
|
||||||
&cx.shared.themes);
|
&cx.shared.themes);
|
||||||
cx.shared.fs.write(&dst, v.as_bytes())?;
|
cx.shared.fs.write(&dst, v.as_bytes())?;
|
||||||
}
|
}
|
||||||
|
@ -1919,7 +1919,7 @@ impl Context {
|
||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
let v = layout::render(&self.shared.layout,
|
let v = layout::render(&self.shared.layout,
|
||||||
&page, sidebar, &all,
|
&page, sidebar, |buf: &mut Buffer| buf.from_display(all),
|
||||||
&self.shared.themes);
|
&self.shared.themes);
|
||||||
self.shared.fs.write(&final_file, v.as_bytes())?;
|
self.shared.fs.write(&final_file, v.as_bytes())?;
|
||||||
|
|
||||||
|
@ -1935,7 +1935,7 @@ impl Context {
|
||||||
themes.push(PathBuf::from("settings.css"));
|
themes.push(PathBuf::from("settings.css"));
|
||||||
let v = layout::render(
|
let v = layout::render(
|
||||||
&self.shared.layout,
|
&self.shared.layout,
|
||||||
&page, sidebar, &settings,
|
&page, sidebar, |buf: &mut Buffer| buf.from_display(settings),
|
||||||
&themes);
|
&themes);
|
||||||
self.shared.fs.write(&settings_file, v.as_bytes())?;
|
self.shared.fs.write(&settings_file, v.as_bytes())?;
|
||||||
|
|
||||||
|
@ -1993,7 +1993,7 @@ impl Context {
|
||||||
if !self.render_redirect_pages {
|
if !self.render_redirect_pages {
|
||||||
layout::render(&self.shared.layout, &page,
|
layout::render(&self.shared.layout, &page,
|
||||||
|buf: &mut _| print_sidebar(self, it, buf),
|
|buf: &mut _| print_sidebar(self, it, buf),
|
||||||
&Item{ cx: self, item: it },
|
|buf: &mut Buffer| buf.from_display(Item { cx: self, item: it }),
|
||||||
&self.shared.themes)
|
&self.shared.themes)
|
||||||
} else {
|
} else {
|
||||||
let mut url = self.root_path();
|
let mut url = self.root_path();
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::fold::DocFolder;
|
||||||
use crate::html::layout;
|
use crate::html::layout;
|
||||||
use crate::html::render::{Error, SharedContext, BASIC_KEYWORDS};
|
use crate::html::render::{Error, SharedContext, BASIC_KEYWORDS};
|
||||||
use crate::html::highlight;
|
use crate::html::highlight;
|
||||||
|
use crate::html::format::Buffer;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Component, Path, PathBuf};
|
use std::path::{Component, Path, PathBuf};
|
||||||
|
@ -120,7 +121,7 @@ impl<'a> SourceCollector<'a> {
|
||||||
static_extra_scripts: &[&format!("source-script{}", self.scx.resource_suffix)],
|
static_extra_scripts: &[&format!("source-script{}", self.scx.resource_suffix)],
|
||||||
};
|
};
|
||||||
let v = layout::render(&self.scx.layout,
|
let v = layout::render(&self.scx.layout,
|
||||||
&page, "", &Source(contents),
|
&page, "", |buf: &mut Buffer| buf.from_display(Source(&contents)),
|
||||||
&self.scx.themes);
|
&self.scx.themes);
|
||||||
self.scx.fs.write(&cur, v.as_bytes())?;
|
self.scx.fs.write(&cur, v.as_bytes())?;
|
||||||
self.scx.local_sources.insert(p.clone(), href);
|
self.scx.local_sources.insert(p.clone(), href);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue