I’ve read about Canny, but it doesn’t seem to enjoy a lot of versions or
users since it’s been released. I’ve read that Ruby natively supplies
template functionality. I need to know how easy it will be with Ruby to
re-skin a webapp. Also, whether Ruby or Ruby on Rails would be
preferable in this situation?
Note, I’m not looking for simple JSP functionality, but the ability to
go beyond that by having Ruby select a specific template at runtime, the
way I can do with Smarty. I want to abstract the template away so that
the end user will get the same URL regardless of the skin that’s used to
display it.
I’d appreciate whatever advice you can give.
Hi Irving,
It’s fairly simple to get the same functionality as Smarty.
In your application controller, just add:
before_filter :set_theme
private
def set_theme
ActionController::Base.template_root = File.join(RAILS_ROOT, ‘app/
views’, theme) if theme
end
def theme
session[:theme] = params[:theme] if params[:theme]
session[:theme]
end
That would allow you to place a folder in your app/views directory
with the name of your theme, and Rails will automatically load the
views from that folder instead.
If you’d like to place them in a separate folder, just change this:
def set_theme
ActionController::Base.template_root = File.join(RAILS_ROOT,
‘themes’, theme) if theme
end
This will allow you to create theme directories in the root of your
application.
Note that this will move the theme routing, so you will need to have
duplicates of all the theme files in the theme folder. There are
other ways to do it so that it only uses the themed version if the
file exists, which allows you to set themed portions and leave the
bulk of your app alone.
As far as a template language goes, check out liquid: http://
home.leetsoft.com/liquid
Best of luck,
Jeremy Hubert
Brilliant. Thank you. So it sounds like Canny is unnecessary. I
wonder why Canny was created.
By the way, can I get that same functionality from Ruby and Ruby on
Rails?