Skip to content

Commit 008587f

Browse files
committed
feat(templs): embed gh live sample
1 parent 0919d7d commit 008587f

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::fmt::Write;
2+
3+
use rari_templ_func::rari_f;
4+
use rari_types::AnyArg;
5+
6+
use crate::error::DocError;
7+
8+
#[rari_f]
9+
pub fn embed_gh_live_sample(
10+
path: String,
11+
width: Option<AnyArg>,
12+
height: Option<AnyArg>,
13+
) -> Result<String, DocError> {
14+
let mut out = String::new();
15+
out.push_str("<iframe ");
16+
if let Some(width) = width {
17+
if !width.is_empty() {
18+
write!(&mut out, r#"width="{}" "#, width)?;
19+
}
20+
}
21+
if let Some(height) = height {
22+
if !height.is_empty() {
23+
write!(&mut out, r#"height="{}" "#, height)?;
24+
}
25+
}
26+
27+
out.extend([
28+
r#"src="https://mdn.github.io/"#,
29+
path.as_str(),
30+
r#""></iframe>"#,
31+
]);
32+
Ok(out)
33+
}

Diff for: crates/rari-doc/src/templ/templs/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod banners;
44
pub mod compat;
55
pub mod cssinfo;
66
pub mod csssyntax;
7+
pub mod embedghlivesample;
78
pub mod embedinteractiveexample;
89
pub mod glossary;
910
pub mod inheritance_diagram;
@@ -34,6 +35,7 @@ pub fn invoke(
3435
"glossary" => glossary::glossary_any,
3536
"csssyntax" => csssyntax::csssyntax_any,
3637
"embedinteractiveexample" => embedinteractiveexample::embed_interactive_example_any,
38+
"embedghlivesample" => embedghlivesample::embed_gh_live_sample_any,
3739
"listsubpages" => listsubpages::list_sub_pages_any,
3840
"listsubpagesgrouped" => listsubpages::list_sub_pages_grouped_any,
3941
"embedlivesample" => livesample::live_sample_any,

0 commit comments

Comments
 (0)