Export mushaf layout data as JSON per page (#257)#620
Merged
naveed-ahmad merged 1 commit intoMay 30, 2026
Conversation
Adds a JSON export for mushaf layouts so the layout can be consumed directly without setting up a server to read it from the database. ExportMushafLayout#export_json writes one <page_number>.json file per page (plus info.json with mushaf metadata) into a dedicated json/ directory, reusing the same line/alignment logic as the SQLite export. Each line carries its type (ayah/surah_name/basmallah), alignment, and for ayah lines the word text (resolved via the mushaf's script using Mushaf#text_type_method) along with the first/last word index range. Wires the export into the mushaf-layout download pipeline alongside the existing SQLite and DOCX downloads. Closes TarteelAI#257
Contributor
|
JAK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a JSON export format for mushaf layouts. Previously a layout could only be downloaded as SQLite (or DOCX); the JSON wiring existed but was commented out. This implements
ExportMushafLayout#export_jsonand enables it in the download pipeline.It writes one
<page_number>.jsonfile per page plus aninfo.jsonwith mushaf metadata, into a dedicatedjson/directory (so it doesn't collide with the DOCXpages/output). The per-page logic reuses the exact same line/alignment helpers as the existing SQLite export (prepare_page_lines,get_line_alignment), so the two stay consistent.Per-page structure:
{ "page": 2, "lines": { "1": { "type": "surah_name", "alignment": "centered", "surah_number": 2 }, "2": { "type": "ayah", "alignment": "justified", "first_word_id": 5, "last_word_id": 12, "data": ["ٱلٓمٓ", "ذَٰلِكَ", "ٱلۡكِتَٰبُ"] } } }info.json:{ "name": "...", "number_of_pages": 604, "lines_per_page": 15, "font_name": "..." }Word text for
datais resolved via the layout's script usingMushaf#text_type_method— the same mechanismMushafLayoutJobalready uses — so glyph-based mushafs (v1/v2) emit their glyph codes and text-based mushafs emit the appropriate script text.Note: I kept the line
typevocabulary (ayah/surah_name/basmallah) consistent with the existing SQLite export rather than the slightly different names sketched in the issue, so both downloads describe lines the same way. Happy to adjust the key names/structure if maintainers prefer.Related Issue
Closes #257
Motivation and Context
The issue asks for per-page JSON so developers can integrate layout data directly without standing up a server to query the database. The export already supported SQLite/DOCX and had a commented-out JSON hook; this fills it in.
How Has This Been Tested?
ruby -cpasses on both changed files.export_page_jsonmirrors the already-in-productionexport_page(SQLite) logic line-for-line, and word-text resolution reuses the establishedword.send(mushaf.text_type_method)pattern fromMushafLayoutJob.export_mushaf_layoutsfor a sample layout to eyeball the generated JSON would be a valuable confirmation.Screenshots (if appropriate):
N/A — backend export change.