-
Notifications
You must be signed in to change notification settings - Fork 453
/
prettydiff.coffee
121 lines (112 loc) · 2.93 KB
/
prettydiff.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"use strict"
Beautifier = require('./beautifier')
module.exports = class PrettyDiff extends Beautifier
name: "Pretty Diff"
options: {
# Apply these options first / globally, for all languages
_:
inchar: "indent_char"
insize: "indent_size"
objsort: (objsort) ->
objsort or false
preserve: ['preserve_newlines', (preserve_newlines) ->
if (preserve_newlines is true ) then \
"all" else "none"
]
cssinsertlines: "newline_between_rules"
comments: ["indent_comments", (indent_comments) ->
if (indent_comments is false) then \
"noindent" else "indent"
]
force: "force_indentation"
quoteConvert: "convert_quotes"
vertical: ['align_assignments', (align_assignments) ->
if (align_assignments is true ) then \
"all" else "none"
]
wrap: "wrap_line_length"
space: "space_after_anon_function"
noleadzero: "no_lead_zero"
endcomma: "end_with_comma"
methodchain: ['break_chained_methods', (break_chained_methods) ->
if (break_chained_methods is true ) then \
false else true
]
ternaryline: "preserve_ternary_lines"
# Apply language-specific options
CSV: true
Coldfusion: true
ERB: true
EJS: true
HTML: true
XML: true
SVG: true
Spacebars: true
JSX: true
JavaScript: true
CSS: true
SCSS: true
Sass: true
JSON: true
TSS: true
Twig: true
LESS: true
Swig: true
Visualforce: true
"Riot.js": true
}
beautify: (text, language, options) ->
return new @Promise((resolve, reject) =>
prettydiff = require("prettydiff")
_ = require('lodash')
# Select Prettydiff language
lang = "auto"
switch language
when "CSV"
lang = "csv"
when "Coldfusion"
lang = "html"
when "EJS", "Twig"
lang = "ejs"
when "ERB"
lang = "html_ruby"
when "Handlebars", "Mustache", "Spacebars", "Swig", "Riot.js"
lang = "handlebars"
when "SGML"
lang = "markup"
when "XML", "Visualforce", "SVG"
lang = "xml"
when "HTML"
lang = "html"
when "JavaScript"
lang = "javascript"
when "JSON"
lang = "json"
when "JSX"
lang = "jsx"
when "JSTL"
lang = "jsp"
when "CSS"
lang = "css"
when "LESS"
lang = "less"
when "SCSS", "Sass"
lang = "scss"
when "TSS"
lang = "tss"
else
lang = "auto"
# Prettydiff Arguments
args =
source: text
lang: lang
mode: "beautify"
# Merge args intos options
_.merge(options, args)
# Beautify
@verbose('prettydiff', options)
output = prettydiff.api(options)
result = output[0]
# Return beautified text
resolve(result)
)