-
Notifications
You must be signed in to change notification settings - Fork 8
Change exercise type selection and allow for more flexible info box layout #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
03a9058
0f52ba9
565dc22
ca2f569
b87fd05
117d0a2
37c4b3b
9dd687b
d99accd
0c9d7a6
1c38ac5
b3e370d
5dc3ab3
057fdab
a03f941
661d9a1
ae3d9ef
240e0e3
3360f8f
2d1c1c3
6a336ad
2ca5a67
fcbe5eb
fdda054
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,90 @@ | ||
| #import "common/format.typ": format-date | ||
| #import "locales.typ": * | ||
|
|
||
| #let resolve-title-sub(title-sub, info, dict) = if type(title-sub) == content { | ||
| title-sub | ||
| } else if type(title-sub) == function { | ||
| title-sub(info, dict) | ||
| } else { | ||
| panic("title-sub has unsupported type. Expected content, function or none. Got " + type(title-sub)) | ||
| /// Creates the subline content. If `info-layout` is a dict, the subline gets filled following | ||
| /// the order specified by the keys in the `info-layout` dict. If a key is present in the | ||
| /// `info` but not in `info-layout`, it does not show up in the subline. | ||
| /// | ||
| /// - exercise-type (string): The type of exercise specified | ||
| /// - info (dict): The info dict containing all relevant data for the subline | ||
| /// - info-layout (dict, boolean): A dict specifying the layout of the subline. If `false` | ||
| /// the value of `#info.custom-subline` gets returned as content | ||
| /// - dict (dict): A language dict to translate standard/pre-defined strings. | ||
| /// -> Returns content filling the subline of the title | ||
| #let resolve-info-layout(exercise-type, info, info-layout, dict) = { | ||
| if info-layout == none { | ||
| if "custom-subline" in info { | ||
| return [#info.custom-subline] | ||
| } | ||
| return none | ||
| } | ||
| let title_keys = ("title", "subtitle", "author") | ||
| let default_keys_exercise = ("term", "date", "sheet") | ||
| let default_keys_submission = ("group", "tutor", "lecturer") | ||
| let default_keys = if exercise-type == "exercise" { | ||
| default_keys_exercise | ||
| } else { | ||
| default_keys_exercise + default_keys_submission | ||
| } | ||
|
|
||
| // filter out standard title keys | ||
| for key in title_keys { | ||
| _ = info.remove(key) | ||
| } | ||
|
|
||
| // Check if info actually contains any items | ||
| if info.len() == 0 { | ||
| return none | ||
| } | ||
|
|
||
| /// Checks if `filter-key` is present in `info-dict` and appends it to `target-list` | ||
| /// if that is the case. Also format the value of key `date` to match the locale. | ||
| let sort-info-to-list(target-list, info-dict, filter-key) = { | ||
| for (info-key, info-value) in info-dict.pairs() { | ||
| if info-key in default_keys { | ||
| if info-key == filter-key { | ||
| if info-key == "date" { | ||
| target-list.push([#format-date(info-value, dict.locale)]) | ||
| } else { | ||
| target-list.push([#dict.at(info-key) #info-value]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hence the dict now doesn't contain the separator anymore it would need to be added here. |
||
| } | ||
| } | ||
| } // This case makes sure the default submission keys don't get mistaken for custom keys | ||
| // I.e. we don't want submission keys ("group", "tutor", "lecturer") showing up, if | ||
| // exercise-type isn't "submission"! | ||
| else if info-key not in default_keys_submission { | ||
| if info-key == filter-key { | ||
| target-list.push([#info-value]) | ||
| } | ||
| } | ||
| } | ||
| return target-list | ||
| } | ||
|
Comment on lines
+42
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The entire function could maybe be changed s.t. instead of constantly appending a single element to a list, it rather takes in an array of all the keys and then returns an array with the corresponding content.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #let sort-info-to-list(wanted, info-dict) = {
return wanted
.filter(key => key in info-dict and (key in default_keys or not key in default_keys_submission))
.map(key => if key == "date" {
format-date(info-dict.at(key), dict.locale)
} else {
[#dict.at(key, default: key) #info-dict.at(key)]
})
}This could do the trick |
||
|
|
||
|
|
||
| let left-items = () | ||
| let right-items = () | ||
| assert( | ||
| exercise-type in ("exercise", "submission"), | ||
| message: "Exercise template only supports types 'exercise' and 'submission'", | ||
| ) | ||
| // Handle layouting, right first then default the rest to left | ||
| if "right" in info-layout { | ||
| for layout-key in info-layout.at("right") { | ||
| right-items = sort-info-to-list(right-items, info, layout-key) | ||
| } | ||
| } | ||
| if "left" in info-layout { | ||
| for layout-key in info-layout.at("left") { | ||
| left-items = sort-info-to-list(left-items, info, layout-key) | ||
| } | ||
| } | ||
|
|
||
| grid( | ||
| columns: (1fr, 1fr), | ||
| align: (alignment.left, alignment.right), | ||
| left-items.join(linebreak()), right-items.join(linebreak()), | ||
| ) | ||
| } | ||
|
|
||
| #let tuda-make-title( | ||
|
|
@@ -18,8 +97,9 @@ | |
| logo_element, | ||
| logo_height, | ||
| info, | ||
| title-sub, | ||
| dict | ||
| info-layout, | ||
| exercise-type, | ||
| dict, | ||
| ) = { | ||
| let text_on_accent_color = if colorback { | ||
| on_accent_color | ||
|
|
@@ -28,7 +108,7 @@ | |
| } | ||
|
|
||
| let text_inset = if colorback { | ||
| (x:3mm) | ||
| (x: 3mm) | ||
| } else { | ||
| (:) | ||
| } | ||
|
|
@@ -46,7 +126,7 @@ | |
| set text(fill: text_on_accent_color) | ||
|
|
||
| box( | ||
| fill: if colorback {accent_color}, | ||
| fill: if colorback { accent_color }, | ||
| width: 100%, | ||
| outset: 0pt, | ||
| { | ||
|
|
@@ -55,9 +135,10 @@ | |
| v(logo_height / 2) | ||
| grid( | ||
| columns: (1fr, auto), | ||
| box(inset: (y:3mm),{ | ||
| box(inset: (y: 3mm), { | ||
| set text(font: "Roboto", weight: "bold", size: 12pt) | ||
| grid(row-gutter: 1em, | ||
| grid( | ||
| row-gutter: 1em, | ||
| inset: text_inset, | ||
| if "title" in info { | ||
| text(info.title, size: 20pt) | ||
|
|
@@ -69,44 +150,44 @@ | |
| if type(info.author) == array { | ||
| for author in info.author { | ||
| if type(author) == array { | ||
| [#author.at(0) | ||
| [#author.at(0) | ||
| #text(weight: "regular", size: 0.8em)[(Mat.: #author.at(1))]] | ||
| linebreak() | ||
| } else { | ||
| author | ||
| linebreak() | ||
| author | ||
| linebreak() | ||
| } | ||
| } | ||
| } else { | ||
| info.author | ||
| } | ||
| } | ||
| }, | ||
| ) | ||
|
|
||
| v(.5em) | ||
| } | ||
| ), | ||
| { | ||
| }), | ||
| { | ||
| if logo_element != none { | ||
| move( | ||
| dx: 6mm, | ||
| { | ||
| set image(height: logo_height) | ||
| logo_element | ||
| } | ||
| }, | ||
| ) | ||
| } | ||
| } | ||
| }, | ||
| ) | ||
| v(6pt) | ||
| line(length: 100%, stroke: stroke) | ||
| if title-sub != none { | ||
| let subline-content = resolve-info-layout(exercise-type, info, info-layout, dict) | ||
| if subline-content != none { | ||
| block( | ||
| inset: text_inset, | ||
| resolve-title-sub(title-sub, info, dict) | ||
| subline-content, | ||
| ) | ||
| line(length: 100%, stroke: stroke) | ||
| } | ||
| } | ||
| }, | ||
| ) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this function is quite complex, I would add a bit of documentation. The original submission function had very good documentation.