1
- use crate :: web:: page:: TemplateData ;
1
+ use crate :: web:: page:: templates:: { Body , Head , Topbar , Vendored } ;
2
+ use crate :: web:: rustdoc:: RustdocPage ;
2
3
use lol_html:: element;
3
4
use lol_html:: errors:: RewritingError ;
4
- use tera :: Context ;
5
+ use rinja :: Template ;
5
6
6
7
/// Rewrite a rustdoc page to have the docs.rs topbar
7
8
///
@@ -12,17 +13,15 @@ use tera::Context;
12
13
pub ( crate ) fn rewrite_lol (
13
14
html : & [ u8 ] ,
14
15
max_allowed_memory_usage : usize ,
15
- ctx : Context ,
16
- templates : & TemplateData ,
16
+ data : & RustdocPage ,
17
17
) -> Result < Vec < u8 > , RewritingError > {
18
18
use lol_html:: html_content:: { ContentType , Element } ;
19
19
use lol_html:: { HtmlRewriter , MemorySettings , Settings } ;
20
20
21
- let templates = & templates. templates ;
22
- let tera_head = templates. render ( "rustdoc/head.html" , & ctx) . unwrap ( ) ;
23
- let tera_vendored_css = templates. render ( "rustdoc/vendored.html" , & ctx) . unwrap ( ) ;
24
- let tera_body = templates. render ( "rustdoc/body.html" , & ctx) . unwrap ( ) ;
25
- let tera_rustdoc_topbar = templates. render ( "rustdoc/topbar.html" , & ctx) . unwrap ( ) ;
21
+ let head_html = Head :: new ( data) . render ( ) . unwrap ( ) ;
22
+ let vendored_html = Vendored :: new ( data) . render ( ) . unwrap ( ) ;
23
+ let body_html = Body :: new ( data) . render ( ) . unwrap ( ) ;
24
+ let topbar_html = Topbar :: new ( data) . render ( ) . unwrap ( ) ;
26
25
27
26
// Before: <body> ... rustdoc content ... </body>
28
27
// After:
@@ -46,12 +45,12 @@ pub(crate) fn rewrite_lol(
46
45
rustdoc_body_class. set_attribute ( "tabindex" , "-1" ) ?;
47
46
// Change the `body` to a `div`
48
47
rustdoc_body_class. set_tag_name ( "div" ) ?;
49
- // Prepend the tera content
50
- rustdoc_body_class. prepend ( & tera_body , ContentType :: Html ) ;
48
+ // Prepend the rinja content
49
+ rustdoc_body_class. prepend ( & body_html , ContentType :: Html ) ;
51
50
// Wrap the transformed body and topbar into a <body> element
52
51
rustdoc_body_class. before ( r#"<body class="rustdoc-page">"# , ContentType :: Html ) ;
53
52
// Insert the topbar outside of the rustdoc div
54
- rustdoc_body_class. before ( & tera_rustdoc_topbar , ContentType :: Html ) ;
53
+ rustdoc_body_class. before ( & topbar_html , ContentType :: Html ) ;
55
54
// Finalize body with </body>
56
55
rustdoc_body_class. after ( "</body>" , ContentType :: Html ) ;
57
56
@@ -62,7 +61,7 @@ pub(crate) fn rewrite_lol(
62
61
element_content_handlers : vec ! [
63
62
// Append `style.css` stylesheet after all head elements.
64
63
element!( "head" , |head: & mut Element | {
65
- head. append( & tera_head , ContentType :: Html ) ;
64
+ head. append( & head_html , ContentType :: Html ) ;
66
65
Ok ( ( ) )
67
66
} ) ,
68
67
element!( "body" , body_handler) ,
@@ -81,7 +80,7 @@ pub(crate) fn rewrite_lol(
81
80
element!(
82
81
"link[rel='stylesheet'][href*='rustdoc-']" ,
83
82
|rustdoc_css: & mut Element | {
84
- rustdoc_css. before( & tera_vendored_css , ContentType :: Html ) ;
83
+ rustdoc_css. before( & vendored_html , ContentType :: Html ) ;
85
84
Ok ( ( ) )
86
85
}
87
86
) ,
0 commit comments