Administrate: Allow easier hooks to provide simple, custom stylesheet/javascript requires

Created on 17 Dec 2015  路  6Comments  路  Source: thoughtbot/administrate

Problem

I made a custom Font-Awesome field that displays a stored icon name string ("fa-facebook") as its rendered icon rather than its name. After getting the appropriate gem, I need to add one line into the application.css file.

Generating the entire administrate:assets:stylesheets stack so I can plug this one value in seems a bit sledgehammerish.

Ideas

Not sure if any/all of these are technically possible.

  • Somehow add a hook into the stylesheet and javascript manifest files that can require into the main app by looking in a special folder or file.
  • Have main app define the root manifest files for the engine, with only a require administrate.scss etc... entry in it. This would allow additional requires before or after the gem scss.
  • Setup some sort of config variable that could take some paths to require within administrate.scss

Or maybe I am just dense and am not seeing the easy way to do this without freezing the entire stylesheet stack into my main app. Ideas?

Most helpful comment

@coneybeare Wondering if this commit solves your problem here.

You can now call Administrate::Engine.add_stylesheet to pass a custom stylesheet to be included on every admin page. Does this solve the issue?

cc @sebbean @marksiemers @bessey

All 6 comments

having this same issue right now. trying to just get something to work. curious how you accomplished injecting css

One option may be to do the same thing that you guys do for javascript - have a partial that can be overridden that has a =yield :stylesheet

That way, you could use a small stylesheet and put the tag in a content_for(:stylesheet) block - if you only need to customize styles for certain pages. If you need a custom style to apply to everything, then you could just create your own _stylesheets.html.erb

An alternative approach is to generate the layout with rails g administrate:views:layout and either add your custom stylesheet to the <head>, or @import "administrate/application"; in your custom stylesheet and completely replace the stylesheet_link line already in the layout.

@coneybeare Wondering if this commit solves your problem here.

You can now call Administrate::Engine.add_stylesheet to pass a custom stylesheet to be included on every admin page. Does this solve the issue?

cc @sebbean @marksiemers @bessey

I'm not using administrate anymore, but this does look like it would have resolved the issue.

@coneybeare Awesome, thanks for the update! If you give Administrate another try in the future, we'd welcome your feedback. Thanks again :)

Was this page helpful?
0 / 5 - 0 ratings