From a570d051324ebd09c3e22274a4e2dd22ee470593 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 1 Dec 2014 01:07:03 +0000 Subject: [PATCH] fixed bug with setting root doc which would fail if the document class isn't on the top line --- .../coffee/Features/Project/ProjectRootDocManager.coffee | 8 +++++--- .../coffee/Project/ProjectRootDocManagerTests.coffee | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee b/services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee index 98b5175c0d..da2743d661 100644 --- a/services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee +++ b/services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee @@ -5,6 +5,7 @@ _ = require("underscore") module.exports = ProjectRootDocManager = setRootDocAutomatically: (project_id, callback = (error) ->) -> + ProjectEntityHandler.getAllDocs project_id, (error, docs) -> return callback(error) if error? @@ -12,13 +13,14 @@ module.exports = ProjectRootDocManager = root_doc_id = null jobs = _.map docs, (doc, path)-> return (cb)-> + rootDocId = null for line in doc.lines || [] match = line.match /(.*)\\documentclass/ # no lookbehind in js regexp :( isRootDoc = Path.extname(path).match(/\.R?tex$/) and match and !match[1].match /%/ if isRootDoc - return cb(doc?._id) - else - return cb() + rootDocId = doc?._id + cb(rootDocId) + async.series jobs, (root_doc_id)-> if root_doc_id? ProjectEntityHandler.setRootDoc project_id, root_doc_id, callback diff --git a/services/web/test/UnitTests/coffee/Project/ProjectRootDocManagerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectRootDocManagerTests.coffee index a155b1b388..c4b7d17d11 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectRootDocManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectRootDocManagerTests.coffee @@ -18,10 +18,10 @@ describe 'ProjectRootDocManager', -> @docs = "/chapter1.tex": _id: "doc-id-1" - lines: ["\\begin{document}", "Hello world", "\\end{document}"] + lines: ["something else","\\begin{document}", "Hello world", "\\end{document}"] "/main.tex": _id: "doc-id-2" - lines: ["\\documentclass{article}", "\\input{chapter1}"] + lines: ["different line","\\documentclass{article}", "\\input{chapter1}"] "/nested/chapter1a.tex": _id: "doc-id-3" lines: ["Hello world"]