overleaf/services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee
Daniel Felder 1d12b88b09 Ignore commented lines when setting root doc #52
Same code I used in public/coffee/pdf/CompiledView.coffee. I didn't test it locally though.
2014-06-05 18:00:07 +02:00

20 lines
813 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 || []
match = line.match /(.*)\\documentclass/ # no lookbehind in js regexp :(
if Path.extname(path).match(/\.R?tex$/) and match and !match[1].match /%/
root_doc_id = doc._id
if root_doc_id?
ProjectEntityHandler.setRootDoc project_id, root_doc_id, sl_req_id, callback
else
callback()