Commit f0db281d authored by BERTHAUT Florent's avatar BERTHAUT Florent
Browse files

Modified tsm template

parent 6fe5c84d
This source diff could not be displayed because it is too large. You can view the blob instead.
No preview for this file type
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -18,6 +18,17 @@ parcoursFilters.set("Traduction spécialisée multilingue", new Map([
["Descriptif du cours", ["Descriptif"]],
["Compétence(s) visée(s)", ["Compétence(s) visée(s)"]],
["Contrôle des connaissances", ["Informations sur l'évaluation"]],
["Langue d'enseignement", ["Langue d'enseignement"]],
["Bibliographie sélective", ["Bibliographie sélective"]]
]));
parcoursFilters.set("default", new Map([
["Enseignement", ["Nom EC"] ],
["Responsable", ["Enseignant.e.s"]],
["Pré-requis", ["Prérequis"]],
["Descriptif du cours", ["Descriptif"]],
["Compétence(s) visée(s)", ["Compétence(s) visée(s)"]],
["Contrôle des connaissances", ["Informations sur l'évaluation"]],
["Langue d'enseignement", ["Langue d'enseignement"]],
["Bibliographie sélective", ["Bibliographie sélective"]]
]));
......@@ -35,6 +46,8 @@ Papa.parse(csv, {
//save all year/specialisation to separate docs
saveAllToDocs();
//saveToDoc("Traduction spécialisée multilingue");
//saveToDoc("Techniques du commerce international (L3)");
}
});
......@@ -43,32 +56,55 @@ Papa.parse(csv, {
function parseParcours(fiches) {
console.log("Building parcours structure");
for(let f of fiches) {
if(f["Parcours"]!="" && f["Parcours"]!=undefined) {
//if specialisation does not already exists
if(!parcours.has(f["Parcours"])) {
parcours.set(f["Parcours"], new Map());
console.log("Creating parcours ", f["Parcours"]);
}
let parc = parcours.get(f["Parcours"]);
//if year does not already exists
if(!parc.has(f["Année"])) {
console.log("Creating year", f["Année"],
"for", f["Parcours"]);
parc.set(f["Année"], new Map());
}
//test if this fiche is for multiple parcours
let parcs = f["Parcours"].split(",");
for(let p of parcs) {
// console.log("processing ", p, f["UE"]);
//if specialisation does not already exists
if(!parcours.has(p)) {
parcours.set(p, new Map());
console.log("Creating parcours ", p);
}
let parc = parcours.get(p);
let year = parc.get(f["Année"]);
//if semester does not already exists
if(!year.has(f["Semestre"])) {
console.log("Creating semester", f["Semestre"],
"for", f["Parcours"]);
year.set(f["Semestre"], []);
//if year does not already exists
if(!parc.has(f["Année"])) {
console.log("Creating year", f["Année"],
"for", p);
parc.set(f["Année"], new Map());
}
let year = parc.get(f["Année"]);
//if semester does not already exists
if(!year.has(f["Semestre"])) {
console.log("Creating semester", f["Semestre"],
"for", p);
year.set(f["Semestre"], []);
}
//fill the specialisation/year/semester with UE info
let sem = year.get(f["Semestre"]);
sem.push(f);
}
}
}
//fill the specialisation/year/semester with UE info
let sem = year.get(f["Semestre"]);
sem.push(f);
for(let parc of parcours.values()) {
for(let year of parc.values()) {
for(let sem of year.values()) {
sem.sort(function(a,b) {
if(a["UE"]<b["UE"]) {
return -1;
}
else if(a["UE"]>b["UE"]) {
return 1;
}
return 0;
});
}
}
}
}
......@@ -81,26 +117,48 @@ function addLine(guide, row, label, suffix) {
function writeFilteredFicheToStr(guide, f) {
let parcFilt = parcoursFilters.get(f["Parcours"]);
if(parcFilt==undefined) {
parcFilt = parcoursFilters.get("default");
}
const empty = /\s*/;
//header
//guide.str +="<div custom-style='Page Break'> \n";
//guide.str += "</div>\n";
//guide.str += "LEA "+f["Année"]+" "+f["Parcours"]+" S"+String(f["Semestre"]).trim();
guide.str += "<p>\n";
guide.str += "<span custom-style='FicheTitle'>UE&nbsp;: </span> ";
guide.str += "<span custom-style='FicheTitleValue'>"+f["Nom UE"]+"</span>\n";
guide.str += "</p>\n";
guide.str += "<p>&nbsp</p>\n";
for(let destField of parcFilt.keys()) {
//guide.str +="<p>\n";
guide.str += "<span custom-style='Paragraph Title'>"+destField+": </span> ";
guide.str += "<p>\n";
guide.str += "<span custom-style='FieldTitle'>"+destField+"&nbsp;: </span> ";
for(let origField of parcFilt.get(destField)) {
let fieldText = f[origField];
fieldText = fieldText.replace(/<br \/>/g, "");
//remove extra lines of type (<p><br /></p>)
fieldText = fieldText.replace(/<p><br \/><\/p>/g, "");
//remove span for lang
fieldText = fieldText.replace(/<span*>/g, "");
fieldText = fieldText.replace(/<\/span>/g, "");
//remove last <br/> if there is one
if(fieldText.endsWith("<br />")) {
fieldText = fieldText.substr(0, fieldText.length-6);
}
guide.str += fieldText+" ";
if(!fieldText.includes("</p>")) {
/*
if(!fieldText.includes("</p>") && !fieldText.includes("</ul>")) {
guide.str +="<br/>\n";
guide.str +="<br/>\n";
}
else {
guide.str +="\n";
}*/
}
guide.str += "</p>\n";
}
guide.str +="<div custom-style='Page Break'> \n";
......@@ -163,76 +221,83 @@ function writeFicheToStr(guide, f) {
}
function saveAllToDocs() {
console.log("Writing to docs");
//Loop on all specialisations
for(let parc of parcours.keys()) {
//console.log(parcours.get(parc));
let guideFileName = "output/guide-"+String(parc).replace(/\ /g, "_");
function saveToDoc(parc) {
let guideFileName = "output/guide-"+String(parc).trim().replace(/\ /g, "_");
guideFileName = guideFileName.replace('(', "").replace(')',"");
let guide = {};
guide.str = "";
let guide = {};
guide.str = "";
//add all the fiches
for(let year of parcours.get(parc).values()) {
for(let sem of year.values()) {
for(let f of sem) {
//add all the fiches
for(let year of parcours.get(parc).values()) {
for(let sem of year.values()) {
for(let f of sem) {
//if(f["Semestre"]=="1" && f["UE"]=="3.1") {
//writeFicheToStr(guide, f);
writeFilteredFicheToStr(guide, f);
}
//}
}
}
}
//Write the html file
fs.writeFileSync(guideFileName+".html", guide.str, {"encoding":"utf-8"});
console.log("Done building "+guideFileName+".html");
//Transform from html to markdown
let commandHTML = "pandoc ";
commandHTML+=" -f html "+guideFileName+".html ";
commandHTML+=" -t markdown -o "+guideFileName+".md";
exec(commandHTML,
(error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
//Write the html file
fs.writeFileSync(guideFileName+".html", guide.str, {"encoding":"utf-8"});
console.log("Done building guide.html");
//Transform from html to markdown
let commandHTML = "pandoc ";//--lua-filter=src/pagebreak.lua ";
commandHTML+=" -f html "+guideFileName+".html ";
commandHTML+=" -t markdown -o "+guideFileName+".md";
exec(commandHTML,
(error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
//Transfrom markdown to doc/odt
let commandODT = "pandoc -t odt+smart ";
// let commandODT = "pandoc -s -t docx ";
commandODT+=" --lua-filter src/pagebreak.lua ";
commandODT+=" --lua-filter src/odt-custom-styles.lua ";
commandODT+=" -f markdown "+guideFileName+".md ";
commandODT+=" --reference-doc='input/reference.odt' ";
commandODT+=" -o "+guideFileName+".odt ";
// commandODT+=" --reference-doc='input/reference.docx' ";
// commandODT+=" -o "+guideFileName+".docx ";
exec(commandODT,
(error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
/*
let commandPDF = "libreoffice --headless --convert-to pdf";
commandPDF+=guideFileName+".odt --outdir output";
//Convert odt to pdf using libreoffice
exec(commandPDF,
(error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
});*/
});
});
//Transfrom markdown to doc/odt
let commandODT = "pandoc -t odt+smart ";
commandODT+=" --lua-filter src/pagebreak.lua ";
commandODT+=" --lua-filter src/odt-custom-styles.lua ";
commandODT+=" -f markdown "+guideFileName+".md ";
commandODT+=" --reference-doc='input/reference.odt' ";
commandODT+=" -o "+guideFileName+".odt ";
exec(commandODT,
(error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
let commandPDF = "libreoffice --headless --convert-to pdf";
commandPDF +=guideFileName+".odt --outdir output";
//Convert odt to pdf using libreoffice
exec(commandPDF,
(error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
});
});
});
}
function saveAllToDocs() {
console.log("Writing to docs");
//Loop on all specialisations
for(let parc of parcours.keys()) {
//console.log(parcours.get(parc));
saveToDoc(parc);
}
console.log("Done converting");
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment