diff --git a/lib/sass/engine.rb b/lib/sass/engine.rb index 64deb530..d4e73e92 100644 --- a/lib/sass/engine.rb +++ b/lib/sass/engine.rb @@ -331,7 +331,6 @@ module Sass def find_file_to_import(filename) was_sass = false original_filename = filename - new_filename = nil if filename[-5..-1] == ".sass" filename = filename[0...-5] @@ -340,14 +339,7 @@ module Sass return filename end - @options[:load_paths].each do |path| - full_path = File.join(path, filename) + '.sass' - - if File.readable?(full_path) - new_filename = full_path - break - end - end + new_filename = find_full_path("#{filename}.sass") if new_filename.nil? if was_sass @@ -359,5 +351,17 @@ module Sass new_filename end end + + def find_full_path(filename) + @options[:load_paths].each do |path| + ["_#{filename}", filename].each do |name| + full_path = File.join(path, name) + if File.readable?(full_path) + return full_path + end + end + end + nil + end end end diff --git a/lib/sass/plugin.rb b/lib/sass/plugin.rb index 7165fc87..d8b29edd 100644 --- a/lib/sass/plugin.rb +++ b/lib/sass/plugin.rb @@ -42,7 +42,7 @@ module Sass # 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) + if !forbid_update?(name) && (options[:always_update] || stylesheet_needs_update?(name)) css = css_filename(name) File.delete(css) if File.exists?(css) @@ -108,6 +108,10 @@ module Sass "#{@@options[:css_location]}/#{name}.css" end + def forbid_update?(name) + name[0] == ?_ + end + def stylesheet_needs_update?(name) !File.exists?(css_filename(name)) || (File.mtime(template_filename(name)) - 2) > File.mtime(css_filename(name)) end diff --git a/test/sass/plugin_test.rb b/test/sass/plugin_test.rb index 00c10be3..2030524a 100644 --- a/test/sass/plugin_test.rb +++ b/test/sass/plugin_test.rb @@ -21,10 +21,10 @@ class SassPluginTest < Test::Unit::TestCase :load_paths => [File.dirname(__FILE__) + '/results'], } Sass::Plugin.options[:always_update] = true - + Sass::Plugin.update_stylesheets end - + def teardown FileUtils.rm_r File.dirname(__FILE__) + '/tmp' end @@ -32,14 +32,14 @@ class SassPluginTest < Test::Unit::TestCase def test_templates_should_render_correctly @@templates.each { |name| assert_renders_correctly(name) } end - + def test_no_update File.delete(tempfile_loc('basic')) assert Sass::Plugin.stylesheet_needs_update?('basic') Sass::Plugin.update_stylesheets assert !Sass::Plugin.stylesheet_needs_update?('basic') end - + def test_exception_handling File.delete(tempfile_loc('bork')) Sass::Plugin.update_stylesheets @@ -59,29 +59,33 @@ class SassPluginTest < Test::Unit::TestCase Sass::Plugin.const_set('RAILS_ENV', 'testing') end - + def test_controller_process File.delete(tempfile_loc('basic')) assert Sass::Plugin.stylesheet_needs_update?('basic') - + ActionController::Base.new.process - + assert !Sass::Plugin.stylesheet_needs_update?('basic') end + def test_doesnt_render_partials + assert !File.exists?(tempfile_loc('_partial')) + end + private - + def assert_renders_correctly(name) File.read(result_loc(name)).split("\n").zip(File.read(tempfile_loc(name)).split("\n")).each_with_index do |pair, line| message = "template: #{name}\nline: #{line + 1}" assert_equal(pair.first, pair.last, message) end end - + def tempfile_loc(name) File.dirname(__FILE__) + "/tmp/#{name}.css" end - + def result_loc(name) File.dirname(__FILE__) + "/results/#{name}.css" end @@ -95,7 +99,7 @@ end class Sass::Engine alias_method :old_render, :render - + def render raise "bork bork bork!" if @template[0] == "{bork now!}" old_render diff --git a/test/sass/results/import.css b/test/sass/results/import.css index bd285caf..61aaf7ea 100644 --- a/test/sass/results/import.css +++ b/test/sass/results/import.css @@ -24,4 +24,6 @@ body { font: Arial; background: blue; } @import basic.css @import ../results/complex.css +#foo { background-color: #baf; } + nonimported { myconst: hello; otherconst: goodbye; } diff --git a/test/sass/templates/_partial.sass b/test/sass/templates/_partial.sass new file mode 100644 index 00000000..bef627d2 --- /dev/null +++ b/test/sass/templates/_partial.sass @@ -0,0 +1,2 @@ +#foo + :background-color #baf diff --git a/test/sass/templates/import.sass b/test/sass/templates/import.sass index d286c1d6..6115c6b3 100644 --- a/test/sass/templates/import.sass +++ b/test/sass/templates/import.sass @@ -1,6 +1,6 @@ !preconst = hello -@import importee, basic, basic.css, ../results/complex.css +@import importee, basic, basic.css, ../results/complex.css, partial nonimported :myconst = !preconst