-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add Tailwind styled scaffold templates #71
Conversation
Co-authored-by: Dino Marić <dino.onex@gmail.com>
Resolves #23 |
Digging this! Will look closer in a bit. Thanks for working on it! |
<%% end %> | ||
|
||
<% attributes.each do |attribute| -%> | ||
<div class="field my-5"> |
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 you know what the field
css class is? I don't think that's tailwind related? Maybe it's the scaffold field class here https://github.com/rails/rails/blob/9c77d72ecc7fdf490e778b0807882fd53115e7a3/actiontext/test/dummy/app/assets/stylesheets/scaffold.css#L40? If so, maybe we can drop that because we want to use only tailwind inlined css?
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.
Ooops...fixed
</div> | ||
|
||
<% end -%> | ||
<div class="actions inline"> |
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.
actions
also looks like it's from the default scaffold css from https://github.com/rails/rails/blob/9c77d72ecc7fdf490e778b0807882fd53115e7a3/actiontext/test/dummy/app/assets/stylesheets/scaffold.css#L41, maybe drop this too and add mb-something here too?
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.
Ooops...fixed. Thank you ❤️
We have to make this match the new style in rails/main where the _post.html.erb partial is used on the index. That's how it matches up to work out of the box with Turbo. Which means we can't use a table on the index. See the templates in https://github.com/rails/rails/tree/main/railties/lib/rails/generators/erb/scaffold/templates |
@dhh no problem. But, yeah I agree that index without the table is going to be easier especially for the scaffolds where the table columns are dynamic and it is hard to style the table properly. Anyways, we'll match with the Rails 7 changes 👍🏻 |
7d80a2b
to
bfb324a
Compare
<%%= form.password_field :password %> | ||
</div> | ||
|
||
<div class="my-5"> |
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.
Don't think these div's are aligned properly, yeah?
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.
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 have had to add that extra indentation for .tt
files that I have worked on in the past too so that the generated files look right as you showed above. That's not the only quirk it has for lining up code. Variables and things also have to be lined up weird so they generate in the correct location. I have never understood why, but would like to look into it more. Any suggestions on where I could dive deeper on this?
|
||
<%%= link_to "Show this <%= human_name.downcase %>", @<%= singular_table_name %>, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
</div> |
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.
Add CR
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %> | ||
|
||
<%%= link_to 'Back to <%= human_name.pluralize.downcase %>', <%= index_helper %>_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
</div> |
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.
Add CR
<%%= link_to 'Edit this <%= human_name.downcase %>', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> | ||
<hr class="mt-6"> | ||
<%% end %> | ||
</div> |
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.
Add CR
Add custom scaffold generator that is same as the one inside the Rails 7 in order to make this work with Rails 6.
8f2b32a
to
f14aa08
Compare
end | ||
end | ||
|
||
template "partial.html.erb", File.join("app/views", controller_file_path, "_#{singular_table_name}.html.erb") |
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.
In order to get the partial in rails 6 I had to "re-implement/copy" Rails 7 scaffold generator :)
@dhh I think this should be ready now, and it should also work with Rails 6. Take a 👀 when you have time. |
end | ||
end | ||
end | ||
end |
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.
Add CR
|
||
%w(index edit new show _form _message).each { |view| assert_file "app/views/messages/#{view}.html.erb" } | ||
end | ||
end |
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.
Add CR
@dhh re paddings that is strange! Only way I could see that happening is if you don't have a Could you push sample app you are showing on the Github so we can double check 🙏 For the reference this is how it looks like on the app I've just created |
I had not run the installer correctly. You're right. It looks great!! This is really neat. |
@dixpac Thanks for your work on this, I’m finally going to get rid of rails_admin gem (with heaps of dependent gems) and scaffold out the rest of my models. Great work 👍 I appreciate it. |
@BakiVernes I absolutely love this, I was working on a similar thing :) Have you considered applying the tailwind classes in css, like daisy-ui does? |
Thank you @lafeber! We have considered extracting classes, but since this gem comes with a precompiled css file with all of tailwinds utility classes inside (so no preprocessing done) it's gonna be a challenge. But we will definitely take a shot at it :) |
I'm sorry if this is not the place for this comment: @dhh I love Rails, among other things, because it enables me to do very fast functional prototypes. And part of that was having an index scaffold that I could instantly show to a client to display a list of items, and customize later. It was amazing and well known: Now, with Rails 7.0.3, if I wanted that, do I have to manually code another view? Or maybe there is some CSS that would allow me to show this new index like a table? I'm not UI expert, and with earlier Rails versions, I didn't needed to be. I'm not the only one troubled with this: https://www.reddit.com/r/rails/comments/pztx9g/scaffold_index_no_longer_generating_html_tables/ IMHO this change as it is, may be beneficial to some while detrimental to others. I feel like the small guy being left behind here. I appreciate very much all the work you have done, @dhh along with all the Rails team. Regards. |
![]() ![]() ![]() @dixpac I'm curious what you did to obtain the output shown in your post. Granted this was likely several versions behind what I used here. There are no browser console or Rails server errors indicating any issues with loading CSS. So is this is the expected stock output of Rails scaffolds in 7.1.3.2 with tailwindcss-rails 2.3.0? Update: Never mind, looks like ![]() ![]() ![]() |
Summary
This PR adds Tailwind styled scaffold templates when this gem is installed. These styles were sanctioned by Adam and the Tailwind team. Some examples:
TODO
[✓] Make new styles based on Adam Wathan suggestions
[✓] Conform template partials to Rails 7 main branch
[✓] Make it work with Rails 6
Additional information
It would great if we had the option of using Tailwinds
@apply
directive. This would be useful when extracting components like buttons, inputs etc. But since the css comes precompiled we did what we could.Maybe something to work on in the future?
Co-authored-by: Dino Marić dino.onex@gmail.com