fix multiline selectors and tidy up group selector output

* all multiline selectors are now outputed in one line
* grouped selectors now honor :style => 'compressed'
This commit is contained in:
Cristi Balan 2008-03-27 17:18:38 +01:00
parent b109c0a6d8
commit ae79bdb8dd
4 changed files with 23 additions and 17 deletions

View File

@ -138,6 +138,15 @@ module Sass
if tabs - old_tabs > 1
raise SyntaxError.new("Illegal Indentation: Only two space characters are allowed as tabulation.", @line)
end
line.strip!
next_line = @template[index+1]
if next_line
next_tabs = count_tabs(next_line)
if line[-1] == ?, && tabs == next_tabs
@template[index+1] = "#{' '*tabs}#{line} #{next_line.strip}"
next
end
end
@lines << [line.strip, tabs]
old_tabs = tabs

View File

@ -20,20 +20,22 @@ module Sass::Tree
# Save this because the comma's removed by the super_rule additions
was_continued = continued?
rule_split = /\s*,\s*/
rule_separator = @style == :compressed ? ',' : ', '
total_rule = if super_rules
super_rules.split(/,\s*/).collect! do |s|
self.rule.split(/,\s*/).collect do |r|
super_rules.split(rule_split).collect! do |s|
self.rule.split(rule_split).collect do |r|
if r.include?(PARENT)
r.gsub(PARENT, s)
else
"#{s} #{r}"
end
end.join(", ")
end.join(", ") + (was_continued ? ',' : '')
end.join(rule_separator)
end.join(rule_separator) + (was_continued ? rule_separator: "")
elsif self.rule.include?(PARENT)
raise Sass::SyntaxError.new("Base-level rules cannot contain the parent-selector-referencing character '#{PARENT}'", line)
else
self.rule
self.rule.gsub(rule_split, rule_separator)
end
children.each do |child|

View File

@ -109,9 +109,9 @@ class SassEngineTest < Test::Unit::TestCase
end
def test_basic_multiline_selector
assert_equal("#foo #bar,\n#baz #boom {\n foo: bar; }\n",
assert_equal("#foo #bar, #baz #boom {\n foo: bar; }\n",
render("#foo #bar,\n#baz #boom\n :foo bar"))
assert_equal("#foo #bar,\n#foo #baz {\n foo: bar; }\n",
assert_equal("#foo #bar, #foo #baz {\n foo: bar; }\n",
render("#foo\n #bar,\n #baz\n :foo bar"))
assert_equal("#foo #bar, #baz #boom { foo: bar; }\n",
render("#foo #bar,\n#baz #boom\n :foo bar", :style => :compact))
@ -179,11 +179,11 @@ class SassEngineTest < Test::Unit::TestCase
assert_equal("@a{#b{a:b}#b #c{d:e}}\n",
render("@a\n #b\n :a b\n #c\n :d e", :style => :compressed))
assert_equal("@a {\n #foo,\n #bar {\n b: c; } }\n",
assert_equal("@a {\n #foo, #bar {\n b: c; } }\n",
render("@a\n #foo, \n #bar\n :b c"))
assert_equal("@a { #foo, #bar { b: c; } }\n",
render("@a\n #foo, \n #bar\n :b c", :style => :compact))
assert_equal("@a {\n #foo,\n #bar {\n b: c;\n }\n}\n",
assert_equal("@a {\n #foo, #bar {\n b: c;\n }\n}\n",
render("@a\n #foo, \n #bar\n :b c", :style => :expanded))
assert_equal("@a{#foo,#bar{b:c}}\n",
render("@a\n #foo, \n #bar\n :b c", :style => :compressed))

View File

@ -1,11 +1,6 @@
#main,
#header {
#main, #header {
height: 50px; }
#main div,
#header div {
#main div, #header div {
width: 100px; }
#main div a span,
#main div em span,
#header div a span,
#header div em span {
#main div a span, #main div em span, #header div a span, #header div em span {
color: pink; }