From 3940abde584713842eb5c5dc156eea6b891c73d3 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Fri, 19 Jun 2009 02:57:01 -0700 Subject: [PATCH] [Sass] css2sass should output new attribute syntax by default. --- lib/haml/exec.rb | 6 ++-- lib/sass/css.rb | 12 ++++---- test/sass/css2sass_test.rb | 56 +++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/lib/haml/exec.rb b/lib/haml/exec.rb index 4568f31a..a2616df6 100644 --- a/lib/haml/exec.rb +++ b/lib/haml/exec.rb @@ -435,10 +435,12 @@ Description: Transforms a CSS file into corresponding Sass code. Options: END - opts.on('-a', '--alternate', 'Output using alternative Sass syntax (margin: 1px)') do - @module_opts[:alternate] = true + opts.on('--old', 'Output the old-style ":prop val" property syntax') do + @module_opts[:old] = true end + opts.on_tail('-a', '--alternate', 'Ignored') {} + super end diff --git a/lib/sass/css.rb b/lib/sass/css.rb index e4882622..f70ef6ae 100644 --- a/lib/sass/css.rb +++ b/lib/sass/css.rb @@ -37,7 +37,7 @@ module Sass class AttrNode # @see Node#to_sass def to_sass(tabs, opts = {}) - "#{' ' * tabs}#{opts[:alternate] ? '' : ':'}#{name}#{opts[:alternate] ? ':' : ''} #{value}\n" + "#{' ' * tabs}#{opts[:old] ? ':' : ''}#{name}#{opts[:old] ? '' : ':'} #{value}\n" end end @@ -59,15 +59,17 @@ module Sass # Sass::CSS.new("p { color: blue }").render #=> "p\n :color blue" class CSS # @param template [String] The CSS code - # @option options :alternate [Boolean] (false) - # Whether or not to output alternate attribute syntax - # (`color: blue` as opposed to `:color blue`). + # @option options :old [Boolean] (false) + # Whether or not to output old attribute syntax + # (`:color blue` as opposed to `color: blue`). def initialize(template, options = {}) if template.is_a? IO template = template.read end - @options = options + @options = options.dup + # Backwards compatibility + @options[:old] = true if @options[:alternate] == false @template = StringScanner.new(template) end diff --git a/test/sass/css2sass_test.rb b/test/sass/css2sass_test.rb index f0434d36..4669412f 100644 --- a/test/sass/css2sass_test.rb +++ b/test/sass/css2sass_test.rb @@ -10,28 +10,28 @@ h1 { } CSS assert_equal(< true)) h1 color: red +SASS + assert_equal(< true)) +h1 + :color red SASS end def test_nesting assert_equal(<