-
Notifications
You must be signed in to change notification settings - Fork 4
/
csscomb.coffee
49 lines (45 loc) · 1.48 KB
/
csscomb.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
CsscombRangeFinder = require './csscomb-range-finder'
Comb = require 'csscomb'
fs = require 'fs'
CSON = require 'season'
module.exports =
activate: (state) ->
atom.commands.add 'atom-text-editor', 'csscomb:run', ->
csscomb atom.workspace.getActivePaneItem()
findConfig = ->
userConfig = atom.config.get 'csscomb'
if userConfig
console.log 'Found user CSScomb config:', userConfig
userConfig
else
jsonConfig = atom.project.getDirectories()[0]?.resolve '.csscomb.json'
csonConfig = atom.project.getDirectories()[0]?.resolve '.csscomb.cson'
if fs.existsSync jsonConfig
console.log 'Found project CSScomb config:', jsonConfig
require jsonConfig
else if fs.existsSync csonConfig
console.log 'Found project CSScomb config:', csonConfig
CSON.readFileSync csonConfig
else
console.log 'Could not find project CSScomb config, using default: \'csscomb\''
'csscomb'
syntaxes =
supported: [
'css'
'sass'
'scss'
'less'
]
default: 'css'
csscomb = (editor) ->
ranges = CsscombRangeFinder.rangesFor editor
title = editor.getTitle()
throw new Error 'No editor selected' unless title?
syntax = (editor.getTitle().split '.').pop()
syntax = syntaxes.default unless syntax in syntaxes.supported
config = findConfig()
comb = new Comb config
ranges.forEach (range) ->
content = editor.getTextInBufferRange range
result = comb.processString content, syntax: syntax
editor.setTextInBufferRange range, result