Forum: Ruby on Rails Using register_template_handler to serve CSS files (Making A

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Iván Vega R. (Guest)
on 2006-01-22 04:18
(Received via mailing list)
Hi,

I wanted to be able to use some Rails code inside CSS files, so I set up
a controller (StylesController) to serve CSS files that reside inside
the controller's view folder when the browser requests
/stylesheets/:action

So in the controller I just define empty actions with the names I want
my style sheets in (ie: def cooleffects end - that would respond to
/stylesheets/cooleffects).

And in views/styles I have cooleffects.css

Then, I tried the following (both inside the controller, and in a
plugin's init.rb):

ActionView::Base.register_template_handler 'css', ActionView::Base

Which doesn't seem to have any effect, because Rails throws an error on
the CSS file (no matter if I comment the line above):

|No rhtml, rxml, or delegate template found for |<contents of the CSS file>

So, how can I make ActionView handle CSS files as if they were RHTML
files?

Thanks!

Ivan V.
Alain R. (Guest)
on 2006-01-22 14:46
(Received via mailing list)
Iván
    >  I wanted to be able to use some Rails code inside CSS files,

Do you know RCSS?
     http://rcss.rubyforge.org/
It lets you use Erb inside css stylesheets.

Note: I've experienced some problems when using RCSS on a shared server
(Dreamhost). I wonder if it's related to RCSS resource need:it has to
translate the RCSS file into a CSS one. What happened is that the page
would sometimes render without any styling, as when you remove all the
stylesheed. Refreshing the page would have display correctly.


Alain
Iván Vega R. (Guest)
on 2006-01-22 17:45
(Received via mailing list)
Thanks Alain, it looks very interesting, specially the server-side
constants, which are something that I was looking to implement using
plain old  erb code.

However, since you mention some problems with it, I'll just keep an eye
on it for future usage. Right now, I went with this:

        tpl = ''
        File.open("#{RAILS_ROOT}/app/views/styles/#{params['cssfile']}")
do |css|
            while line = css.gets
                tpl += line
            end
        end
        render_template tpl

Regards,
Ivan V.

Alain R.
escribió:> Iván
>
This topic is locked and can not be replied to.