implement generation of assignment

This commit is contained in:
2025-10-16 22:20:26 +02:00
parent dd6ecb5c9b
commit f33129f809
5 changed files with 135 additions and 41 deletions

View File

@@ -1,4 +1,4 @@
#import "utils.typ": assert_type_signature, is_none, map_none, deref
#import "utils.typ": assert_type_signature, is_none, map_none, deref, assert_dict_has
#let arguments_structure = (
document: (
@@ -25,12 +25,19 @@
keywords: "dictionary[string : array[string]] | none",
),
acknowledgement: "dictionary[string : string | content] | none",
assignment: "string | none",
assignment: "dictionary[string : any] | content | string | none",
citations: "string",
);
#let assignment_structure = (
personal_number: "string",
department: "string",
academical_year: "string",
content: "content",
);
#let check_arguments(args) = {
#let check_arguments(args, structure: arguments_structure, namespace: none) = {
let check_arguments_dict(structure, args, argument_path) = {
for (key, value) in structure.pairs() {
argument_path.push(str(key).replace("_", " "));
@@ -52,7 +59,7 @@
}
}
check_arguments_dict(arguments_structure, args, ());
check_arguments_dict(structure, args, if is_none(namespace) { () } else { (namespace,) });
}
#let get_arg_single(args, path) = {
@@ -122,6 +129,14 @@
}
}
#let assignment_info(assignment) = {
if type(assignment) == dictionary {
assert_dict_has(assignment_structure.keys(), assignment, "assignment");
check_arguments(assignment, structure: assignment_structure, namespace: "assignment");
}
assignment
}
#let arguments(
document_info,
title_pages,
@@ -141,7 +156,7 @@
project: project_info,
abstract: abstract_info,
acknowledgement: acknowledgement,
assignment: assignment,
assignment: assignment_info(assignment),
citations: citations,
)
}

View File

@@ -31,7 +31,13 @@
args, "acknowledgement", (v) => assert_dict_has((language,), v, "acknowledgement content")
);
args.assignment = map_arg(args, "assignment", (v) => "../../" + v);
args.assignment = map_arg(args, "assignment", (v) => {
if type(v) == str {
"../../" + v
} else {
v
}
});
args.citations = map_arg(args, "citations", (v) => "../../" + v);
args.title_pages = map_arg(args, "title_pages", (v) => "../../" + v);

View File

@@ -135,19 +135,21 @@
}
}
#let info(
#let info_base(
faculty_id,
language,
document_type,
title, author, supervisor, consultant, study_programme, study_specialization, year_of_study,
display_document_type,
title,
info_fields,
show_city: true,
) = {
let info_name_value_padding = 5em;
let info_name_min_width = 10em;
let gutter = .7em;
// document type
if document_type != "other" {
text(get_lang_item(language, document_type), weight: "bold", font: base_font);
if display_document_type != "other" and display_document_type != "other_asgn" {
text(get_lang_item(language, display_document_type), weight: "bold", font: base_font);
v(0em);
}
@@ -158,16 +160,6 @@
);
v(0em);
// other info
// [field_name, field_value, bold]
let info_fields = (
("author", author, true),
("supervisor", person_info(supervisor, "supervisor"), false),
("consultant", person_info(consultant, "consultant"), false),
("study_programme", study_programme, false),
("study_specialization", study_specialization, false),
("year_of_study", map_none(year_of_study, (v) => str(v) + "."), false),
)
context {
let max_field_name_width = calc.max(..info_fields.map((v) => {
if type(v.at(1)) == type(none) {
@@ -191,10 +183,43 @@
);
v(1em);
h(max_field_name_width + info_name_value_padding + gutter);
text(get_lang_item(language, "city") + " " + str(datetime.today().year()), font: base_font);
if show_city {
text(get_lang_item(language, "city") + " " + str(datetime.today().year()), font: base_font);
}
}
}
#let info_mainpage(
faculty_id,
language,
document_type,
title, author, supervisor, consultant, study_programme, study_specialization, year_of_study,
) = {
info_base(faculty_id, language, document_type, title, (
("author", author, true),
("supervisor", person_info(supervisor, "supervisor"), false),
("consultant", person_info(consultant, "consultant"), false),
("study_programme", study_programme, false),
("study_specialization", study_specialization, false),
("year_of_study", map_none(year_of_study, (v) => str(v) + "."), false),
));
}
#let info_assignment(
faculty_id,
language,
document_type,
title, author, personal_number, study_programme, department, academical_year,
) = {
info_base(faculty_id, language, document_type + "_asgn", title, (
("names", author, true),
("personal_number", personal_number, false),
("study_programme", study_programme, false),
("assigning_department", department, false),
("academical_year", academical_year, false),
), show_city: false);
}
// MAINPAGE
#let mainpage(args) = {
@@ -213,23 +238,42 @@
"author.specialization",
"author.year_of_study",
));
page({
if has_all_none((
document_type, title, author, supervisor, consultant, study_programme,
)) {
place(center + horizon, align(left, faculty_logotype(faculty_id, language)));
} else {
header(faculty, language);
align({
info(
faculty, language, document_type, map_none(title, (v) => v.at(language)),
author, supervisor, consultant, map_none(study_programme, (v) => v.at(language)),
map_none(study_specialization, (v) => v.at(language)), year_of_study,
);
v(5em);
}, bottom);
}
}, margin: 2cm);
set text(font: base_font);
set page(margin: 2cm);
pagebreak(weak: true);
if has_all_none((
document_type, title, author, supervisor, consultant, study_programme,
)) {
place(center + horizon, align(left, faculty_logotype(faculty_id, language)));
} else {
header(faculty, language);
align({
info_mainpage(
faculty, language, document_type, map_none(title, (v) => v.at(language)),
author, supervisor, consultant, map_none(study_programme, (v) => v.at(language)),
map_none(study_specialization, (v) => v.at(language)), year_of_study,
);
v(5em);
}, bottom);
}
}
#let assignmentpage(args, language, document_type, faculty, title, author, programme, content) = {
let (personal_number, department, academical_year) = req_arg(args, (
"personal_number", "department", "academical_year",
));
set text(font: base_font);
set page(margin: 2cm);
pagebreak(weak: true);
header(faculty, language);
info_assignment(
faculty, language, document_type, title.at(language), author, personal_number,
programme.at(language), department, academical_year,
);
show heading: it => {
block(it, above: 1em, below: 1em);
}
content;
}
// _ EMBEDDED
@@ -257,7 +301,21 @@
);
return;
}
pdfembed(req_arg(args, "assignment"))
let assignment = req_arg(args, "assignment");
if type(assignment) == str {
pdfembed(req_arg(args, "assignment"));
} else if type(assignment) == content {
req_arg(args, "assignment");
} else if type(assignment) == dictionary {
assignmentpage(
assignment,
..req_arg(args, (
"document.language", "document.type", "document.faculty", "title", "author.name",
"author.programme",
)),
req_arg(assignment, "content"),
);
}
}
// EXTERNAL TITLE PAGES

View File

@@ -7,9 +7,15 @@
"study_programme": "Studijní program",
"study_specialization": "Specializace",
"year_of_study": "Ročník",
"names": "Jméno a příjmení",
"assigning_department": "Zadávající katedra",
"personal_number": "Osobní číslo",
"academical_year": "Akademický rok",
"bp": "Bakalářská práce",
"bp_asgn": "Zadání bakalářské práce",
"dp": "Diplomová práce",
"dp_asgn": "Zadání diplomové práce",
"city": "Liberec",
@@ -75,9 +81,15 @@
"study_programme": "Study programme",
"study_specialization": "Specialization",
"year_of_study": "Year of study",
"names": "Name",
"assigning_department": "Assigning department",
"personal_number": "Personal number",
"academical_year": "Academical year",
"bp": "Bachelor thesis",
"bp_asgn": "Bachelor thesis assignment",
"dp": "Diploma thesis",
"dp_asgn": "Diploma thesis assignment",
"city": "Liberec",

View File

@@ -34,6 +34,7 @@
// - consultant (str): The name of the document's consultant.
// - programme (dictionary): Study programme.
// - specialization (disctionary): Study specialization
// - year_of_study (int): Year of study
// - abstract (dictionary): The abstract.
// - keywords (dictionary): The abstract keywords.
// - assignment (str): Filepath of the assignment document/page.
@@ -107,6 +108,8 @@
title: none, author: none,
author_pronouns: none, supervisor: none, consultant: none, programme: none,
specialization: none, year_of_study: none,
assignment: none,
) = {
import "arguments.typ": (
arguments,
@@ -125,7 +128,7 @@
project_info(supervisor, consultant),
abstract_info(none, none),
none,
none,
assignment,
"",
);
check_arguments(args);