##### #// This is an example of how to use Iowa to intelligently deliver specific #// stylesheets based on some criteria. Differences in how browsers implement #// certain items sometimes mean that it is just easier to have two slightly #// different stylesheets than to try to get everything to work identically #// across all browsers with a single stylesheet. This implementation is #// simplistic, but even so, does seem to work alright in practice. #// #// This code will accomodate X different CSS files. It auto reloads them #// if they are changed, and caches them in memory for speedy delivery. ##### class Styles < Iowa::Component begin MSIErxp rescue NameError MSIErxp = Regexp.new('MSIE') end def styles @styles_mtimes = {'styles.css' => 0, 'styles_mozilla.css' => 0} unless @styles_mtimes begin @style_data = '' if MSIErxp.match session.context.request.headers_in['User-Agent'] style_file = 'styles.css' else style_file = 'styles_mozilla.css' end if File.stat(style_file).mtime.to_i > @styles_mtimes[style_file] File.open(style_file) {|fh| fh.each {|line| @style_data << line}} @styles_mtimes[style_file] = File.stat(style_file).mtime.to_i end rescue Exception => e # Maybe some sort of rudimentary hardcoded style? end @style_data end end