0
@@ -8,7 +8,6 @@ module Sass
0
- :template_location => './public/stylesheets/sass',
0
:css_location => './public/stylesheets',
0
:always_update => false,
0
@@ -35,44 +34,20 @@ module Sass
0
@@options.merge!(value)
0
- # Checks each stylesheet in <tt>options[:css_location]</tt>
0
- # to see if it needs updating,
0
- # and updates it using the corresponding template
0
- # from <tt>options[:templates]</tt>
0
+ # Checks each css stylesheet to see if it needs updating,
0
+ # and updates it using the corresponding sass template if it does.
0
return if options[:never_update]
0
@@checked_for_updates = true
0
- Dir.glob(File.join(options[:template_location], "**", "*.sass")).entries.each do |file|
0
- # Get the relative path to the file with no extension
0
- name = file.sub(options[:template_location] + "/", "")[0...-5]
0
- if !forbid_update?(name) && (options[:always_update] || stylesheet_needs_update?(name))
0
- css = css_filename(name)
0
- File.delete(css) if File.exists?(css)
0
- filename = template_filename(name)
0
- l_options = @@options.dup
0
- l_options[:css_filename] = css
0
- l_options[:filename] = filename
0
- l_options[:load_paths] = load_paths
0
- engine = Engine.new(File.read(filename), l_options)
0
- # Create any directories that might be necessary
0
- dirs = [l_options[:css_location]]
0
- name.split("/")[0...-1].each { |dir| dirs << "#{dirs[-1]}/#{dir}" }
0
- dirs.each { |dir| Dir.mkdir(dir) unless File.exist?(dir) }
0
- # Finally, write the file
0
- File.open(css, 'w') do |file|
0
+ template_location_map.each do |template_location, css_location|
0
+ Dir.glob(File.join(template_location, "**", "*.sass")).each do |file|
0
+ # Get the relative path to the file with no extension
0
+ name = file.sub(template_location + "/", "")[0...-5]
0
+ if !forbid_update?(name) && (options[:always_update] || stylesheet_needs_update?(name, template_location, css_location))
0
+ update_stylesheet(name, template_location, css_location)
0
@@ -80,8 +55,64 @@ module Sass
0
+ def update_stylesheet(name, template_location, css_location)
0
+ css = css_filename(name, css_location)
0
+ File.delete(css) if File.exists?(css)
0
+ filename = template_filename(name, template_location)
0
+ l_options = @@options.dup
0
+ l_options[:css_filename] = css
0
+ l_options[:filename] = filename
0
+ l_options[:load_paths] = load_paths
0
+ engine = Engine.new(File.read(filename), l_options)
0
+ # Create any directories that might be necessary
0
+ mkpath(css_location, name)
0
+ # Finally, write the file
0
+ File.open(css, 'w') do |file|
0
+ # Create any successive directories required to be able to write a file to: File.join(base,name)
0
+ def mkpath(base, name)
0
+ name.split('/')[0...-1].each { |dir| dirs << File.join(dirs[-1],dir) }
0
+ dirs.each { |dir| Dir.mkdir(dir) unless File.exist?(dir) }
0
- (options[:load_paths] || []) + [options[:template_location]]
0
+ (options[:load_paths] || []) + template_locations
0
+ def template_locations
0
+ location = (options[:template_location] || default_template_location)
0
+ if location.is_a?(String)
0
+ location.to_a.map { |l| l.first }
0
+ if !options[:template_location].is_a?(String)
0
+ options[:template_location].to_a.map { |l| l.last }
0
+ Array(options[:css_location])
0
+ # map of template locations to css locations
0
+ def template_location_map
0
+ template_locations.zip(css_locations).inject([]) do |memo, pair|
0
+ memo << [pair.first || memo.first.first, pair.last || memo.first.last]
0
def exception_string(e)
0
@@ -127,25 +158,39 @@ END
0
- def template_filename(name)
0
- "#{options[:template_location]}/#{name}.sass"
0
+ def default_css_location
0
+ Array(options[:css_location]).first
0
+ def default_template_location
0
+ if options[:template_location]
0
+ Array(options[:template_location]).first
0
+ File.join(default_css_location,'sass')
0
+ def template_filename(name, path = default_template_location)
0
+ "#{path}/#{name}.sass"
0
- def css_filename(name)
0
- "#{options[:css_location]}/#{name}.css"
0
+ def css_filename(name, path = default_css_location)
0
def forbid_update?(name)
0
name.sub(/^.*\//, '')[0] == ?_
0
- def stylesheet_needs_update?(name)
0
- if !File.exists?(css_filename(name))
0
+ def stylesheet_needs_update?(name, template_path, css_path)
0
+ css_file = css_filename(name, css_path)
0
+ template_file = template_filename(name, template_path)
0
+ if !File.exists?(css_file)
0
- css_mtime = File.mtime(css_filename(name))
0
- File.mtime(template_filename(name)) > css_mtime ||
0
- dependencies(template_filename(name)).any?(&dependency_updated?(css_mtime))
0
+ css_mtime = File.mtime(css_file)
0
+ File.mtime(template_file) > css_mtime ||
0
+ dependencies(template_file).any?(&dependency_updated?(css_mtime))
Comments
No one has commented yet.