|
| 1 | +#![allow(dead_code, unused_macros, unused_imports)] |
| 2 | +//! A basic UI component. Any other component can accept this |
| 3 | +//! as a parameter and render it. |
| 4 | +
|
| 5 | +use sailfish::TemplateOnce; |
| 6 | + |
| 7 | +#[derive(Default,Clone,TemplateOnce)] |
| 8 | +#[template(path ="components/component.html")] |
| 9 | +pubstructComponent{ |
| 10 | +pubvalue:String, |
| 11 | +} |
| 12 | + |
| 13 | +macro_rules! component{ |
| 14 | +($name:tt) =>{ |
| 15 | +implFrom<$name>forcrate::components::Component{ |
| 16 | +fn from(thing: $name) ->crate::components::Component{ |
| 17 | +use sailfish::TemplateOnce; |
| 18 | + |
| 19 | +crate::components::Component{ |
| 20 | + value: thing.render_once().unwrap(), |
| 21 | +} |
| 22 | +} |
| 23 | +} |
| 24 | +}; |
| 25 | + |
| 26 | +($name:tt, $lifetime:lifetime) =>{ |
| 27 | +impl<$lifetime>From<$name<$lifetime>>forcrate::components::Component{ |
| 28 | +fn from(thing: $name<$lifetime>) ->crate::components::Component{ |
| 29 | +use sailfish::TemplateOnce; |
| 30 | + |
| 31 | +crate::components::Component{ |
| 32 | + value: thing.render_once().unwrap(), |
| 33 | +} |
| 34 | +} |
| 35 | +} |
| 36 | +}; |
| 37 | +} |
| 38 | + |
| 39 | +pub(crate)use component; |
| 40 | + |
| 41 | +// Render any string. |
| 42 | +implFrom<&str>forComponent{ |
| 43 | +fnfrom(value:&str) ->Component{ |
| 44 | +Component{ |
| 45 | +value: value.to_owned(), |
| 46 | +} |
| 47 | +} |
| 48 | +} |
| 49 | + |
| 50 | +// Render any string. |
| 51 | +implFrom<String>forComponent{ |
| 52 | +fnfrom(value:String) ->Component{ |
| 53 | +Component{ value} |
| 54 | +} |
| 55 | +} |