gulp-require-classify
Version:
A gulp plug-in to make requireJS and ng-classify compatible with a simple syntax
56 lines (42 loc) • 1.67 kB
text/coffeescript
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) ->
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)->
processString = subMatch.match(/^((\n|\t|\r)*?)[
tabSize = processString.substr(processString.lastIndexOf('\n'), processString.length).split('\t').length - 1
try
isFunction = opt instanceof Function
options = if isFunction then opt(file) else opt
# Unindenting
for value in [1..tabSize]
subMatch = unindent subMatch
data = ''
data = ng_classify subMatch, options
return indent data, tabSize, '\t'
catch err
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