# Automating CSS in a plugin

**URL:** <https://www.ruby-forum.com/t/automating-css-in-a-plugin/184624>\
**Category:** Rails\
**Created:** [March 5, 2010, 11:05am UTC](https://www.ruby-forum.com/t/automating-css-in-a-plugin/184624 "2010-03-05T11:05:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [March 5, 2010, 11:05am UTC](https://www.ruby-forum.com/t/automating-css-in-a-plugin/184624/1 "2010-03-05T11:05:59Z")

</div>

Hi, I’m looking for advice on how best to implement a plugin that  
contains some CSS. I would like the CSS to be automatically added to any  
layout so that the only action I need to perform is installation of the  
plugin.

Is this possible?

The reason for this is that the plugin includes some view partials and I  
want to provide default stylesheets so the partial’s contents look  
reasonable by default.

If application-specific styling is then required the styles would be  
customised by overriding in a controller’s style sheet outside the  
plugin.

I assume I will need a stylesheets folder in the plugin and have the  
plugin installer copy any stylesheets into the application’s public  
folder. What I don’t know is how I can have that stylesheet applied  
automatically. They way I do this now is to use a helper in the layout  
to include the stylesheet but I’d like to avoid that.

I have used the Styler plugin to help manage css before and it’s quite  
good. I could customise that to include plugin css in its search.

But is there a better way to achieve this?

Thanks!

---

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [March 9, 2010, 5:40pm UTC](https://www.ruby-forum.com/t/automating-css-in-a-plugin/184624/2 "2010-03-09T17:40:21Z")

</div>

Would anyone be able to help with my query?

---

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [March 9, 2010, 10:25pm UTC](https://www.ruby-forum.com/t/automating-css-in-a-plugin/184624/3 "2010-03-09T22:25:43Z")

</div>

John L. wrote:

> Would anyone be able to help with my query?

I’d say monkey patch the view helpers to inject your own code (css, js,  
whatever) in it.
