Skip to content

Commit

Permalink
Remove Topbar type and replace it with RustdocPage
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Aug 21, 2024
1 parent b4012b4 commit c900f94
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 50 deletions.
5 changes: 2 additions & 3 deletions src/utils/html.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::web::page::templates::{Body, Head, Topbar, Vendored};
use crate::web::rustdoc::RustdocPage;
use crate::web::page::templates::{Body, Head, RustdocPage, Vendored};
use lol_html::element;
use lol_html::errors::RewritingError;
use rinja::Template;
Expand All @@ -21,7 +20,7 @@ pub(crate) fn rewrite_lol(
let head_html = Head::new(data).render().unwrap();
let vendored_html = Vendored.render().unwrap();
let body_html = Body.render().unwrap();
let topbar_html = Topbar::new(data).render().unwrap();
let topbar_html = data.render().unwrap();

// Before: <body> ... rustdoc content ... </body>
// After:
Expand Down
45 changes: 15 additions & 30 deletions src/web/page/templates.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::error::Result;
use crate::web::crate_details::CrateDetails;
use crate::web::rustdoc::RustdocPage;
use crate::web::MetaData;
use anyhow::Context;
use rinja::Template;
use std::{fmt, ops::Deref, sync::Arc};
use std::{fmt, sync::Arc};
use tracing::trace;

#[derive(Template)]
Expand All @@ -31,34 +30,20 @@ pub struct Body;

#[derive(Template)]
#[template(path = "rustdoc/topbar.html")]
pub struct Topbar<'a> {
inner: &'a RustdocPage,
permalink_path: &'a str,
krate: &'a CrateDetails,
metadata: &'a MetaData,
current_target: &'a str,
latest_path: &'a str,
}

impl<'a> Topbar<'a> {
pub fn new(inner: &'a RustdocPage) -> Self {
Self {
inner,
permalink_path: &inner.permalink_path,
krate: &inner.krate,
metadata: &inner.metadata,
current_target: &inner.current_target,
latest_path: &inner.latest_path,
}
}
}

impl<'a> Deref for Topbar<'a> {
type Target = RustdocPage;

fn deref(&self) -> &Self::Target {
self.inner
}
#[derive(Debug, Clone)]
pub struct RustdocPage {
pub latest_path: String,
pub permalink_path: String,
pub inner_path: String,
// true if we are displaying the latest version of the crate, regardless
// of whether the URL specifies a version number or the string "latest."
pub is_latest_version: bool,
// true if the URL specifies a version using the string "latest."
pub is_latest_url: bool,
pub is_prerelease: bool,
pub krate: CrateDetails,
pub metadata: MetaData,
pub current_target: String,
}

/// Holds all data relevant to templating
Expand Down
19 changes: 2 additions & 17 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use crate::{
extractors::{DbConnection, Path},
file::File,
match_version,
page::templates::RustdocPage,
page::TemplateData,
MetaData, ReqVersion,
ReqVersion,
},
AsyncStorage, Config, InstanceMetrics, RUSTDOC_STATIC_STORAGE_PREFIX,
};
Expand Down Expand Up @@ -257,22 +258,6 @@ pub(crate) async fn rustdoc_redirector_handler(
}
}

#[derive(Debug, Clone)]
pub struct RustdocPage {
pub latest_path: String,
pub permalink_path: String,
pub inner_path: String,
// true if we are displaying the latest version of the crate, regardless
// of whether the URL specifies a version number or the string "latest."
pub is_latest_version: bool,
// true if the URL specifies a version using the string "latest."
pub is_latest_url: bool,
pub is_prerelease: bool,
pub krate: CrateDetails,
pub metadata: MetaData,
pub current_target: String,
}

impl RustdocPage {
fn into_response(
self,
Expand Down

0 comments on commit c900f94

Please sign in to comment.