Просмотр исходного кода

compile current file if top level document #42

Daniel Felder 12 лет назад
Родитель
Сommit
f03b2df461

+ 8 - 3
services/web/app/coffee/Features/Compile/ClsiManager.coffee

@@ -8,8 +8,8 @@ logger = require "logger-sharelatex"
 url = require("url")
 
 module.exports = ClsiManager =
-	sendRequest: (project_id, callback = (error, success) ->) ->
-		ClsiManager._buildRequest project_id, (error, req) ->
+	sendRequest: (project_id, settingsOverride = {}, callback = (error, success) ->) ->
+		ClsiManager._buildRequest project_id, settingsOverride, (error, req) ->
 			return callback(error) if error?
 			logger.log project_id: project_id, "sending compile to CLSI"
 			ClsiManager._postToClsi project_id, req, (error, response) ->
@@ -52,7 +52,7 @@ module.exports = ClsiManager =
 		return outputFiles
 
 	VALID_COMPILERS: ["pdflatex", "latex", "xelatex", "lualatex"]
-	_buildRequest: (project_id, callback = (error, request) ->) ->
+	_buildRequest: (project_id, settingsOverride={}, callback = (error, request) ->) ->
 		Project.findById project_id, {compiler: 1, rootDoc_id: 1}, (error, project) ->
 			return callback(error) if error?
 			return callback(new Errors.NotFoundError("project does not exist: #{project_id}")) if !project?
@@ -67,6 +67,7 @@ module.exports = ClsiManager =
 
 					resources = []
 					rootResourcePath = null
+					rootResourcePathOverride = null
 
 					for path, doc of docs
 						path = path.replace(/^\//, "") # Remove leading /
@@ -75,6 +76,10 @@ module.exports = ClsiManager =
 							content: doc.lines.join("\n")
 						if project.rootDoc_id? and doc._id.toString() == project.rootDoc_id.toString()
 							rootResourcePath = path
+						if settingsOverride.rootDoc_id? and doc._id.toString() == settingsOverride.rootDoc_id.toString()
+							rootResourcePathOverride = path
+
+					rootResourcePath = rootResourcePathOverride if rootResourcePathOverride?
 
 					for path, file of files
 						path = path.replace(/^\//, "") # Remove leading /

+ 3 - 1
services/web/app/coffee/Features/Compile/CompileController.coffee

@@ -11,9 +11,11 @@ module.exports = CompileController =
 	compile: (req, res, next = (error) ->) ->
 		project_id = req.params.Project_id
 		isAutoCompile = !!req.query?.auto_compile
+		settingsOverride = req.body.settingsOverride ? {};
+		logger.log "root doc overriden" if settingsOverride.rootDoc_id?
 		AuthenticationController.getLoggedInUserId req, (error, user_id) ->
 			return next(error) if error?
-			CompileManager.compile project_id, user_id, { isAutoCompile }, (error, status, outputFiles) ->
+			CompileManager.compile project_id, user_id, { isAutoCompile, settingsOverride }, (error, status, outputFiles) ->
 				return next(error) if error?
 				res.contentType("application/json")
 				res.send 200, JSON.stringify {

+ 1 - 1
services/web/app/coffee/Features/Compile/CompileManager.coffee

@@ -30,7 +30,7 @@ module.exports = CompileManager =
 					return callback(error) if error?
 					DocumentUpdaterHandler.flushProjectToMongo project_id, (error) ->
 						return callback(error) if error?
-						ClsiManager.sendRequest project_id, (error, status, outputFiles) ->
+						ClsiManager.sendRequest project_id, opt.settingsOverride, (error, status, outputFiles) ->
 							return callback(error) if error?
 							logger.log files: outputFiles, "output files"
 							callback(null, status, outputFiles)

+ 6 - 1
services/web/public/coffee/pdf/CompiledView.coffee

@@ -204,7 +204,12 @@ define [
 
 		recompilePdf: () ->
 			@options.manager.trigger "compile:pdf"
-			@options.manager.refreshPdf()
+			rootDocOverride_id = null
+			for line in @ide.editor.getLines()
+				match = line.match /(.*)\\documentclass/
+				if match and !match[1].match /%/
+					rootDocOverride_id = @ide.editor.getCurrentDocId()
+			@options.manager.refreshPdf {rootDocOverride_id}
 
 		toggleFlatViewButton: () -> @$("#flatViewButton").button("toggle")
 		toggleSplitViewButton: () -> @$("#splitViewButton").button("toggle")

+ 6 - 3
services/web/public/coffee/pdf/PdfManager.coffee

@@ -143,7 +143,7 @@ define [
 				@view.onCompiling()
 				@syncButtonsView?.hide()
 				@compiling = true
-				@_doCompile opts.isAutoCompile, (error, status, outputFiles) =>
+				@_doCompile opts, (error, status, outputFiles) =>
 					@compiling = false
 					doneCompiling()
 
@@ -172,16 +172,19 @@ define [
 					if outputFiles?
 						@view.showOutputFileDownloadLinks(outputFiles)
 
-		_doCompile: (isAutoCompile, callback = (error, status, outputFiles) ->) ->
+		_doCompile: (opts, callback = (error, status, outputFiles) ->) ->
 			url = "/project/#{@ide.project_id}/compile"
-			if isAutoCompile
+			if opts.isAutoCompile
 				url += "?auto_compile=true"
 			$.ajax(
 				url: url
 				type: "POST"
 				headers:
 					"X-CSRF-Token": window.csrfToken
+				contentType: "application/json; charset=utf-8"
 				dataType: 'json'
+				data: JSON.stringify settingsOverride: 
+					rootDoc_id: opts.rootDocOverride_id ? null
 				success: (body, status, response) ->
 					callback null, body.status, body.outputFiles
 				error: (error) ->