diff --git a/app/coffee/CompileController.coffee b/app/coffee/CompileController.coffee index ce107f8..f7d46b1 100644 --- a/app/coffee/CompileController.coffee +++ b/app/coffee/CompileController.coffee @@ -68,7 +68,7 @@ module.exports = CompileController = } wordcount: (req, res, next = (error) ->) -> - file = req.query.file + file = req.query.file || "main.tex" project_id = req.params.project_id CompileManager.wordcount project_id, file, (error, result) -> diff --git a/app/coffee/CompileManager.coffee b/app/coffee/CompileManager.coffee index 0392cce..b4a8357 100644 --- a/app/coffee/CompileManager.coffee +++ b/app/coffee/CompileManager.coffee @@ -111,6 +111,18 @@ module.exports = CompileManager = } return results + wordcount: (project_id, file_name, callback = (error, pdfPositions) ->) -> + logger.log project_id:project_id, file_name:file_name, "running wordcount" + file_path = "$COMPILE_DIR/" + file_name + command = [ "texcount", '-inc', file_path, "-out=" + file_path + ".wc"] + directory = Path.join(Settings.path.compilesDir, project_id) + timeout = 10 * 1000 + + CommandRunner.run project_id, command, directory, timeout, (error) -> + return callback(error) if error? + stdout = fs.readFileSync(directory + "/" + file_name + ".wc", "utf-8") + callback null, CompileManager._parseWordcountFromOutput(stdout) + _parseWordcountFromOutput: (output) -> results = { encode: "" @@ -140,16 +152,4 @@ module.exports = CompileManager = results['mathInline'] = parseInt(info, 10) if data.indexOf("displayed") > -1 results['mathDisplay'] = parseInt(info, 10) - return results - - wordcount: (project_id, file_name, callback = (error, pdfPositions) ->) -> - file_path = "$COMPILE_DIR/" + file_name - command = [ "texcount", file_path, "-out=" + file_path + ".wc"] - directory = Path.join(Settings.path.compilesDir, project_id) - timeout = 10 * 1000 - - CommandRunner.run project_id, command, directory, timeout, (error) -> - return callback(error) if error? - stdout = fs.readFileSync(directory + "/" + file_name + ".wc", "utf-8") - callback null, CompileManager._parseWordcountFromOutput(stdout) diff --git a/test/unit/coffee/CompileManagerTests.coffee b/test/unit/coffee/CompileManagerTests.coffee index 10ab2ea..d6678b9 100644 --- a/test/unit/coffee/CompileManagerTests.coffee +++ b/test/unit/coffee/CompileManagerTests.coffee @@ -191,7 +191,7 @@ describe "CompileManager", -> it "should run the texcount command", -> @directory = "#{@Settings.path.compilesDir}/#{@project_id}" @file_path = "$COMPILE_DIR/#{@file_name}" - @command =[ "texcount", @file_path, "-out=" + @file_path + ".wc"] + @command =[ "texcount", '-inc', @file_path, "-out=" + @file_path + ".wc"] @CommandRunner.run .calledWith(@project_id, @command, @directory, @timeout)