O'Reilly logo

Ruby by Example by Kevin C. Baird

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

#44 CSS Stylesheets, Part II (stylesheet2.rcss)

In many ways, this script is just a glorified hack of stylesheet.rcss. I separated it mainly to allow for comparison. The major difference between the two files is that stylesheet2.rcss generalizes the width values into a single function.

The Code

 /* This file outputs CSS data customized by user_agent using eruby. */ <% # define functions ❶ def width(type, user_agent) ❷ small = { 'alpha' => 11.8, 'beta' => 15.8, } ❸ large = { 'alpha' => 14, 'beta' => 18, } ❹ palm = { 'alpha' => 5, 'beta' => 7, } ❺ width = if (user_agent =~ /Windows/) small[type] if (user_agent =~ /Opera/) small[type] if (user_agent =~ /MSIE 6/) large[type] if (user_agent =~ /MSIE/) small[type] elsif (user_agent =~ /Palm/) palm[type] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required