Re: Good solution for managing stylesheets

Michael Schuerig
Fri, 19 Aug 2005 22:26:15 -0000

On Friday 19 August 2005 23:31, Jeffrey Moss wrote:
> Does anybody figure they have the perfect solution for managing
> stylesheets when using layouts and partials?

In this particular case I''m wondering if the effort is worth it. You
may
get better results, all in all, if you put everything into one
stylesheet. The consolidated stylesheet is probably bigger than any
combination of stylesheets you would use on one page otherwise, but it
has the advantage that it requires just one server hit.

If you''re keeping your stylesheets separate for organizational
purposes,
have a look at my rake task below. For one resulting stylesheet, I have
several ERb templates that are combined. The added benefit is that I
can use symbolic constants (well, actually variables) to factor out
commonalities, say colors and distances.

Michael


desc "Update stylesheets"
task :update_stylesheets do
  require ''erb''
  FileList[File.join(File.dirname(__FILE__),
''stylesheets/*/'')].each do
|stylesheet_dir|
    name = stylesheet_dir.sub(/\/$/, '''') +
''.css''
    puts "Updating #{name}..."
    src =
FileList["#{stylesheet_dir}/*.css"].sort.inject('''')
do |
result, f|
      result << File.read(f)
    end
    File.open(name, ''w+'') do |out|
      out.puts ERB.new(src).result.gsub(/^\s+/, '''')
    end
  end
end


--
Michael Schuerig                 Not only does lightning not strike
mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org       twice, it usually
doesn''t strike once.
http://www.schuerig.de/michael/  --Salman Rushdie, Fury