Add Theming Engine to Your Rails Application
I've written about the disguise gem before, but I've made enough changes that it warrants a new blog post. I noticed a few performance problems which have now been fixed and the configuration has been cleaned up a bit.
Disguise makes it simple to swap out the views used by your rails application either by selecting a theme using an admin UI or by changing out the theme based on the current url. For most apps the feature is probably not relevant, but if you are building a piece of software like a blog or social network then letting your users customize the look of the site is crucial to adoption.
Find the install instructions on the project's github account.
While setting a given theme works fine and doesn't incur much of a performance hit beyond method call, swapping out the theme based on the current domain can incur a performance hit since it reloads the localization strings. Here's the bit of code that swaps the views:
def setup_theme
return if !Disguise::Config.themes_enabled
return if current_theme.blank? || current_theme.name.blank?
theme_view_path = File.join(Disguise::Config.theme_full_base_path, current_theme.name, 'views')
if self.view_paths.first == theme_view_path
return
else
return if !theme_exists(theme_view_path)
clean_theme_view_path
self.prepend_view_path(theme_view_path)
clean_theme_locale
set_theme_locale
I18n.reload!
end
end
I'm hoping to find a way to improve performance when changing themes, but for now be aware that changing themes based on domains is a work in progress and shouldn't be used in a production environment.
More from jbasdf
- A copy of ApplicationController has been removed from the module tree but is still active! And can’t dup NilClass
- How New Carpet and Rattlesnake turned me into a Consultant or What the Hell Happened?
- Mac OSX and the Samsung ML1740 on a network
- Ruby on Rails i18n with the Rails I18n Textmate bundle
- Rails Conf Intro from Chad Fowler and Some Stuff from the Mountain West Ruby Conference
Justin Ball is a software consultant and entrepreneur with a passion for Ruby. He evolved from a C++ and .Net monkey into a python programmer and finally found Ruby. In the rare moments when he isn't writing code, talking about code or measuring his code productivity in profanity per hour, you can find him on his bike in the mountains or on the roads surrounding Cache Valley. 









