overleaf/services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee

19 lines
661 B
CoffeeScript
Raw Normal View History

2014-02-12 05:23:40 -05:00
ProjectEntityHandler = require "./ProjectEntityHandler"
Path = require "path"
module.exports = ProjectRootDocManager =
2014-10-15 09:11:02 -04:00
setRootDocAutomatically: (project_id, callback = (error) ->) ->
ProjectEntityHandler.getAllDocs project_id, (error, docs) ->
2014-02-12 05:23:40 -05:00
return callback(error) if error?
root_doc_id = null
for path, doc of docs
for line in doc.lines || []
match = line.match /(.*)\\documentclass/ # no lookbehind in js regexp :(
if Path.extname(path).match(/\.R?tex$/) and match and !match[1].match /%/
2014-02-12 05:23:40 -05:00
root_doc_id = doc._id
if root_doc_id?
2014-10-15 09:11:02 -04:00
ProjectEntityHandler.setRootDoc project_id, root_doc_id, callback
2014-02-12 05:23:40 -05:00
else
callback()