Report definition registry and pure helper functions.
Provides the defreport macro for declaring report definitions as data,
an in-process registry backed by an atom, and pure transformation helpers
used by shell adapters.
FC/IS rule: no I/O here. All side effects (file writing, HTTP responses, calling :data-source) live in the shell layer.
Report definition registry and pure helper functions. Provides the `defreport` macro for declaring report definitions as data, an in-process registry backed by an atom, and pure transformation helpers used by shell adapters. FC/IS rule: no I/O here. All side effects (file writing, HTTP responses, calling :data-source) live in the shell layer.
(build-sections-hiccup sections data)Build Hiccup from a vector of SectionDef maps and the report data.
Supports section types: :header - renders :content Hiccup as-is inside a [:header ...] :table - renders :columns + data as a table :footer - renders :content Hiccup as-is inside a [:footer ...] :spacer - renders an empty [:div.spacer ...]
Returns: [:html [:head ...] [:body ...]]
Build Hiccup from a vector of SectionDef maps and the report data. Supports section types: :header - renders :content Hiccup as-is inside a [:header ...] :table - renders :columns + data as a table :footer - renders :content Hiccup as-is inside a [:footer ...] :spacer - renders an empty [:div.spacer ...] Returns: [:html [:head ...] [:body ...]]
(build-table-rows columns data)Build a Hiccup [:tbody ...] from a collection of data records and column defs.
Each record becomes a [:tr ...] with one [:td ...] per column. Applies :align as an inline style when present.
Returns: [:tbody [:tr [:td ...] ...] ...]
Build a Hiccup [:tbody ...] from a collection of data records and column defs. Each record becomes a [:tr ...] with one [:td ...] per column. Applies :align as an inline style when present. Returns: [:tbody [:tr [:td ...] ...] ...]
(clear-registry!)Reset the registry to an empty map.
Use in tests to avoid inter-test pollution.
Reset the registry to an empty map. Use in tests to avoid inter-test pollution.
(defreport sym definition-map)Define and register a report.
The body is a map literal that must satisfy ReportDefinition schema.
After macro expansion the definition is automatically registered in the
in-process registry so it is available via get-report.
Example (PDF with template fn):
(defreport invoice-report {:id :invoice-report :type :pdf :page-size :a4 :filename "invoice.pdf" :template (fn [data] [:html [:body [:h1 "Invoice #" (:invoice-number data)] [:p "Total: " (:total data)]]])})
Example (Excel with declarative sections):
(defreport sales-report {:id :sales-report :type :excel :filename "sales.xlsx" :sections [{:type :table :columns [{:key :name :label "Product"} {:key :qty :label "Qty" :format :number} {:key :price :label "Price" :format :currency}]}]})
The var invoice-report is bound to the definition map.
The report is registered under :invoice-report.
Define and register a report.
The body is a map literal that must satisfy ReportDefinition schema.
After macro expansion the definition is automatically registered in the
in-process registry so it is available via `get-report`.
Example (PDF with template fn):
(defreport invoice-report
{:id :invoice-report
:type :pdf
:page-size :a4
:filename "invoice.pdf"
:template (fn [data]
[:html
[:body
[:h1 "Invoice #" (:invoice-number data)]
[:p "Total: " (:total data)]]])})
Example (Excel with declarative sections):
(defreport sales-report
{:id :sales-report
:type :excel
:filename "sales.xlsx"
:sections [{:type :table
:columns [{:key :name :label "Product"}
{:key :qty :label "Qty" :format :number}
{:key :price :label "Price" :format :currency}]}]})
The var `invoice-report` is bound to the definition map.
The report is registered under :invoice-report.(format-cell value format-type)Format a single cell value according to format-type.
Supported format-types: :date - converts java.util.Date / java.time.Instant / LocalDate to ISO string :number - coerces to double, falls back to "" on nil :currency - formats as EUR with thousands separator, e.g. "€ 1.234,56" :string - calls str on value (default) nil - treated as :string
Returns a string or number suitable for use in Hiccup or POI cells.
Format a single cell value according to format-type. Supported format-types: :date - converts java.util.Date / java.time.Instant / LocalDate to ISO string :number - coerces to double, falls back to "" on nil :currency - formats as EUR with thousands separator, e.g. "€ 1.234,56" :string - calls str on value (default) nil - treated as :string Returns a string or number suitable for use in Hiccup or POI cells.
(get-report id)Look up a report definition by id.
Returns the definition map or nil if not found.
Look up a report definition by id. Returns the definition map or nil if not found.
(list-reports)Return a vector of all registered report ids.
Return a vector of all registered report ids.
(map-columns columns record)Map a single data record through a vector of ColumnDef maps.
Returns a vector of formatted values in column order.
Example: (map-columns [{:key :name :label "Name"} {:key :price :label "Price" :format :currency}] {:name "Widget" :price 9.99}) ;=> ["Widget" "€ 9,99"]
Map a single data record through a vector of ColumnDef maps.
Returns a vector of formatted values in column order.
Example:
(map-columns [{:key :name :label "Name"} {:key :price :label "Price" :format :currency}]
{:name "Widget" :price 9.99})
;=> ["Widget" "€ 9,99"](prepare-report report-def)Validate a report definition and return {:definition ... :errors ...}.
Pure — does NOT call :data-source or generate bytes. Returns: {:definition report-def :valid? true :errors []} {:definition report-def :valid? false :errors [...malli-errors...]}
Validate a report definition and return {:definition ... :errors ...}.
Pure — does NOT call :data-source or generate bytes.
Returns:
{:definition report-def :valid? true :errors []}
{:definition report-def :valid? false :errors [...malli-errors...]}(register-report! definition)Register a report definition in the in-process registry.
Args: definition - ReportDefinition map
Returns the definition map.
Register a report definition in the in-process registry. Args: definition - ReportDefinition map Returns the definition map.
(resolve-data report-def opts)Call the :data-source fn with opts, returning the result. Returns nil if no :data-source is defined.
NOTE: This is a side-effecting call (queries DB, calls API, etc.). It lives here as a named helper so shell code can call it explicitly and tests can stub the :data-source fn.
Call the :data-source fn with opts, returning the result. Returns nil if no :data-source is defined. NOTE: This is a side-effecting call (queries DB, calls API, etc.). It lives here as a named helper so shell code can call it explicitly and tests can stub the :data-source fn.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |