Over a million developers have joined DZone.

View All Colors From A Set Of Stylesheets

Rake task to grep out colors from a set of CSS stylesheets and display them on a web page. Default configuration works for OS X Safari and a Rails application.

BROWSER = "/Applications/Safari.app/Contents/MacOS/Safari"
CSS_FILES = "#{RAILS_ROOT}/public/stylesheets/**/*.css"

task :colors do
  require "tempfile"
  colors = Dir[CSS_FILES].map(&File.method(:read)).join.scan(/\#[0-9a-f]{3,6}/i).map{|c| c.upcase}.uniq
  Tempfile.open "colors" do |f|
    f.write <<-EOHTML
" }.join} EOHTML system BROWSER, f.path end end

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}