Skip to content

Replace html/assets related configs with simple partials#8156

Merged
javierjulio merged 3 commits into
masterfrom
partials-extraction-for-assets-config
Dec 5, 2023
Merged

Replace html/assets related configs with simple partials#8156
javierjulio merged 3 commits into
masterfrom
partials-extraction-for-assets-config

Conversation

@javierjulio

@javierjulio javierjulio commented Dec 5, 2023

Copy link
Copy Markdown
Member

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 the app/views/active_admin/_head.html.erb partial 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_link and site_title_image configs have been removed. The site_title config remains and can be given a proc for dynamic content. You can also extract the app/views/active_admin/_site_header_title.html.erb into 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.erb in your project with the desired output.

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.
@javierjulio javierjulio self-assigned this Dec 5, 2023
@codecov

codecov Bot commented Dec 5, 2023

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4dfb182) 99.04% compared to head (e7e050e) 99.00%.

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.
📢 Have feedback on the report? Share it here.

@javierjulio javierjulio merged commit 8a64a5e into master Dec 5, 2023
@javierjulio javierjulio deleted the partials-extraction-for-assets-config branch December 5, 2023 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant