1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Sass] Allow mixin argument defaults to use : rather than =.

This commit is contained in:
Nathan Weizenbaum 2010-03-26 18:00:27 -07:00
parent 8070008bf8
commit d220b18cc6
4 changed files with 26 additions and 4 deletions

View file

@ -45,6 +45,7 @@ module Sass
'/' => :div,
'%' => :mod,
'=' => :single_eq,
':' => :colon,
'(' => :lparen,
')' => :rparen,
',' => :comma,

View file

@ -226,8 +226,9 @@ RUBY
def defn_arglist(must_have_default)
return unless c = try_tok(:const)
var = Script::Variable.new(c.value)
if try_tok(:single_eq)
if tok = (try_tok(:colon) || try_tok(:single_eq))
val = assert_expr(:concat)
val.context = :equals if tok.type == :single_eq
elsif must_have_default
raise SyntaxError.new("Required argument #{var.inspect} must come before any optional arguments.")
end

View file

@ -23,7 +23,7 @@ module Sass
else
'(' + @args.map do |v, d|
if d
"#{v.to_sass} = #{d.to_sass}"
"#{v.to_sass}: #{d.to_sass}"
else
v.to_sass
end

View file

@ -708,14 +708,34 @@ SCSS
def test_mixin_definition_with_defaults
assert_renders <<SASS, <<SCSS
=foo-bar($baz, $bang = 12px)
=foo-bar($baz, $bang: 12px)
baz
a: $baz $bang
SASS
@mixin foo-bar($baz, $bang = 12px) {
@mixin foo-bar($baz, $bang: 12px) {
baz {
a: $baz $bang; } }
SCSS
assert_scss_to_sass <<SASS, <<SCSS
=foo-bar($baz, $bang: foo)
baz
a: $baz $bang
SASS
@mixin foo-bar($baz, $bang = "foo") {
baz {
a: $baz $bang; } }
SCSS
assert_sass_to_scss <<SCSS, <<SASS
@mixin foo-bar($baz, $bang: foo) {
baz {
a: $baz $bang; } }
SCSS
=foo-bar($baz, $bang = "foo")
baz
a: $baz $bang
SASS
end
def test_argless_mixin_include