Handle @media and friends properly in css2sass.

This commit is contained in:
Nathan Weizenbaum 2008-09-02 16:59:28 -07:00
parent 3ffaaf5b64
commit 21f261d3a7
1 changed files with 27 additions and 26 deletions

View File

@ -18,7 +18,7 @@ module Sass
end
class ValueNode
def to_sass(tabs)
def to_sass(tabs, opts = {})
"#{value}\n"
end
end
@ -40,6 +40,12 @@ module Sass
"#{' ' * tabs}#{opts[:alternate] ? '' : ':'}#{name}#{opts[:alternate] ? ':' : ''} #{value}\n"
end
end
class DirectiveNode
def to_sass(tabs, opts = {})
"#{' ' * tabs}#{value}#{children.map {|c| c.to_sass(tabs + 1, opts)}}\n"
end
end
end
# This class is based on the Ruby 1.9 ordered hashes.
@ -132,7 +138,6 @@ module Sass
def build_tree
root = Tree::Node.new(nil)
whitespace
directives root
rules root
expand_commas root
parent_ref_rules root
@ -142,37 +147,33 @@ module Sass
root
end
def directives(root)
while @template.scan(/@/)
name = @template.scan /[^\s;]+/
def rules(root)
while r = rule
root << r
whitespace
value = @template.scan /[^;]+/
assert_match /;/
whitespace
if name == "import" && value =~ /^(url\()?"?([^\s\(\)\"]+)\.css"?\)?$/
value = $2
end
root << Tree::ValueNode.new("@#{name} #{value};", nil)
end
end
def rules(root)
rules = []
while @template.scan(/[^\{\s]+/)
rules << @template[0]
def rule
return unless rule = @template.scan(/[^\{\};]+/)
rule.strip!
directive = rule[0] == ?@
if directive
node = Tree::DirectiveNode.new(rule, nil)
return node if @template.scan(/;/)
assert_match /\{/
whitespace
if @template.scan(/\{/)
result = Tree::RuleNode.new(rules.join(' '), nil)
root << result
rules = []
whitespace
attributes(result)
end
rules(node)
return node
end
assert_match /\{/
node = Tree::RuleNode.new(rule, nil)
attributes(node)
return node
end
def attributes(rule)