diff --git a/lib/sass/engine.rb b/lib/sass/engine.rb index aeca7b0e..8e979026 100644 --- a/lib/sass/engine.rb +++ b/lib/sass/engine.rb @@ -37,7 +37,9 @@ module Sass #++ # def initialize(template, options={}) - @options = options + @options = { + :style => :compact + }.merge! options @template = template.split("\n") @lines = [] @constants = {} @@ -48,7 +50,7 @@ module Sass begin split_lines - root = Tree::Node.new + root = Tree::Node.new(@options[:style]) index = 0 while @lines[index] child, index = build_tree(index) @@ -144,7 +146,7 @@ module Sass when Constant::CONSTANT_CHAR parse_constant(line) else - Tree::RuleNode.new(line) + Tree::RuleNode.new(line, @options[:style]) end end @@ -163,7 +165,7 @@ module Sass value = Sass::Constant.parse(value, @constants, @line).to_s end - Tree::AttrNode.new(name, value) + Tree::AttrNode.new(name, value, @options[:style]) end def parse_constant(line) diff --git a/lib/sass/tree/attr_node.rb b/lib/sass/tree/attr_node.rb index 1b9ab3e8..d7120c91 100644 --- a/lib/sass/tree/attr_node.rb +++ b/lib/sass/tree/attr_node.rb @@ -4,9 +4,9 @@ module Sass::Tree class AttrNode < ValueNode attr_accessor :name - def initialize(name, value) + def initialize(name, value, style) @name = name - super(value) + super(value, style) end def to_s(parent_name = nil) @@ -17,7 +17,13 @@ module Sass::Tree real_name = "#{parent_name}-#{real_name}" if parent_name if children.size > 0 to_return = String.new - children.each { |kid| to_return += "#{kid.to_s(real_name)} " } + children.each do |kid| + if @style == :expanded + to_return << "#{kid.to_s(real_name)}\n " + else + to_return << "#{kid.to_s(real_name)} " + end + end to_return[0...-1] else if value.length < 1 diff --git a/lib/sass/tree/node.rb b/lib/sass/tree/node.rb index 7b15fa55..e555f32f 100644 --- a/lib/sass/tree/node.rb +++ b/lib/sass/tree/node.rb @@ -4,7 +4,8 @@ module Sass attr_accessor :children attr_accessor :line - def initialize + def initialize(style) + @style = style @children = [] end diff --git a/lib/sass/tree/rule_node.rb b/lib/sass/tree/rule_node.rb index ea45585f..3498d31c 100644 --- a/lib/sass/tree/rule_node.rb +++ b/lib/sass/tree/rule_node.rb @@ -27,7 +27,11 @@ module Sass::Tree to_return = '' unless attributes.empty? - to_return << "#{total_rule} { #{attributes.join(' ')} }\n" + if @style == :expanded + to_return << "#{total_rule} {\n #{attributes.join("\n ").rstrip}\n}\n" + else + to_return << "#{total_rule} { #{attributes.join(' ')} }\n" + end end sub_rules.each { |sub| to_return << sub.to_s(total_rule) } diff --git a/lib/sass/tree/value_node.rb b/lib/sass/tree/value_node.rb index e87421b3..30adf202 100644 --- a/lib/sass/tree/value_node.rb +++ b/lib/sass/tree/value_node.rb @@ -4,9 +4,9 @@ module Sass::Tree class ValueNode < Node attr_accessor :value - def initialize(value) + def initialize(value, style) @value = value - super() + super(style) end end end diff --git a/test/sass/plugin_test.rb b/test/sass/plugin_test.rb index eb3b5ce3..4ca218f1 100644 --- a/test/sass/plugin_test.rb +++ b/test/sass/plugin_test.rb @@ -15,7 +15,7 @@ class SassPluginTest < Test::Unit::TestCase :template_location => File.dirname(__FILE__) + '/templates', :css_location => File.dirname(__FILE__) + '/tmp', } - Sass::Plugin.options[:always_update] = true + Sass::Plugin.options[:always_update] = true Sass::Plugin.update_stylesheets end @@ -24,6 +24,13 @@ class SassPluginTest < Test::Unit::TestCase File.delete(*Dir[tempfile_loc('*')]) end + def test_expanded_style + engine = Sass::Engine.new(File.read(File.dirname(__FILE__) + '/templates/expanded.sass'), + { :style => :expanded }) + File.open(tempfile_loc('expanded'), 'w') { |f| f.write(engine.render) } + assert_renders_correctly('expanded') + end + def test_templates_should_render_correctly @@templates.each { |name| assert_renders_correctly(name) } end