Replace html/assets related configs with simple partials#8156
Merged
Conversation
This makes it easier to support and customize these defaults through standard Rails partials without needing to create APIs for configuring this. Worth noting code like assets registration predates the Rails asset pipeline. The title tag is rendered separately due to needing a variable. Unlikely that will change and we have a site_title config already that will remain. The title tag contents are now sanitized by default stripping all tags. Since the partial is well isolated, this can also be overridden more easily. The head partial only outputs 5 lines: stylesheet tag, javascript tag and 3 meta tags (viewport, CSRF, CSP). Minus the JS, this matches what Rails 7 includes by default in the application layout for the html head. Users can now add html head content easily without a config. They can even ditch the defaults and rewrite it so the CSS and JS is handled through Shakapacker or through the now deprecated Webpacker even. All without ActiveAdmin having to maintain and support that with wrapper APIs out of the box with just standard Rails partials.
This removes the redundant site_title_* configs since its best for a user to customize using a simple Rails partial with any custom content and full control on layout and appearance. This also removes any concern with asset helpers and allows a user to use whichever asset delivery library they prefer, e.g. Shakapacker, if customizing.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #8156 +/- ##
==========================================
- Coverage 99.04% 99.00% -0.05%
==========================================
Files 182 175 -7
Lines 4722 4603 -119
==========================================
- Hits 4677 4557 -120
- Misses 45 46 +1 ☔ View full report in Codecov by Sentry. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This replaces and removes many html and asset related configs from our initializer with simple partials. These are standard defaults for any Rails app but can be easily overridden using partials and no need to maintain configs or APIs to support multiple asset management solutions. The library will stick to TailwindCSS and Flowbite with cssbundling-rails and jsbundling-rails gems as the expected default but with these partials anyone can override stylesheets, for example, to use Shakapacker asset helpers instead. We just won't provide the functionality out of the box.
To add elements to the HTML
<head>tag, just extract theapp/views/active_admin/_head.html.erbpartial into your project which just renders a single partial called defaults. If you want to replace the contents entirely, simply remove the defaults partial and add your own stylesheets, meta tags, etc.The
site_title_linkandsite_title_imageconfigs have been removed. Thesite_titleconfig remains and can be given a proc for dynamic content. You can also extract theapp/views/active_admin/_site_header_title.html.erbinto your project to override with your own logo, custom styling, mobile support, etc.For a custom footer, just create a partial
app/views/active_admin/_site_footer.html.erbin your project with the desired output.