mattmccray

 
« Theme Generator Shape… | Home | Now for something com… »

Rails Theme Support Plugin

» Published November 14, 2005 under Rails, Software, Theme Support

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!


23 comments

11.14.05 @ 19:13 protocool said...
svn link requires a password….
11.14.05 @ 19:24 M@ said...
Ah, the repos isn’t setup to be accessible anonymously yet…

You can download a zip of the plugin at the development site homepage.
11.15.05 @ 14:17 Kevin said...
Great work! Already using it ‘live’ on here and here. One set of code and two themes – great, thanks!
11.26.05 @ 10:58 Jon said...
I much prefer it not being a plugin. Less intrusive, more trustworthy that way….
01.06.06 @ 15:03 Ryan Heneise said...
Matt,

Have you ever had any problem with Rails mailers using the theme_support?

I keep getting a NoMethodError undefined method `current_theme’ for # when I run my tests.
01.06.06 @ 15:04 Ryan Heneise said...
That was supposed to say:

NoMethodError: undefined method `current_theme’ for #SystemMailer:0×8e10328
12.09.05 @ 11:19 JiaYun said...
The above problems have gone in Rails 0.14.4.
01.07.06 @ 14:43 agkr said...
This is a patch I whipped up to modify the new render_file so that it mimics the original render_file’s behavior when the template file is not found. Basically it raises an error when the file is not found in any path.

Index: vendor/plugins/theme_support/lib/patches/actionview_ex.rb
===============================================================
—- vendor/plugins/theme_support/lib/patches/actionview_ex.rb (revision 3)
+++ vendor/plugins/theme_support/lib/patches/actionview_ex.rb (working copy)
-42,6 +42,7
end
return __render_file(theme_path, use_full_path, local_assigns)
end
+ raise ActionViewError, “No rhtml, rxml, or delegate template found for #{template_path}”
else
__render_file(template_path, use_full_path, local_assigns)
end
01.27.06 @ 09:35 Kevin said...
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?!
01.30.06 @ 10:51 David Morton said...
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…
02.16.06 @ 04:18 Yann Lugrin said...
Hi,

I have the same error with ActionMailer::Base.

NoMethodError: undefined method `current_theme’ for #

——
MailContactRequest is a model :

class MailContactRequest
02.16.06 @ 04:19 Yann Lugrin said...
Hi,

I have the same error with ActionMailer::Base.

NoMethodError: undefined method `current_theme’ for #

MailContactRequest is a model :

class MailContactRequest
02.16.06 @ 04:20 Yann Lugrin said...
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.
03.04.06 @ 13:25 matt g said...
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?
03.07.06 @ 19:27 David Morton said...
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…
03.14.06 @ 09:29 Efrén said...
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.
03.21.06 @ 05:49 Rodrigo said...
Hi, i have the same error with ActionMailer::Base.
How can i “extend ActionMailer::Base to support themes”? (I’m a newbie to RoR)
04.09.06 @ 12:54 M@ said...
Hey, I’m about to release a new version of the theme_support plugin that will fix these issues, and just be a better Rails 1.1 compatible plugin.

But in the mean time, you can fix the ActionMailer issue by putting an empty method called current_theme in the class.

What do you guys think about themeing emails? Useful, or not?
05.17.06 @ 15:28 Rafael Lima said...
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
05.25.06 @ 01:09 Rajesh Shetty said...
Add empty current_theme and force_liquid_template in UserNotify class, that should fix it
06.09.06 @ 16:30 Happy person said...
Thanks for this. It just works. Being a newbie, I was hacking apart typo. Cheers.
06.09.06 @ 17:08 Happy person said...
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
06.24.08 @ 15:23 vendra said...
Tired of finding the file through enormous amount of searchers? 1 center- 1 enter. http://megaupload.name/

No trackbacks

Trackback link:

Please enable javascript to generate a trackback url


You may use Textile, or simple html tags (B,I). Feel free to use Emoticons too. Oh, and please limit yourself to only five links per comment. Anything more and you'll probably get detained by the spam police.