diff --git a/lib/sass/plugin.rb b/lib/sass/plugin.rb index da2a910d..fd63ebaf 100644 --- a/lib/sass/plugin.rb +++ b/lib/sass/plugin.rb @@ -37,9 +37,11 @@ module Sass # from options[:templates] # 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 diff --git a/test/sass/plugin_test.rb b/test/sass/plugin_test.rb index 5bf7e37c..d58c3572 100644 --- a/test/sass/plugin_test.rb +++ b/test/sass/plugin_test.rb @@ -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 diff --git a/test/sass/results/subdir/nested_subdir/nested_subdir.css b/test/sass/results/subdir/nested_subdir/nested_subdir.css new file mode 100644 index 00000000..7aadcfe6 --- /dev/null +++ b/test/sass/results/subdir/nested_subdir/nested_subdir.css @@ -0,0 +1 @@ +#pi { width: 314px; } \ No newline at end of file diff --git a/test/sass/results/subdir/subdir.css b/test/sass/results/subdir/subdir.css new file mode 100644 index 00000000..25c5c19b --- /dev/null +++ b/test/sass/results/subdir/subdir.css @@ -0,0 +1 @@ +#subdir { font-size: 20px; font-weight: bold; } \ No newline at end of file diff --git a/test/sass/templates/subdir/nested_subdir/nested_subdir.sass b/test/sass/templates/subdir/nested_subdir/nested_subdir.sass new file mode 100644 index 00000000..aae9eebf --- /dev/null +++ b/test/sass/templates/subdir/nested_subdir/nested_subdir.sass @@ -0,0 +1,3 @@ +#pi + :width 314px + \ No newline at end of file diff --git a/test/sass/templates/subdir/subdir.sass b/test/sass/templates/subdir/subdir.sass new file mode 100644 index 00000000..bbe9810f --- /dev/null +++ b/test/sass/templates/subdir/subdir.sass @@ -0,0 +1,6 @@ +#subdir + :font + :size 20px + :weight bold + + \ No newline at end of file