-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add custom look #2803
base: main
Are you sure you want to change the base?
Add custom look #2803
Conversation
I've been playing around with this for the past few days, and it's incredibly fun! 🎉 Also, could you update the beta tag to |
Yay! Thanks for doing this. I think it's a big enough conceptual change it should probably go in after v1, if not just so that we can highlight the new functionality and it not get lost in other changes. But I'm still thinking this through! |
Thanks! That makes sense. That said, since My application really depends on both |
The code change is small, but it's a big (positive) step in functionality which makes a nice highlight for a next release. I'm just trying to see if I can draw a line and get v1 done, as I've dragged my feet on it much longer than I was hoping I'd do. I appreciate this makes things annoying for you and your application though 😭 |
Thank you! I really appreciate it. I’m looking forward to the completion of v1. 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great! 🙂 Let some minor comments and after that I think this is a good first feature for the post-v1 release.
class_option( | ||
:look, | ||
type: :string, | ||
desc: "Specify the look for the field", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this is a bit clearer?
desc: "Specify the look for the field", | |
desc: "Generate templates for a \"look\" (alternative representation of the field) |
class_option( | ||
:look, | ||
type: :string, | ||
desc: "Specify the look for the field", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above:
desc: "Specify the look for the field", | |
desc: "Generate templates for a \"look\" (alternative representation of the field) |
But that's assuming this is relevant here, as per my question on whether this generator should be used on its own.
If you want to generate a different look, run the following: | ||
|
||
```bash | ||
rails generate administrate:views:field number --look custom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this actually work? I've been trying today and it didn't work, and only now I'm realising perhaps this generator isn't supposed to run on its own.
|
||
This will generate three files: | ||
|
||
- `app/fields/gravatar_field.rb` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `app/fields/gravatar_field.rb` | |
- `app/fields/gravatar_field.rb` (assuming it doesn't exist already) |
def self.local_partial_prefixes | ||
["fields/#{field_type}"] | ||
def self.local_partial_prefixes(look: :default) | ||
fallback = ["fields/#{field_type}/looks/default", "fields/#{field_type}"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to allow for default
? I think it might get confusing and affect maintenance in the long run. There's already the normal option (no look), so not sure we need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think having both would cause significant confusion, but which approach do you prefer?
I felt that plugin developers might prefer having everything neatly organized within looks
dir, so I designed it this way to allow both options.
Introduces a custom look implementation based on the discussion in #2291.
Changes:
look
option toFieldBase
FieldBase
Field
look
option to generatorsBelongsTo
look in demo appproduct: Field::BelongsTo.with_options(look: :product_card)
Please review and let me know if any changes are needed! 🚀
Usage: