# Include a CSS style sheet in an extension?

**URL:** <https://www.ruby-forum.com/t/include-a-css-style-sheet-in-an-extension/83632>\
**Category:** Radiant CMS\
**Created:** [January 28, 2007, 2:17am UTC](https://www.ruby-forum.com/t/include-a-css-style-sheet-in-an-extension/83632 "2007-01-28T02:17:04Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [January 28, 2007, 2:17am UTC](https://www.ruby-forum.com/t/include-a-css-style-sheet-in-an-extension/83632/1 "2007-01-28T02:17:04Z")

</div>

Is there any way to include a CSS style sheet in an extension? If not,  
what is the preferred way of styling elements in an extension?

---

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [January 28, 2007, 6:42am UTC](https://www.ruby-forum.com/t/include-a-css-style-sheet-in-an-extension/83632/2 "2007-01-28T06:42:24Z")

</div>

Copy it to public as part of the activate method and the inverse in  
deactive?

I have been keeping my stylesheets and related js files in /public/  
extensions/name\_of\_extension/stylesheets and --/scripts. This makes  
sense to me. The more cumbersome part is making sure that the future  
user knows to add the stylesheet to their layout as part of the  
installation of the extension.

Now if you’re asking about stylesheets within the admin area purely,  
take a look at the head of the application layout (/app/views/layouts/  
application.rhtml)… It seems you may be able to inject stylesheet  
references by adding them somehow to the @stylesheets array. Sean  
Cribbs in a recent response to my question also insinuated that there  
is provision for doing this though I’ve not yet looked any further  
into it.

Hope that’s of some help,

Loren J.  
[www.fn-group.com](http://www.fn-group.com)

---

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [January 28, 2007, 3:46pm UTC](https://www.ruby-forum.com/t/include-a-css-style-sheet-in-an-extension/83632/3 "2007-01-28T15:46:47Z")

</div>

Loren,

I’ve had some discussions with John in the past about how this should  
work. There are two possibilities that I remember:

1. SiteController copies “assets” from your extension’s “public”  
directory to the application’s public directory on demand.
2. Provide a rake task to copy them or directive in the extension  
definition that copies assets on startup.

Sean

---

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [January 28, 2007, 8:17pm UTC](https://www.ruby-forum.com/t/include-a-css-style-sheet-in-an-extension/83632/4 "2007-01-28T20:17:29Z")

</div>

My opinion is that the first option would be the least intrusive as  
long as it takes note of the last modified timestamps to recopy them  
when they change.

Regards,  
Kaleb

---

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [January 28, 2007, 8:31pm UTC](https://www.ruby-forum.com/t/include-a-css-style-sheet-in-an-extension/83632/5 "2007-01-28T20:31:31Z")

</div>

You’ve revealed why that option could be somewhat inflexible. Once it  
has  
been copied, it will be served as a static file by the webserver. I  
would  
prefer for it to be copied on activation of the extension, then it is  
up-to-date on startup.

Sean

---

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [January 28, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/include-a-css-style-sheet-in-an-extension/83632/6 "2007-01-28T20:39:33Z")

</div>

Copying upon activation seems like a sensible solution but I’m not  
sure I follow how it is inflexible to copy the file as soon as it  
changes. Then it is always up to date regardless of  
deactivating/activating the extension. I didn’t express it but I would  
have assumed that there would be an initial copy of the file upon  
startup so you don’t have “touch” the file for it to be copied.

Regards,  
Kaleb

---

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [January 29, 2007, 1:10am UTC](https://www.ruby-forum.com/t/include-a-css-style-sheet-in-an-extension/83632/7 "2007-01-29T01:10:23Z")

</div>

Well, maybe not inflexible, but impractical. The problem is that you’d  
have to have some process/controller checking the file’s timestamp on  
every access. This means preventing Apache/lighttpd/Litespeed/whatever  
from sending the file directly, which is proven to be much faster  
anyway. I’m not trying to prematurely optimize, just suggesting that it  
would add complexity.

Sean

---

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [September 26, 2007, 3:13pm UTC](https://www.ruby-forum.com/t/include-a-css-style-sheet-in-an-extension/83632/8 "2007-09-26T15:13:17Z")

</div>

On activation couldnt you overload the controller method to point to the  
extension’s css path instead of the site’s css path?

---

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [January 29, 2007, 1:22am UTC](https://www.ruby-forum.com/t/include-a-css-style-sheet-in-an-extension/83632/9 "2007-01-29T01:22:26Z")

</div>

I can definitely appreciate the impracticality of checking file  
timestamps each time, however, would you agree that under development  
mode it may be a good option to have available?

---

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [September 28, 2007, 12:05am UTC](https://www.ruby-forum.com/t/include-a-css-style-sheet-in-an-extension/83632/10 "2007-09-28T00:05:18Z")

</div>

Or perhaps have a standard hook that allows an extension to copy the  
css/js/image files to the standard path when the extension is  
installed/upgraded??

On 9/26/07, Tim G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## On activation couldnt you overload the controller method to point to the extension’s css path instead of the site’s css path?
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Radiant mailing list  
> Post: removed\_email\_address@domain.invalid  
> Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
Regards,  
Hiram

Blog: [http://hiramchirino.com](http://hiramchirino.com)
