Background
The tapas-xq endpoint POST /tapas-xq/derive-reader/:type transforms a TEI file into an XHTML snippet (a <div>) for display in the TAPAS reading interface. This is the core reader functionality and is not yet implemented in Rails.
Work required
app/services/tapas_xq/derive_reader_service.rb
Create with:
- Constructor:
view_package_type:, tei_content:, extra_params: {}, client: nil
#derive — POSTs to /derive-reader/#{view_package_type} with { file: tei_content }.merge(extra_params), returns the XHTML string
Error handling:
TapasXq::InvalidTeiError (422) — raised by client.rb when tapas-xq rejects the TEI file
TapasXq::InvalidResponseError — raised on 400 (unknown view package type); callers should validate the type against the ViewPackage table before calling
- Other
TapasXq::Error subclasses propagate normally
The extra_params argument supports view-package-specific parameters (each package may define additional form parameters in its configuration file).
Controller / job integration (to be designed)
The derive-reader call is stateless — tapas-xq does not store anything. It can be called:
- On demand per request (acceptable for small files, but may be slow)
- As a background job with result cached on
CoreFile (e.g., a reader_xhtml column) and invalidated on TEI update
The integration point (controller action, background job, or caching strategy) is left to the implementer to decide based on performance requirements.
Dependencies
Tests
See spec/services/tapas_xq/derive_reader_service_spec.rb in the testing plan doc.
Background
The tapas-xq endpoint
POST /tapas-xq/derive-reader/:typetransforms a TEI file into an XHTML snippet (a<div>) for display in the TAPAS reading interface. This is the core reader functionality and is not yet implemented in Rails.Work required
app/services/tapas_xq/derive_reader_service.rbCreate with:
view_package_type:,tei_content:,extra_params: {},client: nil#derive— POSTs to/derive-reader/#{view_package_type}with{ file: tei_content }.merge(extra_params), returns the XHTML stringError handling:
TapasXq::InvalidTeiError(422) — raised byclient.rbwhen tapas-xq rejects the TEI fileTapasXq::InvalidResponseError— raised on 400 (unknown view package type); callers should validate the type against theViewPackagetable before callingTapasXq::Errorsubclasses propagate normallyThe
extra_paramsargument supports view-package-specific parameters (each package may define additional form parameters in its configuration file).Controller / job integration (to be designed)
The derive-reader call is stateless — tapas-xq does not store anything. It can be called:
CoreFile(e.g., areader_xhtmlcolumn) and invalidated on TEI updateThe integration point (controller action, background job, or caching strategy) is left to the implementer to decide based on performance requirements.
Dependencies
TapasXq::ViewPackagesServicemust be implemented first so that validview_package_typevalues are knownInvalidTeiError) must be resolvedTests
See
spec/services/tapas_xq/derive_reader_service_spec.rbin the testing plan doc.