-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.coffee
55 lines (42 loc) · 1.58 KB
/
index.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
events = require 'events'
event_stream = require 'event-stream'
ng_classify = require 'ng-classify'
gulp_util = require 'gulp-util'
unindent = require 'unindent'
indent = require 'indent-string'
module.exports = (opt) =>
console.log this
modifyFile = (file) ->
# Handle Events
emitter = new events.EventEmitter
return if file.isNull()
emitter.emit 'data', file
return if file.isStream()
emitter.emit 'error', new gulp_util.PluginError 'gulp-require-classify', 'Streaming not supported'
fileString = file.contents.toString 'utf8'
file.contents = new Buffer fileString.replace /@classify((.|\n|\t|\r)*)@!classify/g, (Match, subMatch, lastCharacter, numberOfCharacters, completeString)->
# Preparing Data
processString = subMatch.match(/^((\n|\t|\r)*?)[#|a-z]/i)[1]
tabSize = processString.substr(processString.lastIndexOf('\n'), processString.length).split('\t').length - 1
# Processing Data
try
# Applying Options
isFunction = opt instanceof Function
options = if isFunction then opt(file) else opt
# Unindenting
for value in [1..tabSize]
subMatch = unindent subMatch
# Compiling
data = ''
data = ng_classify subMatch, options
# Reindenting
return indent data, tabSize, '\t'
catch err
# Catching Errors
err.filename = file.path
console.log 'Error in :=> ' + err.filename
emitter.on 'error', (err) ->
console.log err.stack
return emitter.emit 'error', new gulp_util.PluginError 'gulp-require-classify', err
@emit 'data', file
event_stream.through modifyFile