Skip to content

Commit 4e2cb85

Browse files
committed
fmt
1 parent a8ae698 commit 4e2cb85

22 files changed

+259
-209
lines changed

build/src/codegen.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use crate::ty::Type;
2-
use crate::{utils, Component, Property};
31
use convert_case::{Case, Casing};
42
use eyre::ensure;
53
use proc_macro2::{Ident, Span, TokenStream};
64
use quote::quote;
75

6+
use crate::ty::Type;
7+
use crate::{utils, Component, Property};
8+
89
pub fn gen_component(component_name: &str, mut variants: Vec<Component>) -> String {
910
if variants.len() == 1 {
1011
let mut component = variants.pop().unwrap();
@@ -211,7 +212,11 @@ fn gen_prop_assignment(output: &mut String, p: &Property) {
211212
output.push_str(&p.property);
212213
output.push_str("={");
213214
let value = p.property.to_case(Case::Snake).replace("ty", "type");
214-
if p.property == "disabled" || p.property == "required" || p.property == "open" || p.property == "selected" {
215+
if p.property == "disabled"
216+
|| p.property == "required"
217+
|| p.property == "open"
218+
|| p.property == "selected"
219+
{
215220
output.push_str("props.");
216221
output.push_str(&value);
217222
output.push_str(".unwrap_or_default()");
@@ -236,7 +241,7 @@ impl Property {
236241
let d = self.default.as_ref()?;
237242
let mut d = d.replace("'", "\"");
238243
if d == "undefined" {
239-
return Some(syn::parse_quote!(None))
244+
return Some(syn::parse_quote!(None));
240245
} else if d.contains(".") {
241246
d = format!("{d:?}")
242247
}
@@ -247,6 +252,7 @@ impl Property {
247252
let expr = syn::parse_str::<syn::Expr>(&d).ok()?;
248253
Some(syn::parse_quote!(Some(#expr)))
249254
}
255+
250256
fn to_tokens(&self) -> TokenStream {
251257
let name = Ident::new(
252258
&self.property.to_case(Case::Snake).replace("ty", "type"),

build/src/main.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ mod codegen;
22
mod ty;
33
mod utils;
44

5-
use crate::ty::Type;
6-
use crate::utils::IterExt;
5+
use std::collections::HashMap;
6+
use std::path::Path;
7+
78
use color_eyre::Section;
89
use convert_case::{Case, Casing};
910
use eyre::{bail, ensure, eyre, ContextCompat, Report};
1011
use pulldown_cmark::{CowStr, Event, HeadingLevel, Options, Parser, Tag};
1112
use serde::Deserialize;
12-
use std::collections::HashMap;
13-
use std::path::Path;
13+
14+
use crate::ty::Type;
15+
use crate::utils::IterExt;
1416

1517
#[derive(Debug, Clone, Deserialize, PartialEq)]
1618
#[serde(rename_all = "PascalCase")]
@@ -105,7 +107,11 @@ fn main() -> eyre::Result<()> {
105107
let component = codegen::gen_component(&component_name, components);
106108
let component = utils::format_tokens(component)?;
107109
std::fs::write(
108-
format!("{}/../src/{}.rs", env!("CARGO_MANIFEST_DIR"), component_name.to_case(Case::Snake)),
110+
format!(
111+
"{}/../src/{}.rs",
112+
env!("CARGO_MANIFEST_DIR"),
113+
component_name.to_case(Case::Snake)
114+
),
109115
component,
110116
)
111117
.unwrap();
@@ -210,19 +216,28 @@ fn extract_data_from_md_table<'a>(
210216
[Event::Start(Tag::TableCell), contents @ .., Event::End(Tag::TableCell)] => {
211217
let mut buf = String::new();
212218
if *header == CowStr::Borrowed("Description") {
213-
pulldown_cmark::html::push_html(&mut buf, contents.iter().map(|e| (*e).clone()));
219+
pulldown_cmark::html::push_html(
220+
&mut buf,
221+
contents.iter().map(|e| (*e).clone()),
222+
);
214223
} else {
215224
for txt in contents {
216225
match txt {
217226
Event::Text(t) => buf.push_str(t),
218227
Event::Code(t) => buf.push_str(t),
219-
actual => bail!("expected Text or Code, found {:?} as value for {header}", actual),
228+
actual => bail!(
229+
"expected Text or Code, found {:?} as value for {header}",
230+
actual
231+
),
220232
}
221233
}
222234
}
223235
properties.insert(header.clone(), buf);
224236
}
225-
c => bail!("expected at least 2 elements (Start, .., End) defining a table cell; found {c:?}"),
237+
c => bail!(
238+
"expected at least 2 elements (Start, .., End) defining a table cell; found \
239+
{c:?}"
240+
),
226241
}
227242
}
228243
entries.push(properties)

build/src/ty.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@ use serde::Deserialize;
44
#[derive(Debug, Clone, Deserialize, PartialEq)]
55
pub struct Type(pub String);
66

7-
87
impl Type {
98
pub fn is_string(&self) -> bool {
109
self.0 == "string"
1110
}
11+
1212
fn convert_ts_to_rust(ty: &str) -> &str {
1313
match ty {
1414
"boolean" => "bool",
1515
"string" => "AttrValue",
1616
"number" => "usize",
1717
// mappings for web_sys types
1818
"HTMLElement & Partial<SurfacePositionTarget>" => "web_sys::HtmlElement",
19-
ty => ty
19+
ty => ty,
2020
}
2121
}
22+
2223
pub(crate) fn as_type(&self) -> syn::Type {
2324
let ty = Self::convert_ts_to_rust(&self.0);
2425
syn::parse_str(ty).unwrap()
2526
}
26-
}
27+
}

build/src/utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use std::io::Write;
12
use std::process::{Command, Stdio};
23
use std::thread;
3-
use std::io::Write;
4+
45
use eyre::{ContextCompat, WrapErr};
56

67
pub fn chunk_with<I>(iter: impl Iterator<Item = I>, callback: impl Fn(&I) -> bool) -> Vec<Vec<I>> {

src/button.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,36 @@ impl ButtonVariants {
2424

2525
#[derive(Properties, PartialEq)]
2626
pub struct Props {
27-
#[doc = "Whether or not the button is disabled."]
27+
/// Whether or not the button is disabled.
2828
#[prop_or(Some(false))]
2929
pub disabled: Option<bool>,
30-
#[doc = "The URL that the link button points to."]
30+
/// The URL that the link button points to.
3131
#[prop_or(Some(AttrValue::Static("")))]
3232
pub href: Option<AttrValue>,
33-
#[doc = "Where to display the linked <code>href</code> URL for a link button. Common options include <code>_blank</code> to open in a new tab."]
33+
/// Where to display the linked <code>href</code> URL for a link button. Common options include
34+
/// <code>_blank</code> to open in a new tab.
3435
#[prop_or(Some(AttrValue::Static("")))]
3536
pub target: Option<AttrValue>,
36-
#[doc = "Whether to render the icon at the inline end of the label rather than the inline start.<br><em>Note:</em> Link buttons cannot have trailing icons."]
37+
/// Whether to render the icon at the inline end of the label rather than the inline
38+
/// start.<br><em>Note:</em> Link buttons cannot have trailing icons.
3739
#[prop_or(Some(false))]
3840
pub trailing_icon: Option<bool>,
39-
#[doc = "Whether to display the icon or not."]
41+
/// Whether to display the icon or not.
4042
#[prop_or(Some(false))]
4143
pub has_icon: Option<bool>,
42-
#[doc = ""]
44+
///
4345
#[prop_or(Some(AttrValue::Static("submit")))]
4446
pub typepe: Option<AttrValue>,
45-
#[doc = ""]
47+
///
4648
#[prop_or(Some(AttrValue::Static("")))]
4749
pub value: Option<AttrValue>,
48-
#[doc = ""]
50+
///
4951
#[prop_or(Some(AttrValue::Static("")))]
5052
pub name: Option<AttrValue>,
51-
#[doc = ""]
53+
///
5254
# [prop_or (Some (wasm_bindgen::JsValue::NULL . into ()))]
5355
pub form: Option<HTMLFormElement>,
54-
#[doc = "The variant to use."]
56+
/// The variant to use.
5557
pub variant: ButtonVariants,
5658
pub children: Html,
5759
#[prop_or(None)]

src/checkbox.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
11
use wasm_bindgen::JsValue;
2+
use web_sys::{HtmlFormElement as HTMLFormElement, NodeList};
23
use yew::prelude::*;
3-
use web_sys::HtmlFormElement as HTMLFormElement;
4-
use web_sys::NodeList;
54

65
type ValidityState = JsValue;
76

87
#[derive(Properties, PartialEq)]
98
pub struct Props {
10-
#[doc = "Whether or not the checkbox is selected."]
9+
/// Whether or not the checkbox is selected.
1110
#[prop_or(Some(false))]
1211
pub checked: Option<bool>,
13-
#[doc = "Whether or not the checkbox is disabled."]
12+
/// Whether or not the checkbox is disabled.
1413
#[prop_or(Some(false))]
1514
pub disabled: Option<bool>,
16-
#[doc = "Whether or not the checkbox is indeterminate.<br>https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#indeterminate_state_checkboxes"]
15+
/// Whether or not the checkbox is indeterminate.<br>https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#indeterminate_state_checkboxes
1716
#[prop_or(Some(false))]
1817
pub indeterminate: Option<bool>,
19-
#[doc = "When true, require the checkbox to be selected when participating in form submission.<br>https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#validation"]
18+
/// When true, require the checkbox to be selected when participating in form submission.<br>https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#validation
2019
#[prop_or(Some(false))]
2120
pub required: Option<bool>,
22-
#[doc = "The value of the checkbox that is submitted with a form when selected.<br>https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value"]
21+
/// The value of the checkbox that is submitted with a form when selected.<br>https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value
2322
#[prop_or(Some(AttrValue::Static("on")))]
2423
pub value: Option<AttrValue>,
25-
#[doc = ""]
24+
///
2625
#[prop_or(None)]
2726
pub name: Option<AttrValue>,
28-
#[doc = ""]
27+
///
2928
#[prop_or(None)]
3029
pub form: Option<HTMLFormElement>,
31-
#[doc = ""]
30+
///
3231
#[prop_or(None)]
3332
pub labels: Option<NodeList>,
34-
#[doc = ""]
33+
///
3534
#[prop_or(None)]
3635
pub validitype: Option<ValidityState>,
37-
#[doc = ""]
36+
///
3837
#[prop_or(None)]
3938
pub validation_message: Option<AttrValue>,
40-
#[doc = ""]
39+
///
4140
#[prop_or(None)]
4241
pub will_validate: Option<bool>,
4342
#[prop_or(None)]

src/chip.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,26 @@ impl ChipVariants {
2121

2222
#[derive(Properties, PartialEq)]
2323
pub struct Props {
24-
#[doc = ""]
24+
///
2525
#[prop_or(Some(false))]
2626
pub elevated: Option<bool>,
27-
#[doc = ""]
27+
///
2828
#[prop_or(Some(AttrValue::Static("")))]
2929
pub href: Option<AttrValue>,
30-
#[doc = ""]
30+
///
3131
#[prop_or(Some(AttrValue::Static("")))]
3232
pub target: Option<AttrValue>,
33-
#[doc = "Whether or not the chip is disabled.<br>Disabled chips are not focusable, unless <code>always-focusable</code> is set."]
33+
/// Whether or not the chip is disabled.<br>Disabled chips are not focusable, unless
34+
/// <code>always-focusable</code> is set.
3435
#[prop_or(Some(false))]
3536
pub disabled: Option<bool>,
36-
#[doc = "When true, allow disabled chips to be focused with arrow keys.<br>Add this when a chip needs increased visibility when disabled. See https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_disabled_controls for more guidance on when this is needed."]
37+
/// When true, allow disabled chips to be focused with arrow keys.<br>Add this when a chip needs increased visibility when disabled. See https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_disabled_controls for more guidance on when this is needed.
3738
#[prop_or(Some(false))]
3839
pub always_focusable: Option<bool>,
39-
#[doc = "The label of the chip."]
40+
/// The label of the chip.
4041
#[prop_or(Some(AttrValue::Static("")))]
4142
pub label: Option<AttrValue>,
42-
#[doc = "The variant to use."]
43+
/// The variant to use.
4344
pub variant: ChipVariants,
4445
pub children: Html,
4546
}

src/circular_progress.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
use yew::prelude::*;
22
#[derive(Properties, PartialEq)]
33
pub struct Props {
4-
#[doc = "Progress to display, a fraction between 0 and <code>max</code>."]
4+
/// Progress to display, a fraction between 0 and <code>max</code>.
55
#[prop_or(Some(0))]
66
pub value: Option<usize>,
7-
#[doc = "Maximum progress to display, defaults to 1."]
7+
/// Maximum progress to display, defaults to 1.
88
#[prop_or(Some(1))]
99
pub max: Option<usize>,
10-
#[doc = "Whether or not to display indeterminate progress, which gives no indication to how long an activity will take."]
10+
/// Whether or not to display indeterminate progress, which gives no indication to how long an
11+
/// activity will take.
1112
#[prop_or(Some(false))]
1213
pub indeterminate: Option<bool>,
13-
#[doc = "Whether or not to render indeterminate mode using 4 colors instead of one."]
14+
/// Whether or not to render indeterminate mode using 4 colors instead of one.
1415
#[prop_or(Some(false))]
1516
pub four_color: Option<bool>,
1617
}

src/fab.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ impl FabVariants {
1717

1818
#[derive(Properties, PartialEq)]
1919
pub struct Props {
20-
#[doc = "The FAB color variant to render."]
20+
/// The FAB color variant to render.
2121
#[prop_or(Some(AttrValue::Static("surface")))]
2222
pub kind: Option<AttrValue>,
23-
#[doc = "The size of the FAB.<br>NOTE: Branded FABs cannot be sized to <code>small</code>, and Extended FABs do not have different sizes."]
23+
/// The size of the FAB.<br>NOTE: Branded FABs cannot be sized to <code>small</code>, and
24+
/// Extended FABs do not have different sizes.
2425
#[prop_or(Some(AttrValue::Static("medium")))]
2526
pub size: Option<AttrValue>,
26-
#[doc = "The text to display on the FAB."]
27+
/// The text to display on the FAB.
2728
#[prop_or(Some(AttrValue::Static("")))]
2829
pub label: Option<AttrValue>,
29-
#[doc = "Lowers the FAB’s elevation."]
30+
/// Lowers the FAB’s elevation.
3031
#[prop_or(Some(false))]
3132
pub lowered: Option<bool>,
32-
#[doc = "The variant to use."]
33+
/// The variant to use.
3334
pub variant: FabVariants,
3435
pub children: Html,
3536
}

0 commit comments

Comments
 (0)