From 8c7901fc821b54d15da3d1b13c57413e7104f3fb Mon Sep 17 00:00:00 2001 From: Hugo Giraudel Date: Sun, 19 Jul 2015 14:03:36 +0200 Subject: [PATCH] Added something about argument-less mixins --- _includes/snippets/mixins/08/index.html | 27 +++++++++++++++++++++++++ en/_mixins.md | 8 ++++++++ 2 files changed, 35 insertions(+) create mode 100644 _includes/snippets/mixins/08/index.html diff --git a/_includes/snippets/mixins/08/index.html b/_includes/snippets/mixins/08/index.html new file mode 100644 index 00000000..a55f572e --- /dev/null +++ b/_includes/snippets/mixins/08/index.html @@ -0,0 +1,27 @@ + +
+
+{% highlight scss %} +// Yep +.foo { + @include center; +} + +// Nope +.foo { + @include center(); +} +{% endhighlight %} +
+
+{% highlight sass %} +// Yep +.foo + +center + +// Nope +.foo + +center() +{% endhighlight %} +
+
diff --git a/en/_mixins.md b/en/_mixins.md index e47680c0..6be27020 100644 --- a/en/_mixins.md +++ b/en/_mixins.md @@ -23,6 +23,14 @@ Another valid example would be a mixin to size an element, defining both `width` * [A Sass Mixin for CSS Triangles](http://www.sitepoint.com/sass-mixin-css-triangles/) * [Building a Linear-Gradient Mixin](http://www.sitepoint.com/building-linear-gradient-mixin-sass/) +## Argument-less mixins + +Sometimes mixins are used only to avoid repeating the same group of declarations over and over again, yet do not need any parameter or have sensible enough defaults so that we don’t necessarily have to pass arguments. + +In such cases, we can safely omit the parentheses when calling them. The `@include` keyword (or `+` sign in indented-syntax) already acts as a indicator that the line is a mixin call; there is no need for extra parentheses here. + +{% include snippets/mixins/08/index.html %} + ## Arguments list When dealing with an unknown number of arguments in a mixin, always use an `arglist` rather than a list. Think of `arglist` as the 8th hidden undocumented data type from Sass that is implicitly used when passing an arbitrary number of arguments to a mixin or a function whose signature contains `...`.