cabin/html/elements/
object.rs

1use std::borrow::Cow;
2
3use cabin_macros::Attribute;
4
5use super::button::Form;
6use super::common::Common;
7use super::global::Global;
8use super::iframe::Name;
9use super::input::{Height, Width};
10use super::link::Type;
11use crate::html::attributes::{Attributes, WithAttribute};
12use crate::html::{Aria, Html};
13use crate::View;
14
15/// The `object` element can represent an external resource, which, depending on the type of the
16/// resource, will either be treated as an image or as a child navigable.
17pub fn object(content: impl View) -> Html<marker::Object, (), impl View> {
18    #[cfg(debug_assertions)]
19    let content = content.boxed();
20    Html::new("object", (), content)
21}
22
23pub mod marker {
24    pub struct Object;
25}
26
27impl<A: Attributes, V: 'static> Object for Html<marker::Object, A, V> {}
28impl<A: Attributes, V: 'static> Common for Html<marker::Object, A, V> {}
29impl<A: Attributes, V: 'static> Global for Html<marker::Object, A, V> {}
30impl<A: Attributes, V: 'static> Aria for Html<marker::Object, A, V> {}
31
32/// The `object` element can represent an external resource, which, depending on the type of the
33/// resource, will either be treated as an image or as a child navigable.
34pub trait Object: WithAttribute {
35    /// Address of the resource.
36    fn data(self, data: impl Into<Cow<'static, str>>) -> Self::Output<Data> {
37        self.with_attribute(Data(data.into()))
38    }
39
40    /// Type of embedded resource.
41    fn r#type(self, r#type: impl Into<Cow<'static, str>>) -> Self::Output<Type> {
42        self.with_attribute(Type(r#type.into()))
43    }
44
45    /// Name of content navigable.
46    fn name(self, name: impl Into<Cow<'static, str>>) -> Self::Output<Name> {
47        self.with_attribute(Name(name.into()))
48    }
49
50    /// Associates the element with a [super::form] element.
51    fn form(self, form: impl Into<Cow<'static, str>>) -> Self::Output<Form> {
52        self.with_attribute(Form(form.into()))
53    }
54
55    /// Horizontal dimension.
56    fn width(self, width: u32) -> Self::Output<Width> {
57        self.with_attribute(Width(width))
58    }
59
60    /// Vertical dimension.
61    fn height(self, height: u32) -> Self::Output<Height> {
62        self.with_attribute(Height(height))
63    }
64}
65
66/// Address of the resource.
67#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
68pub struct Data(pub Cow<'static, str>);