Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename the derive macro helper attribute builder to prop #504

Merged
merged 2 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/next/basics/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ view! {

## Default props

Some property fields might have a default value. Use the `#[builder(default)]` attribute to allow
Some property fields might have a default value. Use the `#[prop(default)]` attribute to allow
omitting the property when constructing the component.

```rust
#[derive(Props)]
struct MyProps {
name: String,
#[builder(default)]
#[prop(default)]
email: String,
}

Expand Down
4 changes: 2 additions & 2 deletions docs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn build_dir(base: &Path, output: &Path) -> Result<(), Box<dyn Error>> {
let page = parse(entry.path())?;
let output_dir: PathBuf = out_dir.join(output);
let output_path: PathBuf = output_dir
.join(entry.path().strip_prefix(&base).unwrap())
.join(entry.path().strip_prefix(base).unwrap())
.with_extension("json");

let output_json = serde_json::to_string(&page).unwrap();
Expand All @@ -163,7 +163,7 @@ fn generate_sitemap_for_dir(
.map(|e| e.unwrap())
.filter(|e| e.path().is_file())
{
let path = entry.path().strip_prefix(&dir).unwrap().with_extension("");
let path = entry.path().strip_prefix(dir).unwrap().with_extension("");
let path_str = path.iter().fold(String::new(), |acc, c| {
format!("{}/{}", acc, c.to_str().unwrap())
});
Expand Down
4 changes: 2 additions & 2 deletions packages/sycamore-macro/src/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,14 @@ fn inline_props_impl(item: &mut ItemFn) -> Result<TokenStream> {
syn::GenericParam::Type(ty) => {
let ty = &ty.ident;
Some(quote! {
#[builder(default, setter(skip))]
#[prop(default, setter(skip))]
#phantom_ident: ::std::marker::PhantomData<#ty>
})
}
syn::GenericParam::Lifetime(lt) => {
let lt = &lt.lifetime;
Some(quote! {
#[builder(default, setter(skip))]
#[prop(default, setter(skip))]
#phantom_ident: ::std::marker::PhantomData<&#lt ()>
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sycamore-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn component(args: TokenStream, item: TokenStream) -> TokenStream {
}

/// The derive macro for `Props`. The macro creates a builder-like API used in the [`view!`] macro.
#[proc_macro_derive(Props, attributes(builder))]
#[proc_macro_derive(Props, attributes(prop))]
pub fn derive_props(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);

Expand Down
24 changes: 12 additions & 12 deletions packages/sycamore-macro/src/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ mod struct_info {
ref name,
ref builder_name,
..
} = *self;
} = self;
let (impl_generics, ty_generics, where_clause) = self.generics.split_for_impl();
let all_fields_param = syn::GenericParam::Type(
syn::Ident::new("PropsFields", proc_macro2::Span::call_site()).into(),
Expand Down Expand Up @@ -270,7 +270,7 @@ mod struct_info {
pub fn field_impl(&self, field: &FieldInfo) -> Result<TokenStream, Error> {
let StructInfo {
ref builder_name, ..
} = *self;
} = self;

let descructuring = self.included_fields().map(|f| {
if f.ordinal == field.ordinal {
Expand All @@ -282,7 +282,7 @@ mod struct_info {
});
let reconstructing = self.included_fields().map(|f| f.name);

let &FieldInfo {
let FieldInfo {
name: ref field_name,
ty: ref field_type,
..
Expand Down Expand Up @@ -356,7 +356,7 @@ mod struct_info {
{
field.type_from_inside_option().ok_or_else(|| {
Error::new_spanned(
&field_type,
field_type,
"can't `strip_option` - field is not `Option<...>`",
)
})?
Expand Down Expand Up @@ -537,7 +537,7 @@ mod struct_info {
ref name,
ref builder_name,
..
} = *self;
} = self;

let generics = self.modify_generics(|g| {
let index_after_lifetime_in_generics = g
Expand Down Expand Up @@ -669,7 +669,7 @@ mod struct_info {
pub fn new(attrs: &[syn::Attribute]) -> Result<TypeBuilderAttr, Error> {
let mut result = TypeBuilderAttr::default();
for attr in attrs {
if path_to_single_string(&attr.path).as_deref() != Some("builder") {
if path_to_single_string(&attr.path).as_deref() != Some("prop") {
continue;
}

Expand Down Expand Up @@ -747,7 +747,7 @@ mod struct_info {
let call_func = quote!(#call_func);
Error::new_spanned(
&call.func,
format!("Illegal builder setting group {}", call_func),
format!("Illegal prop setting group {}", call_func),
)
})?;
match subsetting_name.as_str() {
Expand All @@ -759,7 +759,7 @@ mod struct_info {
}
_ => Err(Error::new_spanned(
&call.func,
format!("Illegal builder setting group name {}", subsetting_name),
format!("Illegal prop setting group name {}", subsetting_name),
)),
}
}
Expand Down Expand Up @@ -875,7 +875,7 @@ mod field_info {
impl FieldBuilderAttr {
pub fn with(mut self, attrs: &[syn::Attribute]) -> Result<Self, Error> {
for attr in attrs {
if path_to_single_string(&attr.path).as_deref() != Some("builder") {
if path_to_single_string(&attr.path).as_deref() != Some("prop") {
continue;
}

Expand Down Expand Up @@ -965,7 +965,7 @@ mod field_info {
let call_func = quote!(#call_func);
Error::new_spanned(
&call.func,
format!("Illegal builder setting group {}", call_func),
format!("Illegal prop setting group {}", call_func),
)
})?;
match subsetting_name.as_ref() {
Expand All @@ -977,7 +977,7 @@ mod field_info {
}
_ => Err(Error::new_spanned(
&call.func,
format!("Illegal builder setting group name {}", subsetting_name),
format!("Illegal prop setting group name {}", subsetting_name),
)),
}
}
Expand Down Expand Up @@ -1011,7 +1011,7 @@ mod field_info {
if let (Some(skip), None) = (&self.setter.skip, &self.default) {
return Err(Error::new(
*skip,
"#[builder(skip)] must be accompanied by default or default_code",
"#[prop(skip)] must be accompanied by default or default_code",
));
}

Expand Down
6 changes: 3 additions & 3 deletions packages/sycamore-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ where
{
view: F,
integration: I,
#[builder(default, setter(skip))]
#[prop(default, setter(skip))]
_phantom: PhantomData<&'a (R, G)>,
}

Expand Down Expand Up @@ -184,7 +184,7 @@ where
view: F,
integration: I,
route: R,
#[builder(default, setter(skip))]
#[prop(default, setter(skip))]
_phantom: PhantomData<&'a G>,
}

Expand Down Expand Up @@ -301,7 +301,7 @@ where
{
view: F,
route: R,
#[builder(default, setter(skip))]
#[prop(default, setter(skip))]
_phantom: PhantomData<&'a (R, G)>,
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sycamore/src/suspense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct SuspenseState {
#[derive(Props, Debug)]
pub struct SuspenseProps<'a, G: GenericNode> {
/// The fallback [`View`] to display while the child nodes are being awaited.
#[builder(default)]
#[prop(default)]
fallback: View<G>,
children: Children<'a, G>,
}
Expand Down
2 changes: 1 addition & 1 deletion website/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn OutlineView<G: Html>(cx: Scope, outline: Vec<Outline>) -> View<G> {
#[derive(Props)]
pub struct ContentProps {
pub data: MarkdownPage,
#[builder(default, setter(strip_option))]
#[prop(default, setter(strip_option))]
pub sidebar: Option<(String, SidebarData)>,
}

Expand Down