duid_core/core/html/attributes/
attribute_macros.rs

1use crate::core::html::attributes::{AttributeValue, Value, attr};
2
3
4#[macro_export]
5macro_rules! declare_attributes {
6    ( $(
7         $(#[$attr:meta])*
8         $name:ident;
9       )*
10     ) => {
11        $(
12            doc_comment::doc_comment!{
13                concat!("Creates html [",stringify!($name),"](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/",stringify!($name),") attribute"),
14
15                $(#[$attr])*
16                #[inline]
17                #[allow(non_snake_case)]
18                pub fn $name<V, MSG>(v: V) -> crate::core::html::attributes::Attribute<MSG>
19                    where V: Into<Value>,
20                    {
21                        attr(stringify!($name), AttributeValue::<MSG>::from_value(v.into()))
22                }
23            }
24         )*
25
26    };
27    ( $(
28         $(#[$attr:meta])*
29         $name:ident => $attribute:tt;
30       )*
31     ) => {
32        $(
33            doc_comment::doc_comment!{
34                concat!("Creates html [",$attribute,"](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/",$attribute,") attribute"),
35                $(#[$attr])*
36                #[inline]
37                #[allow(non_snake_case)]
38                pub fn $name<V, MSG>(v: V) -> crate::core::html::attributes::Attribute<MSG>
39                    where V: Into<Value>,
40                    {
41                        attr($attribute, AttributeValue::<MSG>::from_value(v.into()))
42                }
43             }
44         )*
45    }
46}
47
48macro_rules! declare_html_attributes{
49    ( $(
50         $(#[$attr:meta])*
51         $name:ident;
52       )*
53     ) => {
54        declare_attributes!{ $($name;)*}
55
56        #[cfg(feature = "with-lookup")]
57        pub const HTML_ATTRS:[&'static str; 115] = [$(stringify!($name),)*];
58    }
59}
60
61macro_rules! declare_html_attributes_special{
62    ( $(
63         $(#[$attr:meta])*
64         $name:ident => $attribute:tt;
65       )*
66     ) => {
67        declare_attributes!{ $($name => $attribute;)*}
68
69        #[cfg(feature = "with-lookup")]
70        pub const HTML_ATTRS_SPECIAL:[(&'static str,&'static str); 8] = [$((stringify!($name),$attribute),)*];
71    }
72}
73
74declare_html_attributes! {
75    accept;
76    accesskey;
77    action;
78    align;
79    allow;
80    alt;
81    autocapitalize;
82    autocomplete;
83    autofocus;
84    autoplay;
85    background;
86    bgcolor;
87    border;
88    buffered;
89    challenge;
90    charset;
91    cite;
92    class;
93    codebase;
94    color;
95    cols;
96    colspan;
97    content;
98    contenteditable;
99    contextmenu;
100    controls;
101    coords;
102    crossorigin;
103    csp;
104    data;
105    datetime;
106    decoding;
107    default;
108    defer;
109    dir;
110    dirname;
111    download;
112    draggable;
113    dropzone;
114    enctype;
115    enterkeyhint;
116    formaction;
117    formnovalidate;
118    headers;
119    height;
120    hidden;
121    high;
122    href;
123    hreflang;
124    http;
125    icon;
126    id;
127    importance;
128    integrity;
129    intrinsicsize;
130    inputmode;
131    ismap;
132    itemprop;
133    keytype;
134    kind;
135    lang;
136    language;
137    loading;
138    list;
139    low;
140    manifest;
141    max;
142    maxlength;
143    minlength;
144    media;
145    method;
146    min;
147    multiple;
148    muted;
149    name;
150    novalidate;
151    open;
152    optimum;
153    pattern;
154    ping;
155    placeholder;
156    poster;
157    preload;
158    radiogroup;
159    readonly;
160    referrerpolicy;
161    rel;
162    required;
163    reversed;
164    rows;
165    rowspan;
166    sandbox;
167    scope;
168    scoped;
169    selected;
170    shape;
171    size;
172    sizes;
173    slot;
174    spellcheck;
175    src;
176    srcdoc;
177    srclang;
178    srcset;
179    start;
180    step;
181    summary;
182    tabindex;
183    target;
184    title;
185    translate;
186    usemap;
187    value;
188    width;
189    wrap;
190}
191
192declare_html_attributes_special! {
193    accept_charset => "accept-charset";
194
195    r#async => "async";
196
197    r#for => "for";
198
199    font_family => "font-family";
200    font_size => "font-size";
201    flex_direction => "flex-direction";
202
203    r#loop => "loop";
204
205    r#type => "type";
206}