#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] ...
Get Ruby by Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.