[Sass] css2sass should output new attribute syntax by default.
This commit is contained in:
parent
a01b226217
commit
3940abde58
|
@ -435,10 +435,12 @@ Description: Transforms a CSS file into corresponding Sass code.
|
||||||
Options:
|
Options:
|
||||||
END
|
END
|
||||||
|
|
||||||
opts.on('-a', '--alternate', 'Output using alternative Sass syntax (margin: 1px)') do
|
opts.on('--old', 'Output the old-style ":prop val" property syntax') do
|
||||||
@module_opts[:alternate] = true
|
@module_opts[:old] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on_tail('-a', '--alternate', 'Ignored') {}
|
||||||
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ module Sass
|
||||||
class AttrNode
|
class AttrNode
|
||||||
# @see Node#to_sass
|
# @see Node#to_sass
|
||||||
def to_sass(tabs, opts = {})
|
def to_sass(tabs, opts = {})
|
||||||
"#{' ' * tabs}#{opts[:alternate] ? '' : ':'}#{name}#{opts[:alternate] ? ':' : ''} #{value}\n"
|
"#{' ' * tabs}#{opts[:old] ? ':' : ''}#{name}#{opts[:old] ? '' : ':'} #{value}\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,15 +59,17 @@ module Sass
|
||||||
# Sass::CSS.new("p { color: blue }").render #=> "p\n :color blue"
|
# Sass::CSS.new("p { color: blue }").render #=> "p\n :color blue"
|
||||||
class CSS
|
class CSS
|
||||||
# @param template [String] The CSS code
|
# @param template [String] The CSS code
|
||||||
# @option options :alternate [Boolean] (false)
|
# @option options :old [Boolean] (false)
|
||||||
# Whether or not to output alternate attribute syntax
|
# Whether or not to output old attribute syntax
|
||||||
# (`color: blue` as opposed to `:color blue`).
|
# (`:color blue` as opposed to `color: blue`).
|
||||||
def initialize(template, options = {})
|
def initialize(template, options = {})
|
||||||
if template.is_a? IO
|
if template.is_a? IO
|
||||||
template = template.read
|
template = template.read
|
||||||
end
|
end
|
||||||
|
|
||||||
@options = options
|
@options = options.dup
|
||||||
|
# Backwards compatibility
|
||||||
|
@options[:old] = true if @options[:alternate] == false
|
||||||
@template = StringScanner.new(template)
|
@template = StringScanner.new(template)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,28 +10,28 @@ h1 {
|
||||||
}
|
}
|
||||||
CSS
|
CSS
|
||||||
assert_equal(<<SASS, css2sass(css))
|
assert_equal(<<SASS, css2sass(css))
|
||||||
h1
|
|
||||||
:color red
|
|
||||||
SASS
|
|
||||||
assert_equal(<<SASS, css2sass(css, :alternate => true))
|
|
||||||
h1
|
h1
|
||||||
color: red
|
color: red
|
||||||
|
SASS
|
||||||
|
assert_equal(<<SASS, css2sass(css, :old => true))
|
||||||
|
h1
|
||||||
|
:color red
|
||||||
SASS
|
SASS
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nesting
|
def test_nesting
|
||||||
assert_equal(<<SASS, css2sass(<<CSS))
|
assert_equal(<<SASS, css2sass(<<CSS))
|
||||||
li
|
li
|
||||||
:display none
|
display: none
|
||||||
|
|
||||||
a
|
a
|
||||||
:text-decoration none
|
text-decoration: none
|
||||||
|
|
||||||
span
|
span
|
||||||
:color yellow
|
color: yellow
|
||||||
|
|
||||||
&:hover
|
&:hover
|
||||||
:text-decoration underline
|
text-decoration: underline
|
||||||
SASS
|
SASS
|
||||||
li {
|
li {
|
||||||
display: none;
|
display: none;
|
||||||
|
@ -54,15 +54,15 @@ CSS
|
||||||
def test_no_nesting_around_rules
|
def test_no_nesting_around_rules
|
||||||
assert_equal(<<SASS, css2sass(<<CSS))
|
assert_equal(<<SASS, css2sass(<<CSS))
|
||||||
div .warning
|
div .warning
|
||||||
:color #d21a19
|
color: #d21a19
|
||||||
|
|
||||||
|
|
||||||
span .debug
|
span .debug
|
||||||
:cursor crosshair
|
cursor: crosshair
|
||||||
|
|
||||||
|
|
||||||
div .debug
|
div .debug
|
||||||
:cursor default
|
cursor: default
|
||||||
SASS
|
SASS
|
||||||
div .warning {
|
div .warning {
|
||||||
color: #d21a19; }
|
color: #d21a19; }
|
||||||
|
@ -104,24 +104,24 @@ span.turkey {
|
||||||
CSS
|
CSS
|
||||||
sass = <<SASS
|
sass = <<SASS
|
||||||
elephant.rawr
|
elephant.rawr
|
||||||
:rampages excessively
|
rampages: excessively
|
||||||
|
|
||||||
|
|
||||||
span.turkey
|
span.turkey
|
||||||
:isdinner true
|
isdinner: true
|
||||||
|
|
||||||
|
|
||||||
.turducken
|
.turducken
|
||||||
:chimera not_really
|
chimera: not_really
|
||||||
|
|
||||||
|
|
||||||
#overhere
|
#overhere
|
||||||
:bored sorta
|
bored: sorta
|
||||||
:better_than thread_pools
|
better_than: thread_pools
|
||||||
|
|
||||||
|
|
||||||
#one_more
|
#one_more
|
||||||
:finally srsly
|
finally: srsly
|
||||||
SASS
|
SASS
|
||||||
assert_equal(css2sass(css), sass)
|
assert_equal(css2sass(css), sass)
|
||||||
end
|
end
|
||||||
|
@ -130,7 +130,7 @@ SASS
|
||||||
assert_equal(<<SASS, css2sass(<<CSS))
|
assert_equal(<<SASS, css2sass(<<CSS))
|
||||||
li
|
li
|
||||||
.one, .two
|
.one, .two
|
||||||
:color red
|
color: red
|
||||||
SASS
|
SASS
|
||||||
li .one {
|
li .one {
|
||||||
color: red;
|
color: red;
|
||||||
|
@ -142,16 +142,16 @@ CSS
|
||||||
|
|
||||||
assert_equal(<<SASS, css2sass(<<CSS))
|
assert_equal(<<SASS, css2sass(<<CSS))
|
||||||
.one
|
.one
|
||||||
:color green
|
color: green
|
||||||
|
|
||||||
|
|
||||||
.two
|
.two
|
||||||
:color green
|
color: green
|
||||||
:color red
|
color: red
|
||||||
|
|
||||||
|
|
||||||
.three
|
.three
|
||||||
:color red
|
color: red
|
||||||
SASS
|
SASS
|
||||||
.one, .two {
|
.one, .two {
|
||||||
color: green;
|
color: green;
|
||||||
|
@ -166,23 +166,23 @@ CSS
|
||||||
def test_bad_formatting
|
def test_bad_formatting
|
||||||
assert_equal(<<SASS, css2sass(<<CSS))
|
assert_equal(<<SASS, css2sass(<<CSS))
|
||||||
hello
|
hello
|
||||||
:parent true
|
parent: true
|
||||||
|
|
||||||
there
|
there
|
||||||
:parent false
|
parent: false
|
||||||
|
|
||||||
who
|
who
|
||||||
:hoo false
|
hoo: false
|
||||||
|
|
||||||
why
|
why
|
||||||
:y true
|
y: true
|
||||||
|
|
||||||
when
|
when
|
||||||
:wen nao
|
wen: nao
|
||||||
|
|
||||||
|
|
||||||
down_here
|
down_here
|
||||||
:yeah true
|
yeah: true
|
||||||
SASS
|
SASS
|
||||||
hello {
|
hello {
|
||||||
parent: true;
|
parent: true;
|
||||||
|
|
Loading…
Reference in New Issue