Giter VIP home page Giter VIP logo

sublime-perfectionist's Introduction

A powerful Sublime Text plugin to beautify your CSS!

Powered by perfectionist

screenshot

Input:

/*sublime-perfectionist test*/
@media screen {
.foo { & > .bar {
  -webkit-transform: scale(0);//commment
  -ms-transform: scale(0);-o-transform: scale(0);
  transform: scale(0);}}
}
@for $i from 1 through 3 {
.item-#{$i}{display: inline-block;}
}

Output:

/*sublime-perfectionist test*/

@media screen {
  .foo {
    & > .bar {
      -webkit-transform: scale(0); //commment
          -ms-transform: scale(0);
           -o-transform: scale(0);
              transform: scale(0);
    }
  }
}

@for $i from 1 through 3 {
  .item-#{$i} {
    display: inline-block;
  }
}

Installation

First of all, you need to have Node.js installed.

Make sure it's in your $PATH by running node -v in your command-line.

Note: On OS X it's expected that Node should reside in the /usr/local/bin/ folder, which it does when installed with the default installer. If this is not the case, symlink your Node binary to this location. For example, if you used nvm:
ln -s -f /Users/#{username}/.nvm/versions/#{nodeVersion}/bin/node /usr/local/bin/node
See also: http://weibo.com/1397442732/BA52YbcdG

Method 1: Package Control(Recommend)

You need to have Package Control installed.

  • Open: View > Show Console menu.
  • Paste the appropriate Python code for your version of Sublime Text into the console.

Sublime Text 3:

import urllib.request,os,hashlib; h = 'eb2297e1a458f27d836c04bb0cbaf282' + 'd0e7a3098092775ccb37ca9d6b2e4b7d'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

Sublime Text 2:

import urllib2,os,hashlib; h = 'eb2297e1a458f27d836c04bb0cbaf282' + 'd0e7a3098092775ccb37ca9d6b2e4b7d'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler()) ); by = urllib2.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); open( os.path.join( ipp, pf), 'wb' ).write(by) if dh == h else None; print('Error validating download (got %s instead of %s), please try manual install' % (dh, h) if dh != h else 'Please restart Sublime Text to finish installation')

Then

  1. Open the Command Palette: Cmd + Shift + P(OS X) or Ctrl + Shift + P(Window/Linux).
  2. Input: Package Control: Install Package or just pcip.
  3. Input: perfectionist.
  4. Windows users will need to restart Sublime Text to finish the installation.

Method 2: Install from GitHub

  1. Run the following command in your Sublime Text packages directory
$ git clone https://github.com/yisibl/sublime-perfectionist perfectionist
  1. Depending on your OS (and Sublime Text version), the packages directories are
  • Windows: cd %APPDATA%\Sublime Text 3\Packages
  • OS X: cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages
  • Linux: cd ~/.config/sublime-text-3/packages

Method 3: Download

  1. Download the source zip from Github.
  2. Open Sublime Text menu Preferences > Browse Packages.
  3. Extract it into a new folder named 'perfectionist' in your Sublime Text "Packages" folder.
  4. Restart Sublime Text.

Usage

  • Open the Command Palette: Cmd + Shift + P(OS X) or Ctrl + Shift + P(Window/Linux), input CSS Perfectionist.
  • Context Menu: CSS perfectionist.
  • Shortcut keys: Cmd + Shift + E(OS X)/Ctrl + Shift + E(Window/Linux).

Options

format_on_save

  • Type: boolean
  • Default: true

Automatically format when a file is saved.

file_filter

  • Type: string
  • Default: css,scss,less,html,htm

If format_on_save is true, automatic formatting in these files.

More options, see also: https://github.com/ben-eb/perfectionist#options

Settings

  1. Open Preferences > Package Settings > Perfectionist > Settings - Default.
  2. Copy code.
  3. Open Preferences > Package Settings > Perfectionist > Settings - User.
  4. Paste and modify.

Acknowledgements

This plugin is based on the excellent Autoprefixer plugin by Sindre Sorhus.

Thank @Ovilia for reviewing the document.

License

MIT License

Created by yisibl (Weibo)

sublime-perfectionist's People

Contributors

yisibl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sublime-perfectionist's Issues

scss写了个循环格式化错误

@for $i from 1 through 3 {
  .road-btn#{$i} {
    @include roadBtn('/static/image/h5/kart/button' + $i + '.png');
   }
}

会编译成这样

@for $i from 1 through 3 {
  .road-btn# {
  }

   {
    @include roadBtn('/static/image/h5/kart/button' + $i + '.png');
  }
}

All my code dissappeared

I installed perfectionist a little while ago on ST3 on Mac using Package Control. I had a couple of issues.

  1. When I opened a minified CSS file, it expanded it automaticaly. I had to restore it.
  2. When I made a change to an html file and saved it, all the code dissappeared leaving a blank file. I had to undo then disable perfectionist to save it.

Over-zealous in compression

I have the plugin set to 'expanded' mode.

.class {
    // Not active, not open - use black down arrow
    @include pseudo-element();
    @include retina-sprite(nav-arrow-down-black);
    @include centre-sprite(nav-arrow-down-black);
  }

Becomes:

.class {
    //Notactive,notopen-useblackdownarrow@includepseudo-element()@include retina-sprite(nav-arrow-down-black);
    @include centre-sprite(nav-arrow-down-black);
  }

Which is quite drastic and breaks the code.

Possible to support nested comments

I'm using this in Sublime (in case that is relevant). Given a rule like this (removed some properties for brevity):

.bb-Choices_Label {
    display: inline-flex;
    align-items: center;
    /*This is the underline*/
    &:before {
        content: "";
        position: absolute;
    }
    /*This is the nib*/
    &:after {
        [aria-selected="true"] & {
            position: absolute;
            top: 100%;
        }
    }
}

Perfectionist is generating this:

.bb-Choices_Label {
    display: inline-flex;
    align-items: center;
    /*This is the underline*/

    &:before {
        content: "";
        position: absolute;
    }/*This is the nib*/

    &:after {
        [aria-selected="true"] & {
            position: absolute;
            top: 100%;
        }
    }
}

Would it be possible to retain the position of nested comments with regards to nested selectors. I realise I'm using a non-standard syntax!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.