I've just checked in version 1.4 of the
theme_support plugin. It contains quite a few bugfixes and updates. This version also integrates a couple of patches from akg and D.J. Vogel. Thanks guys!
Version 1.4 adds:
- Bugfixes, of course
- Better Rails 1.1 support
- ActionMailer theme support (experimental)
- Updates to the themeitem liquid tag
- Support for theme sub-directories
- Fleshed out the Theme object to make is easy to list all of the installed Themes
As a little background, the plugin is based on the theme system developed by the Typo guys and adds support for:
- Multiple concurrent themes
- A rails generator for creating a theme folder structure
- Rake tasks for pre-caching all of the themes for increased security and performance
- Overriding views with theme-specific rhtml or liquid templates (based on early Typo code)
- Forcing theme views to only allow liquid templates
- Made supporting themes as easy as using layouts
To install the plugin, go to your rails application root folder and run:
./script/plugin install http://mattmccray.com/svn/rails/plugins/theme_support
or, for you Windows folks:
ruby script\\plugin install http://mattmccray.com/svn/rails/plugins/theme_support
Look at the README in $/vendor/plugins/theme_support for more on implementing themes in your application.
Update: OK, you got me. You should really use the built-in Rails helper, cycle.
<table class="Grid">
<% for user in @users %>
<tr class="<%= cycle('Even', 'Odd') %>">
<td>
... Stuff Here
</td>
</tr>
<% end %>
</table>
Here's the helper I've been using lately for zebra striping table rows:
def zebra_stripe( index, even_class="Even", odd_class="Odd" )
index % 2 == 0 ? even_class : odd_class
end
In the view, you use the rubyesque
.each_with_index like this:
<table class="Grid">
<% @users.each_with_index do |user, i| %>
<tr class="<%= zebra_stripe(i) %>">
<td>
... Stuff Here
</td>
</tr>
<% end %>
</table>
Simple as that!