Den LaTeX-Publisher hinzugefügt.
This commit is contained in:
parent
1e934b0c4c
commit
81b914c1a1
2 changed files with 50 additions and 4 deletions
53
event.js
53
event.js
|
@ -18,7 +18,8 @@ var
|
||||||
,log = require('sys').log
|
,log = require('sys').log
|
||||||
,mustache = require('mustache')
|
,mustache = require('mustache')
|
||||||
,strftime = require('strftime')
|
,strftime = require('strftime')
|
||||||
,fs = require('fs');
|
,fs = require('fs')
|
||||||
|
,glob = require('glob');
|
||||||
|
|
||||||
function nextDay(x){
|
function nextDay(x){
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
|
@ -43,10 +44,8 @@ EventTool.prototype.config = require('./config');
|
||||||
EventTool.prototype.RequestData = '';
|
EventTool.prototype.RequestData = '';
|
||||||
EventTool.prototype.events = [];
|
EventTool.prototype.events = [];
|
||||||
|
|
||||||
EventTool.prototype.publishMail = function() {
|
EventTool.prototype.processEventData = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
log('Verschicke eine E-Mail');
|
|
||||||
|
|
||||||
var view = {
|
var view = {
|
||||||
events: []
|
events: []
|
||||||
};
|
};
|
||||||
|
@ -59,6 +58,13 @@ EventTool.prototype.publishMail = function() {
|
||||||
item['text'] = el.text;
|
item['text'] = el.text;
|
||||||
view.events.push(item);
|
view.events.push(item);
|
||||||
});
|
});
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
EventTool.prototype.publishMail = function() {
|
||||||
|
var self = this;
|
||||||
|
log('Verschicke eine E-Mail');
|
||||||
|
var view = self.processEventData();
|
||||||
// load the template
|
// load the template
|
||||||
var template = fs.readFileSync('templates/email/template.mustache','utf-8');
|
var template = fs.readFileSync('templates/email/template.mustache','utf-8');
|
||||||
console.log(view);
|
console.log(view);
|
||||||
|
@ -78,6 +84,44 @@ EventTool.prototype.publishMail = function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EventTool.prototype.publishLatex = function() {
|
||||||
|
var self = this;
|
||||||
|
log('Erzeuge PDFs mit LaTeX');
|
||||||
|
var view = self.processEventData();
|
||||||
|
// generate the pdfs
|
||||||
|
self.config.latex.templates.forEach(function(template){
|
||||||
|
var templateData = fs.readFileSync('templates/latex/'+template+'.tex','utf-8');
|
||||||
|
var output = mustache.render(templateData, view);
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(self.config.latex.tempDir);
|
||||||
|
} catch(e) {
|
||||||
|
// POKEMON! GOTTA CATCH THEM ALL!
|
||||||
|
}
|
||||||
|
var tempfilePrefix = self.config.latex.tempDir + '/' + template;
|
||||||
|
fs.writeFileSync(tempfilePrefix+'.tex',output);
|
||||||
|
var spawn = require('child_process').spawn,
|
||||||
|
pdflatex = spawn('pdflatex', ['-interaction','nonstopmode','-output-directory', self.config.latex.tempDir,tempfilePrefix+'.tex']);
|
||||||
|
|
||||||
|
pdflatex.on('exit', function (code) {
|
||||||
|
log('child process exited with code ' + code);
|
||||||
|
if (code === 0) {
|
||||||
|
log('Copy the PDF to the output dir');
|
||||||
|
fs.createReadStream(tempfilePrefix+'.pdf').pipe(fs.createWriteStream(self.config.latex.output+'/'+template+'.pdf'));
|
||||||
|
|
||||||
|
// now clean up the tempdir
|
||||||
|
glob('**/*',{cwd:self.config.latex.tempDir},function(err,files){
|
||||||
|
files.forEach(function(file){
|
||||||
|
fs.unlinkSync(self.config.latex.tempDir+'/'+file);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
log('Failed to generate the pdf. Please chek the logs under '+ tempfilePrefix+'.log');
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
EventTool.prototype.publishIdentica = function() {
|
EventTool.prototype.publishIdentica = function() {
|
||||||
log('Verschicke einen Dent');
|
log('Verschicke einen Dent');
|
||||||
}
|
}
|
||||||
|
@ -85,6 +129,7 @@ EventTool.prototype.publishIdentica = function() {
|
||||||
EventTool.prototype.setupPublishers = function() {
|
EventTool.prototype.setupPublishers = function() {
|
||||||
this.on('mail',this.publishMail);
|
this.on('mail',this.publishMail);
|
||||||
this.on('identica',this.publishIdentica);
|
this.on('identica',this.publishIdentica);
|
||||||
|
this.on('latex',this.publishLatex);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventTool.prototype.processEvents = function() {
|
EventTool.prototype.processEvents = function() {
|
||||||
|
|
|
@ -7,5 +7,6 @@
|
||||||
, "jsdom": "latest"
|
, "jsdom": "latest"
|
||||||
, "nodemailer": "latest"
|
, "nodemailer": "latest"
|
||||||
, "strftime": "latest"
|
, "strftime": "latest"
|
||||||
|
, "glob": "latest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue