[Sass] Support @mixin and @include in the indented syntax.
This commit is contained in:
parent
13ea3ded9a
commit
ed13be04fc
|
@ -206,6 +206,28 @@ They behave identically to double-quoted strings,
|
|||
except that single quotes need to be backslash-escaped
|
||||
and double quotes do not.
|
||||
|
||||
#### Mixin Definition and Inclusion
|
||||
|
||||
Sass now supports the `@mixin` directive as a way of defining mixins (like `=`),
|
||||
as well as the `@include` directive as a way of including them (like `+`).
|
||||
The old syntax is *not* deprecated,
|
||||
and the two are fully compatible.
|
||||
For example:
|
||||
|
||||
@mixin pretty-text
|
||||
color: $prettiest-color
|
||||
|
||||
a
|
||||
@include pretty-text
|
||||
|
||||
is the same as:
|
||||
|
||||
=pretty-text
|
||||
color: $prettiest-color
|
||||
|
||||
a
|
||||
+pretty-text
|
||||
|
||||
### Colors
|
||||
|
||||
SassScript color values are much more powerful than they were before.
|
||||
|
|
|
@ -465,6 +465,10 @@ WARNING
|
|||
raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath import directives.",
|
||||
:line => @line + 1) unless line.children.empty?
|
||||
value.split(/,\s*/).map {|f| Tree::ImportNode.new(f)}
|
||||
elsif directive == "mixin"
|
||||
parse_mixin_definition(line)
|
||||
elsif directive == "include"
|
||||
parse_mixin_include(line, root)
|
||||
elsif directive == "for"
|
||||
parse_for(line, root, value)
|
||||
elsif directive == "else"
|
||||
|
@ -528,7 +532,7 @@ WARNING
|
|||
end
|
||||
|
||||
# @private
|
||||
MIXIN_DEF_RE = /^=\s*(#{Sass::SCSS::RX::IDENT})(.*)$/
|
||||
MIXIN_DEF_RE = /^(?:=|@mixin)\s*(#{Sass::SCSS::RX::IDENT})(.*)$/
|
||||
def parse_mixin_definition(line)
|
||||
name, arg_string = line.text.scan(MIXIN_DEF_RE).first
|
||||
raise SyntaxError.new("Invalid mixin \"#{line.text[1..-1]}\".") if name.nil?
|
||||
|
@ -541,7 +545,7 @@ WARNING
|
|||
end
|
||||
|
||||
# @private
|
||||
MIXIN_INCLUDE_RE = /^\+\s*(#{Sass::SCSS::RX::IDENT})(.*)$/
|
||||
MIXIN_INCLUDE_RE = /^(?:\+|@include)\s*(#{Sass::SCSS::RX::IDENT})(.*)$/
|
||||
def parse_mixin_include(line, root)
|
||||
name, arg_string = line.text.scan(MIXIN_INCLUDE_RE).first
|
||||
raise SyntaxError.new("Invalid mixin include \"#{line.text}\".") if name.nil?
|
||||
|
|
|
@ -834,6 +834,19 @@ SASS
|
|||
renders_correctly "mixins", { :style => :expanded }
|
||||
end
|
||||
|
||||
def test_directive_style_mixins
|
||||
assert_equal <<CSS, render(<<SASS)
|
||||
bar {
|
||||
prop: baz; }
|
||||
CSS
|
||||
@mixin foo($arg)
|
||||
prop: $arg
|
||||
|
||||
bar
|
||||
@include foo(baz)
|
||||
SASS
|
||||
end
|
||||
|
||||
def test_mixins_dont_interfere_with_sibling_combinator
|
||||
assert_equal("foo + bar {\n a: b; }\nfoo + baz {\n c: d; }\n",
|
||||
render("foo\n +\n bar\n a: b\n baz\n c: d"))
|
||||
|
|
Loading…
Reference in New Issue