Monday, November 14, 2005

Rails Theme Support Plugin

Update: I changed the svn URL to point to it's new home!

Currently, to add support for themes into your rails application, you have to install the theme_generator. The generator will then create the folder structure for themes, and it also creates the plugin files for theme support in rails.

The more I've thought about it, the less I like this approach. I'd rather have a fully encapsulated plugin that would add support for themes into rails and define a simple generator that would merely create the boilerplate theme structure.

To that end, I present the Rail Theme Support plugin. To install the plugin execute the following in the root of your application (requires rails 0.14.3+):

./script/plugin install http://mattmccray.com/svn/rails/plugins/theme_support

In the next couple of days I'll have a trac installation up and running for it too.

You can, of course, still get the theme_generator from RubyForge. But I think the plugin will be the approach I will recommend moving forward.

Try it out and let me know what you think!

19 comments:

  1. svn link requires a password....

    ReplyDelete
  2. Ah, the repos isn't setup to be accessible anonymously yet...
    You can download a zip of the plugin at the development site homepage.

    ReplyDelete
  3. Great work! Already using it 'live' on here and here. One set of code and two themes - great, thanks!

    ReplyDelete
  4. I much prefer it *not* being a plugin. Less intrusive, more trustworthy that way....

    ReplyDelete
  5. The above problems have gone in Rails 0.14.4.

    ReplyDelete
  6. regading the 'NoMethodError undefined method `current_theme'' error.
    I'm also getting this with the pure plugin version if I try and send mail from the app. The gem version seems to work fine though.
    I'm guessing that the pure plugin tries to patch actionview in a way that mailer does not like?!

    ReplyDelete
  7. I'm working on a project that needs both theme support and translations. I know that the rails community is working on several approaches to translations, but I have another thought...
    When it comes to caching, themes and translations need some interweaving so that various translations can be cached. It's almost like a translation is a sub-theme, or variation on a theme.
    I'd like to help work on a method to provide translations built into the the theme framework... Contact me at: mortonda @ dgrmm.net if you are interested in this approach...

    ReplyDelete
  8. Hi,
    I have the same error with ActionMailer::Base.
    NoMethodError: undefined method `current_theme' for #
    ----
    MailContactRequest is a model :
    class MailContactRequest

    ReplyDelete
  9. Hi,
    I have the same error with ActionMailer::Base.
    NoMethodError: undefined method `current_theme' for #
    MailContactRequest is a model :
    class MailContactRequest

    ReplyDelete
  10. Hi (sorry for other comment, probleme with special char),
    I have the same error with ActionMailer::Base.
    NoMethodError: undefined method `current_theme' for #
    MailContactRequest is a model extend ActionMailer::Base.
    MailContactRequest.create_new() send a mail, and use template to format this.
    The error raise in actionview_ex.rb at line 16 (controller.current_theme), controller is a MailContactRequest object, and not a ActionController.
    This error is resolved if extend ActionMailer::Base to support themes.

    ReplyDelete
  11. There seems to be a problem with using liquid templates if you have the newest version of liquid installed. There is no longer a register_block method. Any ideas on how to fix this?

    ReplyDelete
  12. assert_existance_of_template_file in actionController needs to be updated to look for theme files. Otherwise if the original file is missing, it doesn't work. This limits themes to only using existing files...

    ReplyDelete
  13. We noticed that your blog have some Ruby On Rails related content and that
    is why we would like to invite you to register yourself and your
    blog at RubyCorner, a directory of Ruby related blogs:
    http://www.rubycorner.com/
    We like to think about RubyCorner as a "meeting place" for the
    community, also as a "focal point" where the people new to this
    technology can quickly tune into the pulse of the community.
    Registering your blog will help build a valuable resource for
    this growing community.
    Thanks.

    ReplyDelete
  14. Hi, i have the same error with ActionMailer::Base.
    How can i "extend ActionMailer::Base to support themes"? (I'm a newbie to RoR)

    ReplyDelete
  15. I had a problem with sub-dirs like /images/buttons/btn_enter.gif
    So I changed :filename to *filename on lines 26, 27, 28 of routeset_ex.rb and put params[:filename] = File.join(params[:filename]) one line after "def stylesheets", "def javascript" and "def images".
    I'm using Rails 1.1.2

    ReplyDelete
  16. Add empty current_theme and force_liquid_template in UserNotify class, that should fix it

    ReplyDelete
  17. Thanks for this. *It just works*. Being a newbie, I was hacking apart typo. Cheers.

    ReplyDelete
  18. Just a comment on some things I needed:
    - restart the server to register the plugin
    - ensure that the views/layouts/[default].rhtml exists so that it can be overriden

    ReplyDelete
  19. Tired of finding the file through enormous amount of searchers? 1 center- 1 enter. http://megaupload.name/

    ReplyDelete