├── .gitignore ├── LICENSE.md ├── README.md ├── keymaps └── csscomb.cson ├── lib ├── csscomb-range-finder.coffee └── csscomb.coffee ├── menus └── csscomb.cson └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | node_modules 4 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Bruce Williams, Lynn Wallenstein 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Atom Editor Plugin for CSScomb 2 | 3 | Sort properties of one or more CSS/SCSS/Less rules using 4 | [CSScomb](http://csscomb.com/). 5 | 6 | ## Installation 7 | 8 | See the [Atom docs](http://atom.io/docs/latest/customizing-atom#installing-packages). 9 | 10 | ```shell 11 | $ apm install csscomb 12 | ``` 13 | 14 | ## CSScomb Configuration 15 | 16 | The plugin uses the following strategy to determine the CSScomb configuration to use. 17 | 18 | * First, it looks for a user configuration; a `csscomb` property in your Atom 19 | `config.cson`. 20 | * Next, it looks for a project configuration; `.csscomb.json` or `.csscomb.cson` 21 | in your project root. 22 | * If no configuration is found, it falls back to the predefined "csscomb" 23 | configuration that ships with [csscomb.js](https://github.com/csscomb/csscomb.js/blob/master/config/csscomb.json). 24 | 25 | Your configuration can be a CSScomb configuration object or the [name of a predefined configuration](https://github.com/csscomb/csscomb.js/tree/master/config). 26 | 27 | ## Using It 28 | 29 | Press `ctrl-alt-c` or choose `Packages -> CSScomb -> Sort` or 30 | `Edit -> Lines -> Sort with CSScomb`. 31 | 32 | You can limit what CSScomb processes by using selections. 33 | 34 | Note: Make sure to select entire CSS rules (selector, braces, and 35 | properties; valid CSS), not just the property list. 36 | 37 | The plugin uses the name of the file to determine the syntax 38 | (css, scss, or less). 39 | -------------------------------------------------------------------------------- /keymaps/csscomb.cson: -------------------------------------------------------------------------------- 1 | # Keybindings require three things to be fully defined: A selector that is 2 | # matched against the focused element, the keystroke and the command to 3 | # execute. 4 | # 5 | # Below is a basic keybinding which registers on all platforms by applying to 6 | # the root workspace element. 7 | 8 | # For more detailed documentation see 9 | # https://atom.io/docs/latest/advanced/keymaps 10 | 'atom-workspace': 11 | 'ctrl-alt-c': 'csscomb:run' 12 | -------------------------------------------------------------------------------- /lib/csscomb-range-finder.coffee: -------------------------------------------------------------------------------- 1 | {Range} = require 'atom' 2 | 3 | # Thanks to the sort-lines plugin for this approach 4 | module.exports = 5 | class CsscombRangeFinder 6 | # Public 7 | @rangesFor: (editor) -> 8 | new CsscombRangeFinder(editor).ranges() 9 | 10 | # Public 11 | constructor: (@editor) -> 12 | 13 | # Public 14 | ranges: -> 15 | selectionRanges = @selectionRanges() 16 | if selectionRanges.length is 0 17 | [@sortableRangeForEntireBuffer()] 18 | else 19 | selectionRanges.map (selectionRange) => 20 | @sortableRangeFrom(selectionRange) 21 | 22 | # Internal 23 | selectionRanges: -> 24 | @editor.getSelectedBufferRanges().filter (range) -> 25 | not range.isEmpty() 26 | 27 | # Internal 28 | sortableRangeForEntireBuffer: -> 29 | @editor.getBuffer().getRange() 30 | 31 | # Internal 32 | sortableRangeFrom: (selectionRange) -> 33 | startRow = selectionRange.start.row 34 | startCol = 0 35 | endRow = if selectionRange.end.column == 0 36 | selectionRange.end.row - 1 37 | else 38 | selectionRange.end.row 39 | endCol = @editor.lineTextForBufferRow(endRow).length 40 | 41 | new Range [startRow, startCol], [endRow, endCol] 42 | -------------------------------------------------------------------------------- /lib/csscomb.coffee: -------------------------------------------------------------------------------- 1 | CsscombRangeFinder = require './csscomb-range-finder' 2 | Comb = require 'csscomb' 3 | fs = require 'fs' 4 | CSON = require 'season' 5 | 6 | module.exports = 7 | activate: (state) -> 8 | atom.commands.add 'atom-text-editor', 'csscomb:run', -> 9 | csscomb atom.workspace.getActivePaneItem() 10 | 11 | findConfig = -> 12 | userConfig = atom.config.get 'csscomb' 13 | if userConfig 14 | console.log 'Found user CSScomb config:', userConfig 15 | userConfig 16 | else 17 | jsonConfig = atom.project.getDirectories()[0]?.resolve '.csscomb.json' 18 | csonConfig = atom.project.getDirectories()[0]?.resolve '.csscomb.cson' 19 | if fs.existsSync jsonConfig 20 | console.log 'Found project CSScomb config:', jsonConfig 21 | require jsonConfig 22 | else if fs.existsSync csonConfig 23 | console.log 'Found project CSScomb config:', csonConfig 24 | CSON.readFileSync csonConfig 25 | else 26 | console.log 'Could not find project CSScomb config, using default: \'csscomb\'' 27 | 'csscomb' 28 | 29 | syntaxes = 30 | supported: [ 31 | 'css' 32 | 'sass' 33 | 'scss' 34 | 'less' 35 | ] 36 | default: 'css' 37 | 38 | csscomb = (editor) -> 39 | ranges = CsscombRangeFinder.rangesFor editor 40 | title = editor.getTitle() 41 | throw new Error 'No editor selected' unless title? 42 | syntax = (editor.getTitle().split '.').pop() 43 | syntax = syntaxes.default unless syntax in syntaxes.supported 44 | config = findConfig() 45 | comb = new Comb config 46 | ranges.forEach (range) -> 47 | content = editor.getTextInBufferRange range 48 | result = comb.processString content, syntax: syntax 49 | editor.setTextInBufferRange range, result 50 | -------------------------------------------------------------------------------- /menus/csscomb.cson: -------------------------------------------------------------------------------- 1 | # See https://atom.io/docs/latest/creating-a-package#menus for more details 2 | 'menu': [ 3 | { 4 | 'label': 'Packages' 5 | 'submenu': [ 6 | 'label': 'CSScomb' 7 | 'submenu': [ 8 | { 'label': 'Sort', 'command': 'csscomb:run' } 9 | ] 10 | ] 11 | }, 12 | { 13 | 'label': 'Edit' 14 | 'submenu': [ 15 | 'label': 'Lines' 16 | 'submenu': [ 17 | { 'label': 'Sort with CSScomb', 'command': 'csscomb:run'} 18 | ] 19 | ] 20 | } 21 | ] 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "csscomb", 3 | "main": "./lib/csscomb", 4 | "version": "0.3.1", 5 | "private": true, 6 | "description": "Atom Editor plugin for CSScomb, http://csscomb.com", 7 | "activationCommands": { 8 | "atom-workspace": [ 9 | "csscomb:run" 10 | ] 11 | }, 12 | "repository": "https://github.com/bruce/atom-csscomb", 13 | "license": "MIT", 14 | "engines": { 15 | "atom": ">=0.174.0 <2.0.0" 16 | }, 17 | "dependencies": { 18 | "csscomb": "^3.1.6", 19 | "season": "^5.2.0" 20 | } 21 | } 22 | --------------------------------------------------------------------------------