Re-use parser

This commit is contained in:
Shane Kilkelly 2017-06-12 15:15:14 +01:00
parent debb0c06a4
commit 26be4f84d0
2 changed files with 14 additions and 11 deletions

View file

@ -1,5 +1,6 @@
ProjectEntityHandler = require "../Project/ProjectEntityHandler"
DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler')
Async = require('async')
module.exports = LabelsHandler =
@ -40,14 +41,16 @@ module.exports = LabelsHandler =
docLabels.push(labelMatch[1])
callback(null, docLabels)
extractLabelsFromProjectDocs: (docs, callback=(err, projectLabels)->) ->
extractLabelsFromProjectDocs: (projectDocs, callback=(err, projectLabels)->) ->
projectLabels = {} # docId => List[Label]
for _docPath, doc of docs
docLabels = []
for line in doc.lines
re = LabelsHandler.labelCaptureRegex()
while (labelMatch = re.exec(line))
if labelMatch[1]
docLabels.push(labelMatch[1])
projectLabels[doc._id] = docLabels
callback(null, projectLabels)
docs = for _path, doc of projectDocs
doc
Async.eachSeries(
docs
, (doc, cb) ->
LabelsHandler.extractLabelsFromDoc doc.lines, (err, docLabels) ->
projectLabels[doc._id] = docLabels
cb(err)
, (err, x) ->
callback(err, projectLabels)
)

View file

@ -61,7 +61,7 @@ describe 'LabelsHandler', ->
it 'should not produce an error', (done) ->
@LabelsHandler.extractLabelsFromProjectDocs @docs, (err, projectLabels) ->
expect(err).to.equal null
expect(err).to.be.oneOf [null, undefined]
done()
it 'should extract all the labels', (done) ->