use malevich::Theme;
use super::render::Renderable;
use super::{html, render};
use crate::{Run, Symbol, Value};
#[allow(private_bounds)]
impl<Data: Renderable> Value<'_, Data> {
pub fn to_html(&self, theme: Theme) -> String {
let Some(payload) = self.payload() else {
let header = format!(
"value \u{b7} {} \u{b7} not yet computed",
render::shape_text(&self.shape())
);
return html::card(
theme,
&html::escape(&header),
"<div>run <code>forward</code> to give this value a payload</div>",
);
};
render::payload_card(theme, "value", &payload)
}
pub fn evcxr_display(&self) {
let plain = match self.payload() {
Some(payload) => render::payload_text("value", &payload),
None => format!(
"value {} not yet computed",
render::shape_text(&self.shape())
),
};
html::show(&self.to_html(Theme::detect()), &plain);
}
}
impl Symbol {
pub fn to_html(&self, theme: Theme) -> String {
html::card(
theme,
"symbol",
"<div>a detached name; <code>network.resolve(symbol)</code> \
reads it in any compatible generation</div>",
)
}
pub fn evcxr_display(&self) {
html::show(
&self.to_html(Theme::detect()),
"symbol \u{b7} resolve it against a network to read a payload",
);
}
}
#[allow(private_bounds)]
impl<Data: Renderable> Run<Data> {
pub fn to_html(&self, theme: Theme) -> String {
super::field::profile_card(theme, "run", self.field())
}
pub fn evcxr_display(&self) {
html::show(
&self.to_html(Theme::detect()),
&super::field::profile_text("run", self.field()),
);
}
}
#[cfg(test)]
#[path = "tests/value_tests.rs"]
mod tests;