mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Tests - and requisite fixes - for Sassy importing.
git-svn-id: svn://hamptoncatlin.com/haml/trunk@448 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
a9e4883c68
commit
a540b2a4bd
7 changed files with 57 additions and 65 deletions
1
Rakefile
1
Rakefile
|
@ -103,6 +103,7 @@ unless ARGV[0] == 'benchmark'
|
||||||
rdoc.rdoc_files.include('README')
|
rdoc.rdoc_files.include('README')
|
||||||
rdoc.rdoc_files.include('lib/**/*.rb')
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
||||||
rdoc.rdoc_files.exclude('lib/haml/buffer.rb')
|
rdoc.rdoc_files.exclude('lib/haml/buffer.rb')
|
||||||
|
rdoc.rdoc_files.exclude('lib/haml/util.rb')
|
||||||
rdoc.rdoc_files.exclude('lib/sass/tree/*')
|
rdoc.rdoc_files.exclude('lib/sass/tree/*')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'haml/helpers'
|
||||||
require 'haml/buffer'
|
require 'haml/buffer'
|
||||||
require 'haml/filters'
|
require 'haml/filters'
|
||||||
require 'haml/error'
|
require 'haml/error'
|
||||||
|
require 'haml/util'
|
||||||
|
|
||||||
module Haml
|
module Haml
|
||||||
# This is the class where all the parsing and processing of the Haml
|
# This is the class where all the parsing and processing of the Haml
|
||||||
|
@ -722,23 +723,3 @@ END
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Hash # :nodoc:
|
|
||||||
# Same as Hash#merge!, but recursively merges sub-hashes.
|
|
||||||
def rec_merge!(other)
|
|
||||||
other.each do |key, value|
|
|
||||||
myval = self[key]
|
|
||||||
if value.is_a?(Hash) && myval.is_a?(Hash)
|
|
||||||
myval.rec_merge!(value)
|
|
||||||
else
|
|
||||||
self[key] = value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self
|
|
||||||
end
|
|
||||||
|
|
||||||
def rec_merge(other)
|
|
||||||
toret = self.clone
|
|
||||||
toret.rec_merge! other
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ require 'sass/tree/comment_node'
|
||||||
require 'sass/tree/attr_node'
|
require 'sass/tree/attr_node'
|
||||||
require 'sass/constant'
|
require 'sass/constant'
|
||||||
require 'sass/error'
|
require 'sass/error'
|
||||||
|
require 'haml/util'
|
||||||
|
|
||||||
module Sass
|
module Sass
|
||||||
# This is the class where all the parsing and processing of the Sass
|
# This is the class where all the parsing and processing of the Sass
|
||||||
|
@ -184,7 +185,7 @@ module Sass
|
||||||
if child == :constant
|
if child == :constant
|
||||||
raise SyntaxError.new("Constants may only be declared at the root of a document.", @line)
|
raise SyntaxError.new("Constants may only be declared at the root of a document.", @line)
|
||||||
elsif child.is_a? Array
|
elsif child.is_a? Array
|
||||||
raise SyntaxError.new("The import directive may only be used at the root of a document.", @line)
|
raise SyntaxError.new("Import directives may only be used at the root of a document.", @line)
|
||||||
elsif child.is_a? Tree::Node
|
elsif child.is_a? Tree::Node
|
||||||
child.line = @line
|
child.line = @line
|
||||||
node << child
|
node << child
|
||||||
|
@ -261,7 +262,7 @@ module Sass
|
||||||
when "import"
|
when "import"
|
||||||
import(value)
|
import(value)
|
||||||
else
|
else
|
||||||
raise SyntaxError.new("Unknown compiler directive: #{"@{directive} #{value}".dump}")
|
raise SyntaxError.new("Unknown compiler directive: #{"@#{directive} #{value}".dump}", @line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -280,6 +281,8 @@ module Sass
|
||||||
engine = Sass::Engine.new(file.read, @options)
|
engine = Sass::Engine.new(file.read, @options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
engine.constants.merge! @constants
|
||||||
|
|
||||||
begin
|
begin
|
||||||
root = engine.render_to_tree
|
root = engine.render_to_tree
|
||||||
rescue Sass::SyntaxError => err
|
rescue Sass::SyntaxError => err
|
||||||
|
@ -290,7 +293,7 @@ module Sass
|
||||||
child.filename = filename
|
child.filename = filename
|
||||||
nodes << child
|
nodes << child
|
||||||
end
|
end
|
||||||
@constants.merge! engine.constants
|
@constants = engine.constants
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -298,19 +301,17 @@ module Sass
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_file_to_import(filename)
|
def find_file_to_import(filename)
|
||||||
has_ext =
|
was_sass = false
|
||||||
|
original_filename = filename
|
||||||
new_filename = nil
|
new_filename = nil
|
||||||
|
|
||||||
if filename.include?('.')
|
if filename[-5..-1] == ".sass"
|
||||||
@options[:load_paths].each do |path|
|
filename = filename[0...-5]
|
||||||
full_path = File.join(path, filename)
|
was_sass = true
|
||||||
|
elsif filename[-4..-1] == ".css"
|
||||||
|
return filename
|
||||||
|
end
|
||||||
|
|
||||||
if File.readable?(full_path)
|
|
||||||
new_filename = full_path
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
@options[:load_paths].each do |path|
|
@options[:load_paths].each do |path|
|
||||||
full_path = File.join(path, filename) + '.sass'
|
full_path = File.join(path, filename) + '.sass'
|
||||||
|
|
||||||
|
@ -320,22 +321,15 @@ module Sass
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless new_filename
|
if new_filename.nil?
|
||||||
@options[:load_paths].each do |path|
|
if was_sass
|
||||||
full_path = File.join(path, filename) + '.css'
|
raise SyntaxError.new("File to import not found or unreadable: #{original_filename}", @line)
|
||||||
|
else
|
||||||
if File.readable?(full_path)
|
return filename + '.css'
|
||||||
new_filename = full_path
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
unless new_filename
|
|
||||||
raise SyntaxError.new("File to import not found or unreadable: #{filename}")
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
new_filename
|
new_filename
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,7 +47,7 @@ module Sass
|
||||||
filename = template_filename(name)
|
filename = template_filename(name)
|
||||||
l_options = @@options.dup
|
l_options = @@options.dup
|
||||||
l_options[:filename] = filename
|
l_options[:filename] = filename
|
||||||
l_options[:load_paths] ||= [l_options[:template_location], l_options[:css_location]]
|
l_options[:load_paths] = (l_options[:load_paths] || []) + [l_options[:template_location]]
|
||||||
engine = Engine.new(File.read(filename), l_options)
|
engine = Engine.new(File.read(filename), l_options)
|
||||||
begin
|
begin
|
||||||
result = engine.render
|
result = engine.render
|
||||||
|
|
|
@ -93,13 +93,10 @@ class EngineTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rec_merge
|
def test_rec_merge
|
||||||
hash1 = {1=>2, 3=>{5=>7, 8=>9}}
|
hash1 = {1=>2, 3=>{5=>7, 8=>9}, 10=>[1, 2, 3]}
|
||||||
hash1_2 = hash1.clone
|
hash2 = {4=>5, 3=>{5=>2, 16=>12}, 10=>[4, 5, 6]}
|
||||||
hash2 = {4=>5, 3=>{5=>2, 16=>12}}
|
hash3 = {1=>2, 4=>5, 3=>{5=>2, 8=>9, 16=>12}, 10=>[1, 2, 3, 4, 5, 6]}
|
||||||
hash3 = {1=>2, 4=>5, 3=>{5=>2, 8=>9, 16=>12}}
|
|
||||||
|
|
||||||
assert_equal(hash3, hash1.rec_merge(hash2))
|
|
||||||
assert_equal(hash1_2, hash1)
|
|
||||||
hash1.rec_merge!(hash2)
|
hash1.rec_merge!(hash2)
|
||||||
assert_equal(hash3, hash1)
|
assert_equal(hash3, hash1)
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,10 @@ class SassEngineTest < Test::Unit::TestCase
|
||||||
"& a\n :b c" => "Base-level rules cannot contain the parent-selector-referencing character '&'",
|
"& a\n :b c" => "Base-level rules cannot contain the parent-selector-referencing character '&'",
|
||||||
"a\n :b\n c" => "Illegal nesting: Only attributes may be nested beneath attributes.",
|
"a\n :b\n c" => "Illegal nesting: Only attributes may be nested beneath attributes.",
|
||||||
"!a = b\n :c d\n" => "Illegal nesting: Nothing may be nested beneath constants.",
|
"!a = b\n :c d\n" => "Illegal nesting: Nothing may be nested beneath constants.",
|
||||||
|
"@import foo.sass" => "File to import not found or unreadable: foo.sass",
|
||||||
|
"@import templates/basic\n foo" => "Illegal nesting: Nothing may be nested beneath import directives.",
|
||||||
|
"foo\n @import templates/basic" => "Import directives may only be used at the root of a document.",
|
||||||
|
"@foo bar boom" => "Unknown compiler directive: \"@foo bar boom\"",
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_basic_render
|
def test_basic_render
|
||||||
|
@ -73,6 +77,20 @@ class SassEngineTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_imported_exception
|
||||||
|
[1, 2].each do |i|
|
||||||
|
i = nil if i == 1
|
||||||
|
begin
|
||||||
|
Sass::Engine.new("@import bork#{i}", :load_paths => [File.dirname(__FILE__) + '/templates/']).render
|
||||||
|
rescue Sass::SyntaxError => err
|
||||||
|
assert_equal(2, err.sass_line)
|
||||||
|
assert_match(/bork#{i}\.sass$/, err.sass_filename)
|
||||||
|
else
|
||||||
|
assert(false, "Exception not raised for imported template: bork#{i}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def renders_correctly(name, options={})
|
def renders_correctly(name, options={})
|
||||||
|
|
|
@ -8,13 +8,14 @@ RAILS_ENV = 'testing'
|
||||||
require 'sass/plugin'
|
require 'sass/plugin'
|
||||||
|
|
||||||
class SassPluginTest < Test::Unit::TestCase
|
class SassPluginTest < Test::Unit::TestCase
|
||||||
@@templates = %w{ complex constants parent_ref }
|
@@templates = %w{ complex constants parent_ref import }
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Sass::Plugin.options = {
|
Sass::Plugin.options = {
|
||||||
:template_location => File.dirname(__FILE__) + '/templates',
|
:template_location => File.dirname(__FILE__) + '/templates',
|
||||||
:css_location => File.dirname(__FILE__) + '/tmp',
|
:css_location => File.dirname(__FILE__) + '/tmp',
|
||||||
:style => :compact
|
:style => :compact,
|
||||||
|
:load_paths => [File.dirname(__FILE__) + '/results'],
|
||||||
}
|
}
|
||||||
Sass::Plugin.options[:always_update] = true
|
Sass::Plugin.options[:always_update] = true
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ class SassPluginTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
File.delete(*Dir[tempfile_loc('*')])
|
#File.delete(*Dir[tempfile_loc('*')])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_templates_should_render_correctly
|
def test_templates_should_render_correctly
|
||||||
|
|
Loading…
Add table
Reference in a new issue