Sass "partials" can be used - starting a Sass filename with an underscore means it won't be rendered, and can be imported without the underscore.

git-svn-id: svn://hamptoncatlin.com/haml/trunk@596 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2007-08-28 05:33:57 +00:00
parent 6e2c784c6a
commit 103c564cdc
6 changed files with 38 additions and 22 deletions

View File

@ -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

View File

@ -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

View File

@ -69,6 +69,10 @@ class SassPluginTest < Test::Unit::TestCase
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)

View File

@ -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; }

View File

@ -0,0 +1,2 @@
#foo
:background-color #baf

View File

@ -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