ProjectRootDocManager.coffee 661 B

123456789101112131415161718
  1. ProjectEntityHandler = require "./ProjectEntityHandler"
  2. Path = require "path"
  3. module.exports = ProjectRootDocManager =
  4. setRootDocAutomatically: (project_id, callback = (error) ->) ->
  5. ProjectEntityHandler.getAllDocs project_id, (error, docs) ->
  6. return callback(error) if error?
  7. root_doc_id = null
  8. for path, doc of docs
  9. for line in doc.lines || []
  10. match = line.match /(.*)\\documentclass/ # no lookbehind in js regexp :(
  11. if Path.extname(path).match(/\.R?tex$/) and match and !match[1].match /%/
  12. root_doc_id = doc._id
  13. if root_doc_id?
  14. ProjectEntityHandler.setRootDoc project_id, root_doc_id, callback
  15. else
  16. callback()