├── .gitignore ├── demo.gif ├── .gitattributes ├── .editorconfig ├── menus └── csscomb.cson ├── readme.md ├── license.md ├── package.json └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | .idea 4 | node_modules 5 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1000ch/atom-csscomb/HEAD/demo.gif -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text eol=lf 3 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /menus/csscomb.cson: -------------------------------------------------------------------------------- 1 | 'context-menu': 2 | 'atom-text-editor': [{ 3 | label: 'Sort CSS properties' 4 | command: 'atom-csscomb:comb' 5 | }] 6 | 7 | 'menu': [{ 8 | 'label': 'Packages' 9 | 'submenu': [ 10 | 'label': 'CSSComb' 11 | 'submenu': [{ 12 | label: 'Sort CSS properties', 13 | command: 'atom-csscomb:comb' 14 | }] 15 | ] 16 | }] 17 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # [atom-csscomb](https://atom.io/packages/atom-csscomb) [![Dependency Status](https://david-dm.org/1000ch/atom-csscomb.svg)](https://david-dm.org/1000ch/atom-csscomb) 2 | 3 | Sort CSS properties with [CSSComb](https://github.com/csscomb/csscomb.js). 4 | 5 | ![demo](https://raw.githubusercontent.com/1000ch/atom-csscomb/master/demo.gif) 6 | 7 | ## Installation 8 | 9 | ```bash 10 | $ apm install atom-csscomb 11 | ``` 12 | 13 | ## Usage 14 | 15 | - Packages > CSSComb > Sort properties 16 | - Context Menu > Sort properties 17 | - Command Palette ( + shift + P) > **CSSComb: Comb** 18 | 19 | ## Configuration 20 | 21 | To configure with [`.csscomb.json`](https://github.com/csscomb/csscomb.js/blob/master/doc/options.md), just put it to workspace. 22 | 23 | ### Preset config 24 | 25 | Configure with presets (`csscomb`, `zen`, `yandex`). 26 | 27 | ### Extend preset 28 | 29 | Extend selected preset config with project config if exists. 30 | 31 | ## License 32 | 33 | [MIT](https://1000ch.mit-license.org) © [Shogo Sensui](https://github.com/1000ch) 34 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Shogo Sensui 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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "atom-csscomb", 3 | "version": "3.0.0", 4 | "private": true, 5 | "description": "Sort CSS properties with CSSComb.", 6 | "activationCommands": { 7 | "atom-text-editor:not([mini])": [ 8 | "atom-csscomb:comb" 9 | ] 10 | }, 11 | "repository": "https://github.com/1000ch/atom-csscomb", 12 | "license": "MIT", 13 | "author": { 14 | "name": "1000ch", 15 | "email": "shogo.sensui@gmail.com", 16 | "url": "https://github.com/1000ch" 17 | }, 18 | "engines": { 19 | "atom": "*", 20 | "node": "*" 21 | }, 22 | "dependencies": { 23 | "atom-linter": "^10.0.0", 24 | "csscomb": "^4.2.0" 25 | }, 26 | "configSchema": { 27 | "presetConfig": { 28 | "title": "Configure with preset", 29 | "description": "Select preset config bundled with CSSComb.", 30 | "type": "string", 31 | "default": "csscomb", 32 | "enum": [ 33 | "csscomb", 34 | "zen", 35 | "yandex" 36 | ] 37 | }, 38 | "extendPreset": { 39 | "title": "Extend preset", 40 | "description": "Extend selected preset config with project config if exists.", 41 | "type": "boolean", 42 | "default": false 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use babel'; 2 | 3 | import { CompositeDisposable } from 'atom'; 4 | import * as path from 'path'; 5 | import Comb from 'csscomb'; 6 | import { find } from 'atom-linter'; 7 | 8 | let subscriptions; 9 | let projectConfig; 10 | let presetConfig; 11 | let extendPreset; 12 | 13 | export function activate(state) { 14 | subscriptions = new CompositeDisposable(); 15 | 16 | subscriptions.add(atom.config.observe('atom-csscomb.presetConfig', value => { 17 | presetConfig = Comb.getConfig(value); 18 | })); 19 | 20 | subscriptions.add(atom.config.observe('atom-csscomb.extendPreset', value => { 21 | extendPreset = value; 22 | })); 23 | 24 | atom.commands.add('atom-workspace', 'atom-csscomb:comb', () => { 25 | comb(atom.workspace.getActiveTextEditor()); 26 | }); 27 | } 28 | 29 | export function deactivate() { 30 | subscriptions.dispose(); 31 | } 32 | 33 | function getConfig(filePath) { 34 | const configFile = find(path.dirname(filePath), '.csscomb.json'); 35 | const projectConfig = configFile ? require(configFile) : null; 36 | 37 | if (extendPreset) { 38 | return Object.assign(presetConfig, projectConfig); 39 | } 40 | 41 | return projectConfig || presetConfig; 42 | } 43 | 44 | async function comb(editor) { 45 | if (!editor) { 46 | return; 47 | } 48 | 49 | const position = editor.getCursorBufferPosition(); 50 | const config = getConfig(editor.getPath()); 51 | 52 | try { 53 | const comb = new Comb(config); 54 | const css = await comb.processString(editor.getText(), { 55 | syntax: editor.getGrammar().name.toLowerCase() 56 | }); 57 | 58 | editor.setText(css); 59 | editor.setCursorBufferPosition(position); 60 | } catch (e) { 61 | console.error(e); 62 | } 63 | } 64 | --------------------------------------------------------------------------------