Compare commits

...

11 Commits

4 changed files with 146 additions and 22 deletions

View File

@@ -14,18 +14,29 @@ curl "https://stag.tul.cz/StagPortletsJSR168/ProhlizeniPrint?stateClass=cz.zcu.s
}]
}] | from_entries' >> programmes.js
if [ ! -d template_upstream ]; then
git clone git@gordon.zumepro.cz:tul/tultemplate2 template_upstream
TEMPLATE=template_upstream
if [ ! -d $TEMPLATE ]; then
git clone git@gordon.zumepro.cz:tul/tultemplate2 $TEMPLATE
else
cd template_upstream
git pull
cd $TEMPLATE
git fetch --tags
cd ..
fi
cd $TEMPLATE
git checkout $(git describe --tags "$(git rev-list --tags --max-count=1)")
cd ..
TEMPLATE_PACKDIR=$TEMPLATE/pack/bundle
rm -r $TEMPLATE_PACKDIR
cd $TEMPLATE
make bundle
cd ..
cp -r \
template_upstream/template \
template_upstream/citations.bib \
template_upstream/Makefile \
$TEMPLATE_PACKDIR/. \
assignment.pdf \
archive

88
data.js
View File

@@ -18,6 +18,10 @@ let steps = {
layout: language_layout,
result: {
lang: "cs"
},
finalize: (result) => {
result.is_cs = result.lang === "cs";
result.is_en = result.lang === "en";
}
},
thesis_title: {
@@ -51,6 +55,7 @@ let steps = {
}
},
programme: {
condition: () => programmes[steps.faculty.result.name] !== undefined,
title: "Který program studujete?",
layout: programme_layout,
result: {
@@ -101,6 +106,24 @@ let steps = {
finalize: (result) => {
result.include_pdf = result.format === "external";
}
},
other_details: {
title: "Ostatní detaily",
layout: other_details_layout,
result: {
has_keywords: true,
has_acknowledgement: true
}
},
toolchain: {
title: "Jak budete používat Typst?",
layout: toolchain_layout,
result: {
toolchain: "online"
},
finalize: (result) => {
result.include_makefile = result.toolchain === "local";
}
}
}
@@ -197,6 +220,15 @@ const assignment_formats = {
}
}
const toolchains = {
"online": {
name: "Pomocí webového editoru Typstu"
},
"local": {
name: "Pomocí příkazové řádky"
}
}
const typst_header = `#import "template/template.typ": *
#show: tultemplate2.with(
@@ -204,21 +236,38 @@ const typst_header = `#import "template/template.typ": *
document: "{thesis_type.type}",
lang: "{language.lang}",
title: (cs: "{thesis_title.cs}", en: "{thesis_title.en}"),
specialization: ({language.lang}: "SEM DOPLŇTE SPECIALIZACI"),
<other_details.has_keywords: keywords: (
cs: ("DOPLŇTE", "SEM", "KLÍČOVÁ", "SLOVA"),
en: ("INSERT", "KEYWORDS", "HERE")
),
><other_details.has_acknowledgement: acknowledgement: (
<language.is_cs:cs: "
Rád bych poděkoval všem, kteří přispěli ke vzniku tohoto dílka.
"><language.is_en:en: "
I would like to acknowledge everyone who contributed to the creation of this fine piece of work.
">
),
> abstract: (
cs: "
Sem vyplňte abstrakt své práce v češtině.
",
en: "
Insert the abstract of your theses in English here.
"
),
author: "{author_info.name}",
author_pronouns: "{author_info.pronouns}",
<collaborators.has_supervisor: supervisor: "{collaborators.supervisor_name}",
><collaborators.has_consultant: consultant: "{collaborators.consultant_name}",
><programme.has_programme: programme: "{programme.programme}",
><programme.has_programme: programme: ({language.lang}: "{programme.programme}"),
><assignment.include_pdf: assignment: "assignment.pdf",
> citations: "citations.bib"
)
= Nadpis
skibidi
`;
function generate_template() {
function generate_template_header() {
let out = typst_header;
for(const step_key in steps) {
@@ -234,9 +283,12 @@ function generate_template() {
console.log("- " + key);
const search_condition = "<" + step_key + "." + key + ":";
const condition_pos = out.search(search_condition);
if(condition_pos >= 0) {
while(true) {
const condition_pos = out.search(search_condition);
if(condition_pos < 0) break;
const condition_end_pos = out.slice(condition_pos).search(">");
if(condition_end_pos >= 0) {
@@ -249,9 +301,12 @@ function generate_template() {
}
const search_replacement = "{" + step_key + "." + key + "}";
const replacement_pos = out.search(search_replacement);
if(replacement_pos >= 0) {
while(true) {
const replacement_pos = out.search(search_replacement);
if(replacement_pos < 0) break;
const head = out.slice(0, replacement_pos);
const meat = result[key];
const tail = out.slice(replacement_pos + search_replacement.length);
@@ -270,12 +325,25 @@ async function generate_zip() {
let assets_zip = await fetch("template.zip");
let out_zip = await new JSZip().loadAsync(await assets_zip.blob());
out_zip.file("thesis.typ", generate_template());
let template = await out_zip.file(steps.thesis_type.result.type + ".typ").async("string");
template = generate_template_header() + template;
out_zip.forEach((path, _) => {
if(path.match(/^[a-z_]*\.typ$/)) {
out_zip.remove(path)
}
});
out_zip.file("thesis.typ", template);
if(!steps.assignment.result.include_pdf) {
out_zip.remove("assignment.pdf");
}
if(!steps.toolchain.result.include_makefile) {
out_zip.remove("Makefile");
}
return await out_zip.generateAsync({ type: "blob" });
}

47
ui.js
View File

@@ -178,6 +178,43 @@ async function assignment_layout(content, result) {
}
}
async function other_details_layout(content, result) {
content.appendChild(new BinaryInputBuilder(result, "has_keywords")
.label("Vložit klíčová slova")
.finish());
content.appendChild(new BinaryInputBuilder(result, "has_acknowledgement")
.label("Vložit poděkování")
.finish());
content.appendChild(new ElementBuilder("div.vertical-spacer").finish());
content.appendChild(new ElementBuilder("div.hint")
.text("Generátor pouze vygeneruje ukázky, jak by tato pole měla vypadat. Samotná klíčová slova či poděkování si poté upravíte dle svých potřeb.")
.finish());
}
async function toolchain_layout(content, result) {
if(!Object.keys(toolchains).includes(result.toolchain)) {
document.querySelector("#next-button").disabled = true;
}
let buttons = new ButtonListBuilder(Object.keys(toolchains))
.should_be_pressed((key) => result.toolchain == key)
.modify((b, key) => b.class("wide").text(toolchains[key].name))
.on_click((key) => {
result.toolchain = key;
document.querySelector("#next-button").disabled = false;
})
.finish();
for(const button of buttons) {
content.appendChild(button);
}
content.appendChild(new ElementBuilder("div.vertical-spacer").finish());
content.appendChild(new ElementBuilder("div.hint")
.text("Toto rozhodnutí pouze ovlivní, zda výsledná šablona bude obsahovat soubor Makefile pro jednodušší použití s příkazovou řádkou. Webový editor Typstu tento soubor nepotřebuje.")
.finish());
}
async function run() {
startbutton.style.cursor = "auto";
startbutton.disabled = true;
@@ -219,14 +256,20 @@ async function run() {
let steps_len = Object.keys(steps).length;
while(id < steps_len) {
let step = get_step(id);
if(step.condition && !step.condition()) {
if(animation > 0) id++;
if(animation < 0) id--;
continue;
}
back_button.style.display = (id != 0) ? "" : "none";
next_button.innerText = (id < steps_len - 1) ? "Další →" : "Dokončit";
next_button.disabled = false;
container.innerHTML = "";
let step = get_step(id);
let title = new ElementBuilder("h1")
.html(step.title)
.finish();

View File

@@ -235,11 +235,13 @@ class BinaryInputBuilder {
let input = new ElementBuilder("input#" + this.key)
.type("checkbox")
.checked(this.result[this.key])
.if(this.update_handler !== null, b => b.on_click(e => {
.on_click(e => {
console.log(e.target.checked);
this.result[this.key] = e.target.checked;
this.update_handler(e.target.checked);
}))
if(this.update_handler !== null) {
this.update_handler(e.target.checked);
}
})
.finish();
let bundle = new ElementBuilder("div.horizontal-list")