Include a CSS style sheet in an extension?

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?

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

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

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

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

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

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

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

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?

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. [email protected] 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/.


Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant


Regards,
Hiram

Blog: http://hiramchirino.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs