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

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

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