[Sass] css2sass should output new attribute syntax by default.

This commit is contained in:
Nathan Weizenbaum 2009-06-19 02:57:01 -07:00
parent a01b226217
commit 3940abde58
3 changed files with 39 additions and 35 deletions

View File

@ -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

View File

@ -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

View File

@ -10,28 +10,28 @@ h1 {
}
CSS
assert_equal(<<SASS, css2sass(css))
h1
:color red
SASS
assert_equal(<<SASS, css2sass(css, :alternate => true))
h1
color: red
SASS
assert_equal(<<SASS, css2sass(css, :old => true))
h1
:color red
SASS
end
def test_nesting
assert_equal(<<SASS, css2sass(<<CSS))
li
:display none
display: none
a
:text-decoration none
text-decoration: none
span
:color yellow
color: yellow
&:hover
:text-decoration underline
text-decoration: underline
SASS
li {
display: none;
@ -54,15 +54,15 @@ CSS
def test_no_nesting_around_rules
assert_equal(<<SASS, css2sass(<<CSS))
div .warning
:color #d21a19
color: #d21a19
span .debug
:cursor crosshair
cursor: crosshair
div .debug
:cursor default
cursor: default
SASS
div .warning {
color: #d21a19; }
@ -104,24 +104,24 @@ span.turkey {
CSS
sass = <<SASS
elephant.rawr
:rampages excessively
rampages: excessively
span.turkey
:isdinner true
isdinner: true
.turducken
:chimera not_really
chimera: not_really
#overhere
:bored sorta
:better_than thread_pools
bored: sorta
better_than: thread_pools
#one_more
:finally srsly
finally: srsly
SASS
assert_equal(css2sass(css), sass)
end
@ -130,7 +130,7 @@ SASS
assert_equal(<<SASS, css2sass(<<CSS))
li
.one, .two
:color red
color: red
SASS
li .one {
color: red;
@ -142,16 +142,16 @@ CSS
assert_equal(<<SASS, css2sass(<<CSS))
.one
:color green
color: green
.two
:color green
:color red
color: green
color: red
.three
:color red
color: red
SASS
.one, .two {
color: green;
@ -166,23 +166,23 @@ CSS
def test_bad_formatting
assert_equal(<<SASS, css2sass(<<CSS))
hello
:parent true
parent: true
there
:parent false
parent: false
who
:hoo false
hoo: false
why
:y true
y: true
when
:wen nao
wen: nao
down_here
:yeah true
yeah: true
SASS
hello {
parent: true;