ProjectRootDocManager.coffee 735 B

12345678910111213141516171819
  1. slReqIdHelper = require('soa-req-id')
  2. ProjectEntityHandler = require "./ProjectEntityHandler"
  3. Path = require "path"
  4. module.exports = ProjectRootDocManager =
  5. setRootDocAutomatically: (project_id, sl_req_id, callback = (error) ->) ->
  6. {callback, sl_req_id} = slReqIdHelper.getCallbackAndReqId(callback, sl_req_id)
  7. ProjectEntityHandler.getAllDocs project_id, sl_req_id, (error, docs) ->
  8. return callback(error) if error?
  9. root_doc_id = null
  10. for path, doc of docs
  11. for line in doc.lines || []
  12. if Path.extname(path).match(/\.R?tex$/) and line.match(/\\documentclass/)
  13. root_doc_id = doc._id
  14. if root_doc_id?
  15. ProjectEntityHandler.setRootDoc project_id, root_doc_id, sl_req_id, callback
  16. else
  17. callback()