Skip to content

Instantly share code, notes, and snippets.

@tybruffy
Last active December 17, 2015 11:19

Revisions

  1. tybruffy renamed this gist Mar 25, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. tybruffy revised this gist May 17, 2013. 1 changed file with 46 additions and 0 deletions.
    46 changes: 46 additions & 0 deletions Readme.markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    Less.js Loop for manipulating adjacent siblings. Defaults to add the style to all X number of siblings as specified in the call.

    ```less
    .testcase {
    .adjacents-content() {
    display: inline;
    }
    .adjacents(4, ".item" );
    }
    ```

    Will output to

    ```css
    .testcase + .item {
    display: inline;
    }
    .testcase + .item + .item {
    display: inline;
    }
    .testcase + .item + .item + .item {
    display: inline;
    }
    .testcase + .item + .item + .item + .item {
    display: inline;
    }
    ```

    Alternately you can target just a specific sibling:

    ```less
    .testcase {
    .adjacents-content() {
    display: inline;
    }
    .adjacents(4, ".item", false );
    }
    ```

    Outputs

    ```css
    .testcase + .item + .item + .item + .item {
    display: inline;
    }
    ```
  3. tybruffy created this gist May 17, 2013.
    32 changes: 32 additions & 0 deletions adjacents.less
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    .adjacents( @count, @item: "", @all: true, @name: "" ) when (@all) {
    @selector: ~"@{name} + @{item}";

    .loop (@index) when (@index > 0) {
    (@selector) {
    .adjacents-content();
    }
    .adjacents(@index - 1, @item, true, @selector );
    }
    .loop (0) {}

    .loop(@count);
    }

    .adjacents( @count, @item: "", @all: true, @name: "" ) when not (@all) {
    @selector: ~"@{name} + @{item}";

    .loop(@index) when(@index > 1) {
    .adjacents(@index - 1, @item, false, @selector );
    }

    .loop (@index) when (@index = 1) {
    (@selector) {
    .adjacents-content();
    }
    .adjacents(@index - 1, @item, false, @selector );
    }
    .loop (0) {}

    .loop(@count);
    }
    .adjacents(0);