mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-29 06:43:43 +00:00
20 lines
735 B
CoffeeScript
20 lines
735 B
CoffeeScript
|
slReqIdHelper = require('soa-req-id')
|
||
|
ProjectEntityHandler = require "./ProjectEntityHandler"
|
||
|
Path = require "path"
|
||
|
|
||
|
module.exports = ProjectRootDocManager =
|
||
|
setRootDocAutomatically: (project_id, sl_req_id, callback = (error) ->) ->
|
||
|
{callback, sl_req_id} = slReqIdHelper.getCallbackAndReqId(callback, sl_req_id)
|
||
|
ProjectEntityHandler.getAllDocs project_id, sl_req_id, (error, docs) ->
|
||
|
return callback(error) if error?
|
||
|
root_doc_id = null
|
||
|
for path, doc of docs
|
||
|
for line in doc.lines || []
|
||
|
if Path.extname(path).match(/\.R?tex$/) and line.match(/\\documentclass/)
|
||
|
root_doc_id = doc._id
|
||
|
if root_doc_id?
|
||
|
ProjectEntityHandler.setRootDoc project_id, root_doc_id, sl_req_id, callback
|
||
|
else
|
||
|
callback()
|
||
|
|