summary refs log tree commit diff stats
path: root/java
diff options
context:
space:
mode:
authorSudipto Mallick <smlckz@termux-alpine>2024-01-12 10:13:01 +0000
committerSudipto Mallick <smlckz@termux-alpine>2024-01-12 10:13:01 +0000
commitac7aba2bacaaf74a91e218ee537fe3bf267b8e4d (patch)
treeffa6a98fa31b9031b918d448a6cb7744ad66122d /java
parent87554cf575a4a92f00908a7cccfe6c92db2ef3ef (diff)
downloadzadania-ac7aba2bacaaf74a91e218ee537fe3bf267b8e4d.tar.gz
Initial implementation of complete assignment
This is the initial implementation of the generation of complete document of the assignments.

java/buildall: Generates a Typst document from the list of assignments
in `alist.txt` (needs to updated to work with `state.sql` in future).
java/prelude.typ: Contains the prelude code responsible for generating
the table of contents, using the facilities provided by Typst.
java/template.typ: Updated so that it can be used with `prelude.typ` for
generating the table of contents.
.gitignore: To ignore `all.typ`, which is a build artifact.
Diffstat (limited to 'java')
-rw-r--r--java/buildall6
-rw-r--r--java/prelude.typ38
-rw-r--r--java/template.typ17
3 files changed, 54 insertions, 7 deletions
diff --git a/java/buildall b/java/buildall
index 7cdd0c0..4468d35 100644
--- a/java/buildall
+++ b/java/buildall
@@ -1,4 +1,4 @@
 #!/bin/sh
-
-awk '$3 == "#" { printf("#include(\"text/%s.typ\")\n", $2) }' alist.txt > all.typ
-typst compile --root $PWD all.typ a/all.pdf
+cat prelude.typ > all.typ
+awk '$2 == "#" { printf("#include(\"text/%s.typ\")\n", $1) }' alist.txt >> all.typ
+typst compile --root $PWD all.typ docs/all.pdf
diff --git a/java/prelude.typ b/java/prelude.typ
new file mode 100644
index 0000000..027bfef
--- /dev/null
+++ b/java/prelude.typ
@@ -0,0 +1,38 @@
+#import "@preview/tablex:0.0.7": tablex, cellx
+#import "/template.typ": *
+
+#apply(page-numbering: "(i)" , [
+  #align(center, [== Contents])
+  #let heading-format(content) = cellx(align: center + horizon, content)
+  #let col-aligns = (right, auto, center + horizon, center + horizon, auto)
+  #let preprocess-alist(l, lpno) = {
+    let i = 0
+    let e = l.len() - 1
+    let nl = ()
+    while i < e {
+      let it = l.at(i)
+      i = i + 1
+      let nit = l.at(i)
+      it.at(2) = [ #it.at(2) - #{nit.at(2) - 1} ]
+      it.push([])
+      nl.push(it)
+    }
+    l.at(e).at(2) = [ #{l.at(e).at(2)} - #lpno ]
+    l.at(e).push([])
+    nl.push(l.at(e))
+    nl
+  }
+  #list-of-assignments((l, lpno) =>
+    tablex(
+      columns: (3em, 1fr, 4em, 8em, 10em),
+      stroke: 1pt + gray,
+      map-cols: (i, cells) => (cells.first(), ..cells.slice(1).map(cell => (..cell, align: col-aligns.at(i)))),
+      heading-format[*Sl.* \ *No.*], heading-format[*Description*], heading-format[*Page No.*], heading-format[*Date*], heading-format[*Teacher’s* \ *Signature*],
+      ..preprocess-alist(l, lpno).flatten(),
+    ))
+])
+
+#colbreak()
+
+#counter(page).update(0)
+
diff --git a/java/template.typ b/java/template.typ
index 47a97a1..57e2e48 100644
--- a/java/template.typ
+++ b/java/template.typ
@@ -31,13 +31,13 @@
 }
 
 /* Draws page border around the provided content, taking an optional function to be called at the footer. */
-#let apply-page-borders(body, ..font-options, footer-special-func: none) = {
+#let apply-page-borders(body, ..font-options, footer-special-func: none, page-numbering: none) = {
   let page-margin = (left: 0.75in, right: 0.25in, top: 0.25in, bottom: 0.25in)
   let margin = (left: 0.65in, right: 0.15in, top: 1.5em, bottom: 1.5em)
   let page-border-thickness = 1.25pt
   set page(
     margin: (..page-margin, bottom: margin.bottom + 2em),
-    numbering: "1",
+    numbering: if page-numbering != none { page-numbering } else { "1" },
     background: align(top + start, pad(..margin, rect(width: 100%, height: 100%, stroke: page-border-thickness + gray, radius: 5pt))),
     footer: locate(loc => {
       align(center, move(dy: -margin.bottom + 1em, text(..font-options, size: 9pt, counter(page).display(loc.page-numbering()))))
@@ -50,7 +50,7 @@
   body
 }
 
-#let apply(body) = {
+#let apply(body, page-numbering: none) = {
   let body-font-settings = (font: "Nunito Sans 10pt", size: 12pt, stretch: 75%)
 //  let body-font-settings = (font: "Hanken Grotesk", size: 12pt, stretch: 75%)
   set text(..body-font-settings)
@@ -74,7 +74,7 @@
   show raw.where(block: true): it => align(left, it)
   set list(marker: ([$square.filled.tiny$], [--]))
   set par(leading: 0.5em)
-  apply-page-borders(body, ..body-font-settings, footer-special-func: signature-footer)
+  apply-page-borders(body, ..body-font-settings, footer-special-func: signature-footer, page-numbering: page-numbering)
 }
 
 #let scos(name) = {
@@ -86,9 +86,18 @@
   include ofname
 }
 
+#let alist = state("assignment-list", ())
+
+#let list-of-assignments(cb) = locate(loc => {
+  let l = alist.final(loc)
+  let lpno = counter(page).final(loc).first()
+  cb(l, lpno)
+})
+
 #let assignment(number, description) = align(center, [
 = #text(weight: 600, [Assignment #number])
 == #text(weight: 500, [Program statement:]) #text(weight: 400, description)
+#locate(loc => alist.update(lst => (..lst, (number, description, counter(page).at(loc).first(), []))))
 ])
 
 #let skind(kind) = [
f='#n360'>360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642