Module Sass::Plugin
In: lib/sass/plugin.rb
StandardError SyntaxError ValueNode CommentNode DirectiveNode AttrNode RuleNode Node Literal Number Color Nil String CSS Engine Operation lib/sass/css.rb lib/sass/error.rb lib/sass/engine.rb lib/sass/tree/value_node.rb lib/sass/tree/node.rb lib/sass/tree/comment_node.rb lib/sass/tree/directive_node.rb lib/sass/tree/rule_node.rb lib/sass/tree/attr_node.rb Tree Plugin lib/sass/constant/number.rb lib/sass/constant/operation.rb lib/sass/constant/nil.rb lib/sass/constant/literal.rb lib/sass/constant/color.rb lib/sass/constant/string.rb Constant Sass dot/m_33_0.png

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.

Methods

Public Class methods

Whether or not Sass has ever checked if the stylesheets need updates (in this Ruby instance).

[Source]

    # File lib/sass/plugin.rb, line 20
20:       def checked_for_updates
21:         @@checked_for_updates
22:       end

Get the options ready to be passed to the Sass::Engine

[Source]

    # File lib/sass/plugin.rb, line 38
38:       def engine_options(additional_options = {})
39:         opts = options.dup.merge(additional_options)
40:         opts[:load_paths] = load_paths(opts)
41:         opts
42:       end

Gets various options for Sass. See README.rdoc for details.

[Source]

    # File lib/sass/plugin.rb, line 28
28:       def options
29:         @@options
30:       end

Sets various options for Sass.

[Source]

    # File lib/sass/plugin.rb, line 33
33:       def options=(value)
34:         @@options.merge!(value)
35:       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 49
49:       def update_stylesheets
50:         return if options[:never_update]
51: 
52:         @@checked_for_updates = true
53:         Dir.glob(File.join(options[:template_location], "**", "*.sass")).entries.each do |file|
54: 
55:           # Get the relative path to the file with no extension
56:           name = file.sub(options[:template_location] + "/", "")[0...-5]
57: 
58:           if !forbid_update?(name) && (options[:always_update] || stylesheet_needs_update?(name))
59:             css = css_filename(name)
60:             File.delete(css) if File.exists?(css)
61: 
62:             filename = template_filename(name)
63:             engine = Engine.new(File.read(filename), engine_options(:filename => filename))
64:             result = begin
65:                        engine.render
66:                      rescue Exception => e
67:                        exception_string(e)
68:                      end
69: 
70:             # Create any directories that might be necessary
71:             dirs = [options[:css_location]]
72:             name.split("/")[0...-1].each { |dir| dirs << "#{dirs[-1]}/#{dir}" }
73:             dirs.each { |dir| Dir.mkdir(dir) unless File.exist?(dir) }
74: 
75:             # Finally, write the file
76:             File.open(css, 'w') do |file|
77:               file.print(result)
78:             end
79:           end
80:         end
81:       end

Private Class methods

[Source]

     # File lib/sass/plugin.rb, line 133
133:       def css_filename(name)
134:         "#{options[:css_location]}/#{name}.css"
135:       end

[Source]

     # File lib/sass/plugin.rb, line 158
158:       def dependencies(filename)
159:         File.readlines(filename).grep(/^@import /).map do |line|
160:           line[8..-1].split(',').map do |inc|
161:             Sass::Engine.find_file_to_import(inc.strip, load_paths)
162:           end
163:         end.flatten.grep(/\.sass$/)
164:       end

[Source]

     # File lib/sass/plugin.rb, line 151
151:       def dependency_updated?(css_mtime)
152:         lambda do |dep|
153:           File.mtime(dep) > css_mtime ||
154:             dependencies(dep).any?(&dependency_updated?(css_mtime))
155:         end
156:       end

[Source]

     # File lib/sass/plugin.rb, line 89
 89:       def exception_string(e)
 90:         if options[:full_exception]
 91:           e_string = "#{e.class}: #{e.message}"
 92: 
 93:           if e.is_a? Sass::SyntaxError
 94:             e_string << "\non line #{e.sass_line}"
 95: 
 96:             if e.sass_filename
 97:               e_string << " of #{e.sass_filename}"
 98: 
 99:               if File.exists?(e.sass_filename)
100:                 e_string << "\n\n"
101: 
102:                 min = [e.sass_line - 5, 0].max
103:                 File.read(e.sass_filename).rstrip.split("\n")[
104:                   min .. e.sass_line + 5
105:                 ].each_with_index do |line, i|
106:                   e_string << "#{min + i + 1}: #{line}\n"
107:                 end
108:               end
109:             end
110:           end
111:           "/*\n\#{e_string}\n\nBacktrace:\\n\#{e.backtrace.join(\"\\n\")}\n*/\nbody:before {\n  white-space: pre;\n  font-family: monospace;\n  content: \"\#{e_string.gsub('\"', '\\\"').gsub(\"\\n\", '\\\\A ')}\"; }\n"
112:           # Fix an emacs syntax-highlighting hiccup: '
113:         else
114:           "/* Internal stylesheet error */"
115:         end
116:       end

[Source]

     # File lib/sass/plugin.rb, line 137
137:       def forbid_update?(name)
138:         name.sub(/^.*\//, '')[0] == ?_
139:       end

[Source]

    # File lib/sass/plugin.rb, line 85
85:       def load_paths(opts = options)
86:         (opts[:load_paths] || []) + [options[:template_location]]
87:       end

[Source]

     # File lib/sass/plugin.rb, line 141
141:       def stylesheet_needs_update?(name)
142:         if !File.exists?(css_filename(name))
143:           return true
144:         else
145:           css_mtime = File.mtime(css_filename(name))
146:           File.mtime(template_filename(name)) > css_mtime ||
147:             dependencies(template_filename(name)).any?(&dependency_updated?(css_mtime))
148:         end
149:       end

[Source]

     # File lib/sass/plugin.rb, line 129
129:       def template_filename(name)
130:         "#{options[:template_location]}/#{name}.sass"
131:       end

[Validate]