Skip to content

Commit bc2a857

Browse files
committed
feat(templs): more banners
1 parent aac156e commit bc2a857

File tree

4 files changed

+81
-37
lines changed

4 files changed

+81
-37
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use rari_templ_func::rari_f;
2+
use rari_types::AnyArg;
3+
use tracing::warn;
4+
5+
use crate::error::DocError;
6+
7+
#[rari_f]
8+
pub fn deprecated_header(version: Option<AnyArg>) -> Result<String, DocError> {
9+
if version.is_some() {
10+
warn!("Do not use deprectaed header with parameter!")
11+
}
12+
let title = rari_l10n::l10n_json_data("Template", "deprecated_badge_abbreviation", env.locale)?;
13+
let copy = rari_l10n::l10n_json_data("Template", "deprecated_header_copy", env.locale)?;
14+
15+
Ok([
16+
r#"<div class="notecard deprecated"><strong>"#,
17+
title,
18+
":</strong> ",
19+
copy,
20+
"</div>",
21+
]
22+
.join(""))
23+
}
24+
25+
#[rari_f]
26+
pub fn available_in_workers(typ: Option<String>) -> Result<String, DocError> {
27+
let default_typ = "available_in_worker__default";
28+
let typ = typ
29+
.map(|s| s.to_lowercase())
30+
.map(|typ| format!("available_in_worker__{typ}"));
31+
let copy = rari_l10n::l10n_json_data(
32+
"Template",
33+
typ.as_deref().unwrap_or(default_typ),
34+
env.locale,
35+
)
36+
.unwrap_or(rari_l10n::l10n_json_data(
37+
"Template",
38+
default_typ,
39+
env.locale,
40+
)?);
41+
42+
Ok([r#"<div class="notecard note"><p> "#, copy, "</p></div>"].join(""))
43+
}
44+
45+
#[rari_f]
46+
pub fn see_compat_table() -> Result<String, DocError> {
47+
let title =
48+
rari_l10n::l10n_json_data("Template", "experimental_badge_abbreviation", env.locale)?;
49+
let copy = rari_l10n::l10n_json_data("Template", "see_compat_table_copy", env.locale)?;
50+
51+
Ok([
52+
r#"<div class="notecard experimental"><strong>"#,
53+
title,
54+
":</strong> ",
55+
copy,
56+
"</div>",
57+
]
58+
.join(""))
59+
}
60+
61+
#[rari_f]
62+
pub fn secure_context_header() -> Result<String, DocError> {
63+
let title = rari_l10n::l10n_json_data("Template", "secure_context_label", env.locale)?;
64+
let copy = rari_l10n::l10n_json_data("Template", "secure_context_header_copy", env.locale)?;
65+
66+
Ok([
67+
r#"<div class="notecard secure"><strong>"#,
68+
&html_escape::encode_double_quoted_attribute(title),
69+
":</strong> ",
70+
copy,
71+
"</div>",
72+
]
73+
.join(""))
74+
}

crates/rari-doc/src/templ/templs/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod apiref;
22
pub mod badges;
3+
pub mod banners;
34
pub mod compat;
45
pub mod cssinfo;
56
pub mod csssyntax;
@@ -10,7 +11,6 @@ pub mod listsubpages;
1011
pub mod livesample;
1112
pub mod quick_links_with_subpages;
1213
pub mod secure_context;
13-
pub mod seecompattable;
1414
pub mod specification;
1515

1616
use rari_types::globals::deny_warnings;
@@ -44,10 +44,14 @@ pub fn invoke(
4444
"deprecated_inline" => badges::deprecated_any,
4545
"optional_inline" => badges::optional_any,
4646
"readonlyinline" => badges::readonly_any,
47-
"seecompattable" => seecompattable::see_compat_table_any,
48-
"securecontext_header" => secure_context::secure_context_header_any,
4947
"securecontext_inline" => secure_context::secure_context_inline_any,
5048

49+
//banners
50+
"seecompattable" => banners::see_compat_table_any,
51+
"securecontext_header" => banners::secure_context_header_any,
52+
"availableinworkers" => banners::available_in_workers_any,
53+
"deprecated_header" => banners::deprecated_header_any,
54+
5155
// links
5256
"csp" => links::csp::csp_any,
5357
"rfc" => links::rfc::rfc_any,

crates/rari-doc/src/templ/templs/secure_context.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,3 @@ pub fn secure_context_inline() -> Result<String, DocError> {
1616
]
1717
.join(""))
1818
}
19-
20-
#[rari_f]
21-
pub fn secure_context_header() -> Result<String, DocError> {
22-
let title = rari_l10n::l10n_json_data("Template", "secure_context_label", env.locale)?;
23-
let copy = rari_l10n::l10n_json_data("Template", "secure_context_header_copy", env.locale)?;
24-
25-
Ok([
26-
r#"<div class="notecard secure"><strong>"#,
27-
&html_escape::encode_double_quoted_attribute(title),
28-
":</strong> ",
29-
copy,
30-
"</div>",
31-
]
32-
.join(""))
33-
}

crates/rari-doc/src/templ/templs/seecompattable.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)