Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added placeholders for "Mixins as Functions", "Recursive Mixins / Loops" #34

Merged
merged 1 commit into from
Oct 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions content/features/mixins-as-functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Using Mixins as Functions

All variables defined in a mixin are visible and can be used in caller's scope (unless the caller defines its own variable with the same name).

Example:
```less
.mixin() {
@width: 100%;
@height: 200px;
}

.caller {
.mixin();
width: @width;
height: @height;
}

```
Output:
```css
.caller {
width: 100%;
height: 200px;
}
```

Thus variables defined in a mixin can act as its return values. This allows us to create a mixin that can be used almost like a function.

Example:
```less
.average(@x, @y) {
@average: ((@x + @y) / 2);
}

div {
.average(16px, 50px); // "call" the mixin
padding: @average; // use its "return" value
}

```
Output:
```css
div {
padding: 33px;
}
```
57 changes: 57 additions & 0 deletions content/features/mixins-recursive-loops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Recursive Mixin ~~Calls~~ and Loops

...

~~It's not so easy to invent a very simple and in the same time less or more practical loop example. The simplest loops are totally useless and practical code is usually too advanced as it also uses many other (or at least one more) LESS features.~~

Example:
```less
.loop(@index) when (@index > 0) {
.loop((@index - 1)); // next iteration
width: (10px * @index); // code for each iteration
}

div {
.loop(5); // launch the loop
}
```
Output:
```css
div {
width: 10px;
width: 20px;
width: 30px;
width: 40px;
width: 50px;
}
```

Example:
```less
@nColumns: 4;

.loop(1);
.loop(@i) when (@i <= @nColumns) {

.column-@{i} {
width: (@i * 100% / @nColumns)
}

.loop((@i + 1));
}
```
Output:
```css
.column-1 {
width: 25%;
}
.column-2 {
width: 50%;
}
.column-3 {
width: 75%;
}
.column-4 {
width: 100%;
}
```