OK, so after a short discussion and some experiments, I've realized that the Typo approach to themes has a lot more merit than I initially thought... For general use it still has some trouble areas, but that's nothing that can't be fixed.
I've created a new theme_generator that takes their general approach and makes it easy to leverage in any application. Even an existing one.
How to use it...
Usage is extremely easy. First, use the generator to create a default theme.
./script/generate theme default
(It doesn't have to be called 'default', it can be whatever you'd like)
This will create the main themes folder structure, the initial theme files for the theme ('default' in this case), and it creates the plugins/components needed to support themes.
Now you can use themes as easily as you do layouts. The following will use a layout named 'main' in the 'default' theme.
class ApplicationController < ActionController::Base layout 'main' theme 'default' end
Here's an example of per-user themes:
class ApplicationController < ActionController::Base layout 'default' theme :get_user_theme def get_user_theme # This assumes, of course, your User has a 'theme' field return @session[:user].nil? ? 'default' : @session[:user].theme end end
Differences from Typo themes...
I did take the liberty of tweaking of couple of things (beyond setting the theme in your controller). The main difference is that I changed the cached theme structure.
Before:
/public /images /theme /stylesheets /theme /javascript /theme
After:
/public /themes /[THEME_NAME] /images /stylesheets /javascript
What does this mean? For one thing, it's a lot easier to remove cached theme files... Just delete the public/themes
folder.
Also, you should be using relative paths to images in your CSS. For example:
BODY { background: #FFF url(../images/page-bg.jpg) top left; }
Requirements...
Update: theme_generator is now hosted on RubyForge.
The theme_generator requires Rails >= 0.14. The easiest way to install the theme_generator is by running:
sudo gem install theme_generator
It's that simple. Feel free to install it and let me know what you think.