Skip to content

Export mushaf layout data as JSON per page (#257)#620

Merged
naveed-ahmad merged 1 commit into
TarteelAI:mainfrom
hammadxcm:feat/mushaf-layout-json-export
May 30, 2026
Merged

Export mushaf layout data as JSON per page (#257)#620
naveed-ahmad merged 1 commit into
TarteelAI:mainfrom
hammadxcm:feat/mushaf-layout-json-export

Conversation

@hammadxcm

Copy link
Copy Markdown
Contributor

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_json and enables it in the download pipeline.

It writes one <page_number>.json file per page plus an info.json with mushaf metadata, into a dedicated json/ directory (so it doesn't collide with the DOCX pages/ 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 data is resolved via the layout's script using Mushaf#text_type_method — the same mechanism MushafLayoutJob already 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 type vocabulary (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 -c passes on both changed files.
  • RuboCop (Layout/Lint) reports no new offenses in the added code.
  • The new export_page_json mirrors the already-in-production export_page (SQLite) logic line-for-line, and word-text resolution reuses the established word.send(mushaf.text_type_method) pattern from MushafLayoutJob.
  • I was not able to run the exporter end-to-end against a seeded database in my environment, so a maintainer running export_mushaf_layouts for a sample layout to eyeball the generated JSON would be a valuable confirmation.

Screenshots (if appropriate):

N/A — backend export change.

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
@naveed-ahmad

Copy link
Copy Markdown
Contributor

JAK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export mushaf layout data in JSON format for each page

2 participants