Skip to main content

topcoat_view/
lib.rs

1mod attribute;
2mod class;
3mod component;
4mod element;
5mod escape;
6mod format;
7mod length;
8mod node;
9mod props;
10pub mod svg;
11mod unescaped;
12mod view;
13
14pub use attribute::*;
15pub use class::*;
16pub use component::*;
17pub use element::*;
18pub use escape::*;
19pub use format::*;
20pub use length::*;
21pub use node::*;
22pub use props::*;
23pub use unescaped::*;
24pub use view::*;
25
26/// Macro helpers to shorten the generated source code.
27#[doc(hidden)]
28pub mod internal {
29    use topcoat_core::context::Cx;
30
31    use crate::{
32        Attribute, AttributeKeyViewParts, AttributeValueViewParts, AttributeViewParts,
33        ElementNameViewParts, HtmlContext, NodeViewParts, PartsWriter, Unescaped, View, ViewParts,
34    };
35
36    #[inline]
37    pub fn __unescaped(_cx: &Cx, parts: &mut ViewParts, s: &'static str) {
38        PartsWriter::new(parts, HtmlContext::Unescaped).push_str(s);
39    }
40
41    #[inline]
42    pub fn __view(_cx: &Cx, parts: &mut ViewParts, view: View) {
43        parts.push_view(view);
44    }
45
46    #[inline]
47    pub fn __node(cx: &Cx, parts: &mut ViewParts, node: impl NodeViewParts) {
48        node.into_view_parts(cx, &mut PartsWriter::new(parts, HtmlContext::Text));
49    }
50
51    #[inline]
52    pub fn __element_name(cx: &Cx, parts: &mut ViewParts, element_name: impl ElementNameViewParts) {
53        element_name.into_view_parts(cx, &mut PartsWriter::new(parts, HtmlContext::ElementName));
54    }
55
56    #[inline]
57    pub fn __attribute_key(
58        cx: &Cx,
59        parts: &mut ViewParts,
60        attribute_key: impl AttributeKeyViewParts,
61    ) {
62        attribute_key.into_view_parts(cx, &mut PartsWriter::new(parts, HtmlContext::AttributeKey));
63    }
64
65    #[inline]
66    pub fn __attribute_value(
67        cx: &Cx,
68        parts: &mut ViewParts,
69        attribute_value: impl AttributeValueViewParts,
70    ) {
71        attribute_value.into_view_parts(
72            cx,
73            &mut PartsWriter::new(parts, HtmlContext::AttributeValue),
74        );
75    }
76
77    #[inline]
78    pub fn __attribute(
79        cx: &Cx,
80        parts: &mut ViewParts,
81        (key, value): (impl AttributeKeyViewParts, impl AttributeValueViewParts),
82    ) {
83        __attributes(cx, parts, Attribute::new(key, value));
84    }
85
86    #[inline]
87    pub fn __attribute_unescaped(
88        cx: &Cx,
89        parts: &mut ViewParts,
90        (key, value): (&'static str, impl AttributeValueViewParts),
91    ) {
92        __attributes(
93            cx,
94            parts,
95            Attribute::new(Unescaped::new_unchecked(key), value),
96        );
97    }
98
99    #[inline]
100    pub fn __attributes(cx: &Cx, parts: &mut ViewParts, attributes: impl AttributeViewParts) {
101        // Whole-attribute values do their own context transitions between
102        // keys and values; the attribute-value context here is the safe
103        // default for any text pushed directly.
104        attributes.into_view_parts(
105            cx,
106            &mut PartsWriter::new(parts, HtmlContext::AttributeValue),
107        );
108    }
109}