mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Re-use parser
This commit is contained in:
@@ -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)
|
||||
)
|
||||
|
||||
+1
-1
@@ -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) ->
|
||||
Reference in New Issue
Block a user