render-document.typ 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // ==========================================
  2. // APPLICATION: СБОРКА ДОКУМЕНТА
  3. // ==========================================
  4. #import "../domain/document.typ": document-context, render-options, validate-profile-contract
  5. #import "../domain/company.typ": validate-company
  6. #import "../domain/parties.typ": validate-parties
  7. #import "../domain/attachments.typ": attachment-set, validate-attachment-set
  8. #import "../domain/references.typ": validate-bibliographies
  9. #import "../infrastructure/company-assets.typ": load-company
  10. #let resolve-company(value) = {
  11. if type(value) == str {
  12. validate-company(load-company(value))
  13. } else {
  14. validate-company(value)
  15. }
  16. }
  17. #let render-document(
  18. body,
  19. company,
  20. profile,
  21. options: (:),
  22. ) = {
  23. let company = resolve-company(company)
  24. let profile = validate-profile-contract(profile)
  25. let normalized = (profile.normalize)(profile.metadata)
  26. let validated = (profile.validate)(normalized)
  27. let metadata = if validated == none { normalized } else { validated }
  28. let parties = validate-parties(metadata.at("parties", default: ()))
  29. let attachments = validate-attachment-set(
  30. metadata.at("attachments", default: attachment-set()),
  31. )
  32. let bibliographies = validate-bibliographies(metadata.at("bibliographies", default: ()))
  33. let ctx = document-context(
  34. company,
  35. profile,
  36. metadata,
  37. render-options(options: options),
  38. parties: parties,
  39. attachments: attachments,
  40. bibliographies: bibliographies,
  41. )
  42. (profile.render)(body, ctx)
  43. }