Module | Sass::Plugin |
In: |
lib/sass/plugin.rb
|
This module contains methods to aid in using Sass as a stylesheet-rendering plugin for various systems. Currently Rails/ActionController and Merb are supported out of the box.
Checks each stylesheet in options[:css_location] to see if it needs updating, and updates it using the corresponding template from options[:templates] if it does.
# File lib/sass/plugin.rb, line 35 35: def update_stylesheets 36: Dir.glob(File.join(options[:template_location], "**", "*.sass")).entries.each do |file| 37: 38: # Get the relative path to the file with no extension 39: name = file.sub(options[:template_location] + "/", "")[0...-5] 40: 41: if options[:always_update] || stylesheet_needs_update?(name) 42: css = css_filename(name) 43: File.delete(css) if File.exists?(css) 44: 45: filename = template_filename(name) 46: l_options = @@options.dup 47: l_options[:filename] = filename 48: l_options[:load_paths] = (l_options[:load_paths] || []) + [l_options[:template_location]] 49: engine = Engine.new(File.read(filename), l_options) 50: begin 51: result = engine.render 52: rescue Exception => e 53: if options[:full_exception] 54: e_string = "#{e.class}: #{e.message}" 55: 56: if e.is_a? Sass::SyntaxError 57: e_string << "\non line #{e.sass_line}" 58: 59: if e.sass_filename 60: e_string << " of #{e.sass_filename}" 61: 62: if File.exists?(e.sass_filename) 63: e_string << "\n\n" 64: 65: min = [e.sass_line - 5, 0].max 66: File.read(e.sass_filename).rstrip.split("\n")[ 67: min .. e.sass_line + 5 68: ].each_with_index do |line, i| 69: e_string << "#{min + i + 1}: #{line}\n" 70: end 71: end 72: end 73: end 74: result = "/*\n#{e_string}\n\nBacktrace:\n#{e.backtrace.join("\n")}\n*/" 75: else 76: result = "/* Internal stylesheet error */" 77: end 78: end 79: 80: # Create any directories that might be necessary 81: dirs = [l_options[:css_location]] 82: name.split("/")[0...-1].each { |dir| dirs << "#{dirs[-1]}/#{dir}" } 83: dirs.each { |dir| Dir.mkdir(dir) unless File.exist?(dir) } 84: 85: # Finally, write the file 86: File.open(css, 'w') do |file| 87: file.print(result) 88: end 89: end 90: end 91: end