Merge branch 'cache-bug-fix' into stable

This commit is contained in:
Nathan Weizenbaum 2009-07-12 10:22:29 -04:00
commit 8d3f1403f3
6 changed files with 71 additions and 50 deletions

View File

@ -12,7 +12,7 @@ require 'sass/tree/if_node'
require 'sass/tree/while_node' require 'sass/tree/while_node'
require 'sass/tree/for_node' require 'sass/tree/for_node'
require 'sass/tree/debug_node' require 'sass/tree/debug_node'
require 'sass/tree/file_node' require 'sass/tree/import_node'
require 'sass/environment' require 'sass/environment'
require 'sass/script' require 'sass/script'
require 'sass/error' require 'sass/error'
@ -227,21 +227,23 @@ END
def build_tree(parent, line, root = false) def build_tree(parent, line, root = false)
@line = line.index @line = line.index
node = parse_line(parent, line, root) node_or_nodes = parse_line(parent, line, root)
# Node is a symbol if it's non-outputting, like a variable assignment, Array(node_or_nodes).each do |node|
# or an array if it's a group of nodes to add # Node is a symbol if it's non-outputting, like a variable assignment
return node unless node.is_a? Tree::Node next unless node.is_a? Tree::Node
node.line = line.index node.line = line.index
node.filename = line.filename node.filename = line.filename
if node.is_a?(Tree::CommentNode) if node.is_a?(Tree::CommentNode)
node.lines = line.children node.lines = line.children
else else
append_children(node, line.children, false) append_children(node, line.children, false)
end
end end
return node
node_or_nodes
end end
def append_children(parent, children, root) def append_children(parent, children, root)
@ -279,7 +281,7 @@ END
case child case child
when Tree::MixinDefNode when Tree::MixinDefNode
raise SyntaxError.new("Mixins may only be defined at the root of a document.", line.index) raise SyntaxError.new("Mixins may only be defined at the root of a document.", line.index)
when Tree::DirectiveNode, Tree::FileNode when Tree::ImportNode
raise SyntaxError.new("Import directives may only be used at the root of a document.", line.index) raise SyntaxError.new("Import directives may only be used at the root of a document.", line.index)
end end
end end
@ -365,7 +367,7 @@ END
# it's a CSS @import rule and we don't want to touch it. # it's a CSS @import rule and we don't want to touch it.
if directive == "import" && value !~ /^(url\(|")/ if directive == "import" && value !~ /^(url\(|")/
raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath import directives.", @line + 1) unless line.children.empty? raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath import directives.", @line + 1) unless line.children.empty?
import(value) value.split(/,\s*/).map {|f| Tree::ImportNode.new(f)}
elsif directive == "for" elsif directive == "for"
parse_for(line, root, value) parse_for(line, root, value)
elsif directive == "else" elsif directive == "else"
@ -470,27 +472,5 @@ END
offset = options[:offset] || 0 offset = options[:offset] || 0
Script.parse(script, line, offset, @options[:filename]) Script.parse(script, line, offset, @options[:filename])
end end
def import_paths
paths = (@options[:load_paths] || []).dup
paths.unshift(File.dirname(@options[:filename])) if @options[:filename]
paths
end
def import(files)
files.split(/,\s*/).map do |filename|
engine = nil
begin
filename = Sass::Files.find_file_to_import(filename, import_paths)
rescue Exception => e
raise SyntaxError.new(e.message, @line)
end
next Tree::DirectiveNode.new("@import url(#{filename})") if filename =~ /\.css$/
Tree::FileNode.new(filename)
end.flatten
end
end end
end end

View File

@ -5,10 +5,7 @@ module Sass::Tree
# only CSS directives like `@media` and `@font-face` become {DirectiveNode}s. # only CSS directives like `@media` and `@font-face` become {DirectiveNode}s.
# #
# `@import` is a bit of a weird case; # `@import` is a bit of a weird case;
# if it's importing a Sass file, # it becomes an {ImportNode}.
# it becomes a {FileNode},
# but if it's importing a plain CSS file,
# it becomes a {DirectiveNode}.
# #
# @see Sass::Tree # @see Sass::Tree
class DirectiveNode < Node class DirectiveNode < Node

View File

@ -3,10 +3,10 @@ module Sass
# A static node that wraps the {Sass::Tree} for an `@import`ed file. # A static node that wraps the {Sass::Tree} for an `@import`ed file.
# It doesn't have a functional purpose other than to add the `@import`ed file # It doesn't have a functional purpose other than to add the `@import`ed file
# to the backtrace if an error occurs. # to the backtrace if an error occurs.
class FileNode < Node class ImportNode < Node
# @param filename [String] The name of the imported file # @param imported_filename [String] The name of the imported file
def initialize(filename) def initialize(imported_filename)
@filename = filename @imported_filename = imported_filename
super() super()
end end
@ -30,12 +30,36 @@ module Sass
# @param environment [Sass::Environment] The lexical environment containing # @param environment [Sass::Environment] The lexical environment containing
# variable and mixin values # variable and mixin values
def perform!(environment) def perform!(environment)
self.children = Sass::Files.tree_for(filename, @options).children return unless full_filename = import
self.children = Sass::Files.tree_for(full_filename, @options).children
self.children = perform_children(environment) self.children = perform_children(environment)
rescue Sass::SyntaxError => e rescue Sass::SyntaxError => e
e.add_backtrace_entry(@filename) e.add_backtrace_entry(@filename)
raise e raise e
end end
private
def import_paths
paths = (@options[:load_paths] || []).dup
paths.unshift(File.dirname(@options[:filename])) if @options[:filename]
paths
end
def import
begin
full_filename = Sass::Files.find_file_to_import(@imported_filename, import_paths)
rescue Exception => e
raise SyntaxError.new(e.message, self.line)
end
if full_filename =~ /\.css$/
@to_s = "@import url(#{full_filename});"
return false
end
return full_filename
end
end end
end end
end end

View File

@ -126,8 +126,8 @@ class SassEngineTest < Test::Unit::TestCase
render("p\n\ta: b\n\tq\n\t\tc: d\n")) render("p\n\ta: b\n\tq\n\t\tc: d\n"))
end end
def test_exceptions EXCEPTION_MAP.each do |key, value|
EXCEPTION_MAP.each do |key, value| define_method("test_exception (#{key.inspect})") do
line = 10 line = 10
begin begin
Sass::Engine.new(key, :filename => __FILE__, :line => line).render Sass::Engine.new(key, :filename => __FILE__, :line => line).render

View File

@ -34,7 +34,7 @@ class SassPluginTest < Test::Unit::TestCase
end end
def test_update_needed_when_modified def test_update_needed_when_modified
sleep(1) sleep 1
FileUtils.touch(template_loc('basic')) FileUtils.touch(template_loc('basic'))
assert Sass::Plugin.stylesheet_needs_update?('basic', template_loc, tempfile_loc) assert Sass::Plugin.stylesheet_needs_update?('basic', template_loc, tempfile_loc)
Sass::Plugin.update_stylesheets Sass::Plugin.update_stylesheets
@ -42,7 +42,7 @@ class SassPluginTest < Test::Unit::TestCase
end end
def test_update_needed_when_dependency_modified def test_update_needed_when_dependency_modified
sleep(1) sleep 1
FileUtils.touch(template_loc('basic')) FileUtils.touch(template_loc('basic'))
assert Sass::Plugin.stylesheet_needs_update?('import', template_loc, tempfile_loc) assert Sass::Plugin.stylesheet_needs_update?('import', template_loc, tempfile_loc)
Sass::Plugin.update_stylesheets Sass::Plugin.update_stylesheets
@ -122,6 +122,21 @@ class SassPluginTest < Test::Unit::TestCase
assert !File.exists?(tempfile_loc('_partial')) assert !File.exists?(tempfile_loc('_partial'))
end end
## Regression
def test_cached_dependencies_update
FileUtils.mv(template_loc("basic"), template_loc("basic", "more_"))
set_plugin_opts :load_paths => [result_loc, template_loc(nil, "more_")]
sleep 1
FileUtils.touch(template_loc("basic", "more_"))
assert Sass::Plugin.stylesheet_needs_update?("import", template_loc, tempfile_loc)
Sass::Plugin.update_stylesheets
assert_renders_correctly("import")
ensure
FileUtils.mv(template_loc("basic", "more_"), template_loc("basic"))
end
private private
def assert_renders_correctly(*arguments) def assert_renders_correctly(*arguments)
@ -182,6 +197,11 @@ class SassPluginTest < Test::Unit::TestCase
:always_update => true, :always_update => true,
}.merge(overrides) }.merge(overrides)
end end
def wait_a_tick
time = Time.now
loop {break if Time.now.sec != time.sec}
end
end end
module Sass::Plugin module Sass::Plugin

View File

@ -3,7 +3,7 @@
=premixin =premixin
pre-mixin: here pre-mixin: here
@import importee, basic, basic.css, ../results/complex.css, partial @import importee.sass, basic.sass, basic.css, ../results/complex.css, partial.sass
nonimported nonimported
:myconst = !preconst :myconst = !preconst