Module Sass::Plugin
In: lib/sass/plugin.rb

This module contains methods that ActionController calls to automatically update Sass templates that need updating. It wasn‘t designed to be used outside of the context of ActionController.

Methods

Public Class methods

Gets various options for Sass. See README for details.

[Source]

    # File lib/sass/plugin.rb, line 25
25:       def options
26:         @@options
27:       end

Sets various options for Sass.

[Source]

    # File lib/sass/plugin.rb, line 30
30:       def options=(value)
31:         @@options.merge!(value)
32:       end

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.

[Source]

    # File lib/sass/plugin.rb, line 39
39:       def update_stylesheets
40:         Dir.glob(File.join(options[:template_location], "**", "*.sass")).entries.each do |file|
41:           
42:           # Get the relative path to the file with no extension
43:           name = file.sub(options[:template_location] + "/", "")[0...-5]
44:                     
45:           if options[:always_update] || stylesheet_needs_update?(name)
46:             css = css_filename(name)
47:             File.delete(css) if File.exists?(css)
48:             
49:             filename = template_filename(name)
50:             l_options = @@options.dup
51:             l_options[:filename] = filename
52:             l_options[:load_paths] = (l_options[:load_paths] || []) + [l_options[:template_location]]
53:             engine = Engine.new(File.read(filename), l_options)
54:             begin
55:               result = engine.render
56:             rescue Exception => e
57:               if RAILS_ENV != "production"
58:                 e_string = "#{e.class}: #{e.message}"
59: 
60:                 if e.is_a? Sass::SyntaxError
61:                   e_string << "\non line #{e.sass_line}"
62: 
63:                   if e.sass_filename
64:                     e_string << " of #{e.sass_filename}"
65: 
66:                     if File.exists?(e.sass_filename)
67:                       e_string << "\n\n"
68: 
69:                       min = [e.sass_line - 5, 0].max
70:                       File.read(e.sass_filename).rstrip.split("\n")[
71:                           min .. e.sass_line + 5
72:                       ].each_with_index do |line, i|
73:                         e_string << "#{min + i + 1}: #{line}\n"
74:                       end
75:                     end
76:                   end
77:                 end
78:                 result = "/*\n#{e_string}\n\nBacktrace:\n#{e.backtrace.join("\n")}\n*/"
79:               else
80:                 result = "/* Internal stylesheet error */"
81:               end
82:             end
83:             
84:             # Create any directories that might be necessary
85:             dirs = [l_options[:css_location]]
86:             name.split("/")[0...-1].each { |dir| dirs << "#{dirs[-1]}/#{dir}" }
87:             dirs.each { |dir| Dir.mkdir(dir) unless File.exist?(dir) }
88:             
89:             # Finally, write the file
90:             File.open(css, 'w') do |file|
91:               file.print(result)
92:             end
93:           end
94:         end
95:       end

[Validate]