ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

SCSS Expander

by garetht ST2/ST3

Expands the SCSS rule in the current cursor scope.

Details

Installs

  • Total 18K
  • Win 11K
  • OS X 5K
  • Linux 2K
Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5 Sep 4 Sep 3 Sep 2
Windows 4 5 1 2 8 6 9 6 3 4 5 6 7 7 5 9 2 7 9 12 10 8 11 7 8 6 10 8 10 8 2 6 8 10 7 4 0 4 1 5 7 7 11 8 2 4
OS X 1 3 2 1 3 4 2 4 6 4 0 4 2 8 3 6 3 2 2 3 6 3 3 3 2 0 4 4 3 1 1 3 5 5 8 4 1 0 3 2 5 1 3 0 1 1
Linux 0 0 1 0 0 4 0 0 0 1 0 0 1 1 2 1 0 2 1 3 0 0 1 0 4 1 0 1 0 2 2 1 1 1 1 2 0 2 0 1 0 2 1 2 1 2

Readme

Source
raw.​githubusercontent.​com

SCSS Expander

Build Status

Suppose you're working on a particularly long project written using the SCSS syntax, and you're starting to forget the nesting structure of the current rule is.

//... {
        .foo {
          &.bar {
            // what CSS rule is being generated here?
          }
        }
//... }

It's possible to look at the generated CSS, of course, if the generated stylesheets are not too complex. But even that requires keeping another file open somewhere and hunting for line numbers. Most of the time you just want an answer straight away; here, you might get this answer:

.bim
.baz
.foo.bar

(because Sublime Text's alert window has remarkably little space.)

Installation and Usage

sublime-scss-expander does that for you. To install, either place this repository in the Sublime packages folder or use the far simpler Sublime Package Control. Press ctrl+shift+p on Windows/Linux and cmd+shift+p on a Mac to bring up Sublime's Command Palette, then type install package to bring up Package Control's package selector. It should be the first selection. Type SCSS Expander which, again, should be the first selection, and then hit enter.

To use, position the cursor in the scope of the rule you want to know about, and press command-E by default to show the rule that is in scope at that position. It is also available in the command palette as SCSS Expander: Expand Cursor Scope.

Support

It supports most sane uses of SCSS, including SASS 3.3's @at-root with all possible arguments, various permutations of the parent selector as well as combinatorically combined comma-separated rules.

Because it is not a parser, it works only when you give it correct code. It does not expand content-blocks that masquerade as rules. It does not even attempt to peek inside any imports.

Examples

Here are a few examples of how it works. In each case assume the cursor is placed in the innermost scope. All examples are drawn from the tests; look in the test file for more.

Comma-separated rules

.first-rule, .second-rule {
  &:hover {
    font-weight: 500;
  }
}
.first-rule:hover,
.second-rule:hover

Interpolated variables

.bim {
  @for $thing in (foo bar) {
    .test-#{$thing}-bling {
      width: 20px;
    }
  }
}
.bim .test-#{$thing}-bling

At-root without

@media screen {
  @supports something {
    .foo {
      @at-root(without: rule media) .bar {
        top: 0;
      }
    }
  }
}
@supports something .bar

Tests

There's a mound of tests which hopefully give good coverage. These are located in scss_expand_test.py. This does not test Sublime Text directly; instead, the expander can and has been generalized to work with any piece of text given a starting position within that text and a function that, given an index, returns the character at that position within the text. This means that the main Python class, SCSSExpander, can be exported for use with other projects.