-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking Issue for Rustdoc Askama Migration #108868
Comments
I'm working on |
I'm working on |
As part of this, I'd like to get rid of Rationale: Using Buffer was introduced as an alternative to In the original PR adding This is a summary of a similar comment I made on Zulip. |
Update on the above: I missed a few places where we use
I still think it makes sense to filter internally-generated HTML with a limited tag stripper, but it looks like we'll need to be able to actually emit the text rather than just count it, which means processing the entities (no big deal). |
FWIW, feel free to tag me in reviews if there are questions. Excited to see more usage of Askama in rustdoc!
As a potential point of interest, at work we have started using a very small procedural macro that effectively duplicates a template type to allow having two #[email(template = "contact-email")]
pub struct DomainContactEmail<'a> {
pub domain: &'a str,
pub sender: &'a ContactSender<'a>,
pub message: &'a str,
pub inbox_url: &'a str,
} expands to this: impl<'a: 'email, 'email> email::BodyTemplates<'email> for DomainContactEmail<'a> {
type Text = DomainContactEmailText<'a, 'email>;
type Html = DomainContactEmailHtml<'a, 'email>;
}
#[derive(askama::Template)]
#[template(path = "contact-email.txt")]
pub struct DomainContactEmailText<'a, 'email>(&'email DomainContactEmail<'a>);
impl<'a: 'email, 'email> From<&'email DomainContactEmail<'a>>
for DomainContactEmailText<'a, 'email>
{
fn from(email: &'email DomainContactEmail<'a>) -> Self {
Self(email)
}
}
impl<'a: 'email, 'email> std::ops::Deref for DomainContactEmailText<'a, 'email> {
type Target = &'email DomainContactEmail<'a>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(askama::Template)]
#[template(path = "contact-email.html")]
pub struct DomainContactEmailHtml<'a, 'email>(&'email DomainContactEmail<'a>);
impl<'a: 'email, 'email> std::ops::Deref for DomainContactEmailHtml<'a, 'email> {
type Target = &'email DomainContactEmail<'a>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'a: 'email, 'email> From<&'email DomainContactEmail<'a>>
for DomainContactEmailHtml<'a, 'email>
{
fn from(email: &'email DomainContactEmail<'a>) -> Self {
Self(email)
}
} Maybe this is used too much/duplicating the templates would be too much work for Rustdoc, just thought I'd mention it here as a point in the design space. |
I'm working on changing primitive_link_fragment, href_relative_parts, and href_with_root_path to use a template to construct the hrefs with fewer allocations. And thanks for the proc macro advice, and the kind offer of assistance, @djc! |
…meGomez Render source page layout with Askama ~~I was looking at making `code_html` render into the buffer instead of in advance, but it turned out to need a pretty big refactor, so starting with rearranging the high-level layout.~~ Found another approach which required much less changes cc rust-lang#108868
…meGomez Render source page layout with Askama ~~I was looking at making `code_html` render into the buffer instead of in advance, but it turned out to need a pretty big refactor, so starting with rearranging the high-level layout.~~ Found another approach which required much less changes cc rust-lang#108868
rustdoc: use a template to generate Hrefs Previously, href always returned a string, so each link incurred at least one allocation. We were also using `"../".repeat()`, and `.collect()` into strings to generate part of the paths. This abstracts away those repetitions into a couple of helper structs, ParentDirectories and PathComponents, and puts them together into an `Href` template, which should save some allocations. As a side benefit, I think it makes the logic of constructing links a little clearer. This removes the only call sites for certain methods of UrlPartsBuilder, so it also removes those methods. Also, remove the ItemType return value from `href` and friends; it was basically unused. Part of rust-lang#108868
…omez Migrate `item_static` to Askama This pull request addresses the type signature of the item_static function in our codebase. Previously, this function accepted a mutable reference to a Buffer for writing output. The current changes modify this to instead accept a mutable reference to any type that implements the Write trait. Referes rust-lang#108868
…it, r=GuillaumeGomez rustdoc: Add `ItemTemplate` trait and related functions to avoid repetitively wrapping existing functions Context: rust-lang#111430 (comment) This trait will be used extensively in performing migrations to Askama templates (tracking issue: rust-lang#108868)
…llaumeGomez Migrate `item_foreign_type` to Askama This PR continues the migration of `print_item.rs` functions to Askama. This piece of work migrates the function `item_foreign_type` Refers rust-lang#108868
…llaumeGomez Migrate `item_proc_macro` to Askama This PR migrates `item_proc_macro` to Askama Refers rust-lang#108868
…llaumeGomez Migrate `item_proc_macro` to Askama This PR migrates `item_proc_macro` to Askama Refers rust-lang#108868
…aumeGomez Migrate `item_trait_alias` to Askama This PR migrates `item_trait_alias` to Askama Refers rust-lang#108868
…uillaumeGomez Migrate `item_primitive` to Askama This PR migrates `item_primitive` to Askama Refers rust-lang#108868
…laumeGomez Migrate `item_opaque_ty` to Askama This PR migrates `item_opaque_ty` to Askama Refers: rust-lang#108868
Migrate `item_trait_alias` to Askama This PR migrates `item_trait_alias` to Askama Refers rust-lang/rust#108868
…omez Migrate `item_primitive` to Askama This PR migrates `item_primitive` to Askama Refers rust-lang/rust#108868
we are migrating to askama see rust-lang#108868
we are migrating to askama see rust-lang#108868
we are migrating to askama see rust-lang#108868
…omez Migrate `item_primitive` to Askama This PR migrates `item_primitive` to Askama Refers rust-lang/rust#108868
…omez Migrate `item_primitive` to Askama This PR migrates `item_primitive` to Askama Refers rust-lang/rust#108868
@clubby789 can I please ask you to update the current status of components? |
Tracking Issue for Rustdoc Askama Migration
Zulip Discussion
This issue is to track the progress of migrating rustdoc's HTML rendering to Askama.
Suggested Workflow
If you'd like to work on a component, please leave a comment claiming it so that work doesn't conflict.
Work on translating the current series of
format!()
and string building calls into an HTML template. Where possible, try to keep as much logic as possible on the Rust side. Make sure to refer toSTYLE.md
for templating style, especially using comment blocks to minimize whitespace.A specific example of a migration (and some style considerations) is here.
Components to Migrate
document_item_info
to Askama #108757)print_item.rs
)item_proc_macro
to Askama #112031)item_primitive
to Askama #112032)item_foreign_type
to Askama #112005)Keywordsitem_opaque_ty
to Askama #112034)item_trait_alias
to Askama #112030)Implementation History
@rustbot label +T-rustdoc +A-rustdoc-ui
The text was updated successfully, but these errors were encountered: