Skip to content

Commit

Permalink
feat(templ): new embedlivesample iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Nov 21, 2024
1 parent 5660801 commit e5382ca
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions crates/rari-doc/src/templ/templs/embeds/livesample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt::Write;

use rari_templ_func::rari_f;
use rari_types::AnyArg;
use rari_utils::concat_strs;

use crate::error::DocError;
use crate::templ::api::RariApi;
Expand All @@ -21,11 +22,13 @@ pub fn live_sample(
let title = dedup_whitespace(&id.replace('_', " "));
let id = RariApi::anchorize(&id);
let mut out = String::new();
out.push_str(r#"<div class="code-example"><div class="example-header"></div><iframe class="sample-code-frame" title=""#);
out.push_str(&html_escape::encode_quoted_attribute(&title));
out.push_str(r#" sample" id="frame_"#);
out.push_str(&id);
out.push_str(r#"" "#);
out.extend([
r#"<div class="code-example"><div class="example-header"></div><iframe class="sample-code-frame" title=""#,
&html_escape::encode_quoted_attribute(&title),
r#" sample" id="frame_"#,
&id,
r#"" "#
]);
if let Some(width) = width {
if !width.is_empty() {
write!(&mut out, r#"width="{}" "#, width)?;
Expand All @@ -41,18 +44,17 @@ pub fn live_sample(
}
}
}
write!(
&mut out,
r#"src="{}{}{}runner.html?id={}" "#,
RariApi::live_sample_base_url(),
out.extend([
r#"src="about:blank" data-live-path=""#,
env.url,
if env.url.ends_with('/') { "" } else { "/" },
id
)?;
r#"" data-live-id=""#,
&id,
r#"" "#,
]);
if let Some(allowed_features) = allowed_features {
write!(&mut out, r#"allow="{}" "#, allowed_features)?;
}
out.push_str(r#"sandbox="allow-same-origin allow-scripts" "#);
out.push_str(r#"loading="lazy"></iframe></div>"#);
out.push_str(r#"sandbox="allow-same-origin allow-scripts" loading="lazy"></iframe></div>"#);
Ok(out)
}

0 comments on commit e5382ca

Please sign in to comment.