-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #89695 - jsha:more-templates, r=GuillaumeGomez
Move top part of print_item to Tera templates Part of #84419. This moves the first line of each item page (E.g. `Struct foo::Bar .... 1.0.0 [-][src]` into a Tera template. I also moved template initialization into its own module and added a small macro to reduce duplication and opportunity for errors.
- Loading branch information
Showing
6 changed files
with
113 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::error::Error as StdError; | ||
|
||
use crate::error::Error; | ||
|
||
pub(crate) fn load() -> Result<tera::Tera, Error> { | ||
let mut templates = tera::Tera::default(); | ||
|
||
macro_rules! include_template { | ||
($file:literal, $fullpath:literal) => { | ||
templates.add_raw_template($file, include_str!($fullpath)).map_err(|e| Error { | ||
file: $file.into(), | ||
error: format!("{}: {}", e, e.source().map(|e| e.to_string()).unwrap_or_default()), | ||
})? | ||
}; | ||
} | ||
|
||
include_template!("page.html", "../templates/page.html"); | ||
include_template!("print_item.html", "../templates/print_item.html"); | ||
Ok(templates) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<h1 class="fqn"> {#- -#} | ||
<span class="in-band"> {#- -#} | ||
{{-typ-}} | ||
{#- The breadcrumbs of the item path, like std::string -#} | ||
{%- for component in path_components -%} | ||
<a href="{{component.path | safe}}index.html">{{component.name}}</a>::<wbr> | ||
{%- endfor -%} | ||
<a class="{{item_type}}" href="#">{{name}}</a> {#- -#} | ||
<button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"> {#- -#} | ||
<img src="{{static_root_path | safe}}clipboard{{page.resource_suffix}}.svg" {# -#} | ||
width="19" height="18" {# -#} | ||
alt="Copy item path"> {#- -#} | ||
</button> {#- -#} | ||
</span> {#- -#} | ||
<span class="out-of-band"> {#- -#} | ||
{{- stability_since_raw | safe -}} | ||
<span id="render-detail"> {#- -#} | ||
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs"> {#- -#} | ||
[<span class="inner">−</span>] {#- -#} | ||
</a> {#- -#} | ||
</span> {#- -#} | ||
{%- if src_href -%} | ||
<a class="srclink" href="{{src_href | safe}}" title="goto source code">[src]</a> | ||
{%- endif -%} | ||
</span> {#- -#} | ||
</h1> {#- -#} |