1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Merge branch 'stable'

Conflicts:

	lib/sass/tree/attr_node.rb
	lib/sass/tree/node.rb
	lib/sass/tree/value_node.rb
This commit is contained in:
Nathan Weizenbaum 2009-02-19 20:12:23 -08:00
commit 51599f2064
6 changed files with 211 additions and 2 deletions

View file

@ -371,7 +371,7 @@ module Sass
def fold_commas(root)
prev_rule = nil
root.children.map! do |child|
next child unless Tree::RuleNode === child
next child unless child.is_a?(Tree::RuleNode)
if prev_rule && prev_rule.children == child.children
prev_rule.rule << ", #{child.rule}"

View file

@ -7,7 +7,11 @@ module Sass::Tree
@value = value
super(options)
end
def ==(other)
self.class == other.class && name == other.name && value == other.value && super
end
def to_s(tabs, parent_name = nil)
if value[-1] == ?;
raise Sass::SyntaxError.new("Invalid attribute: #{declaration.dump} (This isn't CSS!).", @line)

View file

@ -9,6 +9,10 @@ module Sass::Tree
super(options)
end
def ==(other)
self.value == other.value && super
end
def to_s(tabs = 0, parent_name = nil)
return if @style == :compressed

View file

@ -23,6 +23,10 @@ module Sass
children.last
end
def ==(other)
self.class == other.class && other.children == children
end
def to_s
result = String.new
children.each do |child|

View file

@ -10,6 +10,10 @@ module Sass::Tree
super(options)
end
def ==(other)
self.class == other.class && rules == other.rules && super
end
def rules
Array(rule)
end

193
test/sass/css2sass_test.rb Normal file
View file

@ -0,0 +1,193 @@
require 'test/unit'
require File.dirname(__FILE__) + '/../test_helper'
require 'sass/css'
class CSS2SassTest < Test::Unit::TestCase
def test_basic
css = <<CSS
h1 {
color: red;
}
CSS
assert_equal(<<SASS, css2sass(css))
h1
:color red
SASS
assert_equal(<<SASS, css2sass(css, :alternate => true))
h1
color: red
SASS
end
def test_nesting
assert_equal(<<SASS, css2sass(<<CSS))
li
:display none
a
:text-decoration none
span
:color yellow
&:hover
:text-decoration underline
SASS
li {
display: none;
}
li a {
text-decoration: none;
}
li a span {
color: yellow;
}
li a:hover {
text-decoration: underline;
}
CSS
end
def test_comments_multiline
css = <<CSS
/* comment */
elephant.rawr {
rampages: excessively;
}
/* actual multiline
comment */
span.turkey {
isdinner: true;
}
.turducken {
/* Sounds funny
doesn't it */
chimera: not_really;
}
#overhere {
bored: sorta; /* it's for a good
cause */
better_than: thread_pools;
}
#one_more {
finally: srsly;
} /* just a line here */
CSS
sass = <<SASS
elephant.rawr
:rampages excessively
span.turkey
:isdinner true
.turducken
:chimera not_really
#overhere
:bored sorta
:better_than thread_pools
#one_more
:finally srsly
SASS
assert_equal(css2sass(css), sass)
end
def test_fold_commas
assert_equal(<<SASS, css2sass(<<CSS))
li
.one, .two
:color red
SASS
li .one {
color: red;
}
li .two {
color: red;
}
CSS
assert_equal(<<SASS, css2sass(<<CSS))
.one
:color green
.two
:color green
:color red
.three
:color red
SASS
.one, .two {
color: green;
}
.two, .three {
color: red;
}
CSS
end
def test_bad_formatting
assert_equal(<<SASS, css2sass(<<CSS))
hello
:parent true
there
:parent false
who
:hoo false
why
:y true
when
:wen nao
down_here
:yeah true
SASS
hello {
parent: true;
}
hello there {
parent: false;
}
hello who {
hoo: false;
}
hello why {
y: true;
}
hello when {
wen: nao;
}
down_here { yeah: true; }
CSS
end
private
def css2sass(string, opts={})
Sass::CSS.new(string, opts).render
end
end