Added support for nested Sass subdirectories. Credit goes to Robin Ward!

git-svn-id: svn://hamptoncatlin.com/haml/trunk@500 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2007-05-03 09:04:20 +00:00
parent cc654e0890
commit 5cd1dd3c11
6 changed files with 30 additions and 9 deletions

View File

@ -37,9 +37,11 @@ module Sass
# from <tt>options[:templates]</tt>
# if it does.
def update_stylesheets
Dir[options[:template_location] + '/*.sass'].each do |file|
name = File.basename(file)[0...-5]
Dir.glob(File.join(options[:template_location], "**", "*.sass")).entries.each do |file|
# Get the relative path to the file with no extension
name = file.sub(options[:template_location] + "/", "")[0...-5]
if options[:always_update] || stylesheet_needs_update?(name)
css = css_filename(name)
File.delete(css) if File.exists?(css)
@ -79,7 +81,12 @@ module Sass
end
end
Dir.mkdir(l_options[:css_location]) unless File.exist?(l_options[:css_location])
# Create any directories that might be necessary
dirs = [l_options[:css_location]]
name.split("/")[0...-1].each { |dir| dirs << "#{dirs[-1]}/#{dir}" }
dirs.each { |dir| Dir.mkdir(dir) unless File.exist?(dir) }
# Finally, write the file
File.open(css, 'w') do |file|
file.print(result)
end

View File

@ -1,16 +1,19 @@
#!/usr/bin/env ruby
require 'test/unit'
require File.dirname(__FILE__) + '/../../lib/sass'
RAILS_ENV = 'testing'
require 'test/unit'
require 'fileutils'
require File.dirname(__FILE__) + '/../../lib/sass'
require 'sass/plugin'
class SassPluginTest < Test::Unit::TestCase
@@templates = %w{ complex constants parent_ref import alt }
@@templates = %w{
complex constants parent_ref import alt
subdir/subdir subdir/nested_subdir/nested_subdir
}
def setup
FileUtils.mkdir File.dirname(__FILE__) + '/tmp'
Sass::Plugin.options = {
:template_location => File.dirname(__FILE__) + '/templates',
:css_location => File.dirname(__FILE__) + '/tmp',
@ -23,7 +26,7 @@ class SassPluginTest < Test::Unit::TestCase
end
def teardown
File.delete(*Dir[tempfile_loc('*')])
FileUtils.rm_r File.dirname(__FILE__) + '/tmp'
end
def test_templates_should_render_correctly

View File

@ -0,0 +1 @@
#pi { width: 314px; }

View File

@ -0,0 +1 @@
#subdir { font-size: 20px; font-weight: bold; }

View File

@ -0,0 +1,3 @@
#pi
:width 314px

View File

@ -0,0 +1,6 @@
#subdir
:font
:size 20px
:weight bold