Skip to main content

Class: BibleTextService

Defined in: Services/BibleTextService.ts:120

Service for rendering Bible passages using templates.

This service accepts a TemplateView (template + engine selection) and passage data, then uses the specified template engine to render HTML output. Multiple template engines can be registered and selected per-render call.

Controllers should:

  1. Fetch verse data from repositories
  2. Enrich verses with context using BibleTextService.enrichVerse()
  3. Create a TemplateView with the desired engine and template
  4. Call renderPassage() with the TemplateView and passage data

Example

// Template engine implementations live in the platform package (e.g. @bible/desktop)
// import { LiquidTemplateEngine, HandlebarsTemplateEngine } from '@bible/desktop';

// Create template engines (provide your own ITemplateEngine implementations)
const engines = new Map<TemplateEngineType, ITemplateEngine>();
// engines.set(TemplateEngineType.Liquid, new LiquidTemplateEngine());
// engines.set(TemplateEngineType.Handlebars, new HandlebarsTemplateEngine());

const service = new BibleTextService(engines);

// Controller fetches data and enriches it
const verses = bibleRepo.getChapterVerses(43, 3); // John 3
const enrichedVerses = verses.map(v =>
BibleTextService.enrichVerse(v, "John", "Jn", "King James Version", "KJV")
);

// Prepare passage data
const passageData: PassageData = {
verses: enrichedVerses,
reference: "John 3:1-21",
startVerseId: enrichedVerses[0].verseId,
endVerseId: enrichedVerses[enrichedVerses.length - 1].verseId,
moduleName: "King James Version",
moduleAbbreviation: "KJV",
displayMode: "standard"
};

// Create template view (specify engine + template)
const templateView: TemplateView = {
engine: TemplateEngineType.Liquid,
template: standardTemplate
};

// Render using template view
const html = await service.renderPassage(templateView, passageData);

Constructors

Constructor

new BibleTextService(engines): BibleTextService

Defined in: Services/BibleTextService.ts:128

Creates a BibleTextService with a registry of template engines.

Parameters

engines

Map<TemplateEngineType, ITemplateEngine>

Map of template engine types to their implementations

Returns

BibleTextService

Methods

getRegisteredEngines()

getRegisteredEngines(): TemplateEngineType[]

Defined in: Services/BibleTextService.ts:284

Gets the list of registered template engine types.

Returns

TemplateEngineType[]

Array of registered engine types


hasEngine()

hasEngine(engineType): boolean

Defined in: Services/BibleTextService.ts:275

Checks if a template engine type is registered.

Parameters

engineType

TemplateEngineType

The template engine type to check

Returns

boolean

true if the engine is registered


renderPassage()

renderPassage(templateView, passageData): Promise<string>

Defined in: Services/BibleTextService.ts:140

Renders a Bible passage using the provided template view.

Parameters

templateView

TemplateView

The template view containing engine type and template string

passageData

PassageData

The passage data with enriched verse information

Returns

Promise<string>

A promise that resolves to the rendered HTML

Throws

Error if template engine not found or template rendering fails


validateTemplate()

validateTemplate(templateView): boolean

Defined in: Services/BibleTextService.ts:261

Validates that a template view is syntactically correct.

Parameters

templateView

TemplateView

The template view to validate

Returns

boolean

true if the template is valid and engine is registered


enrichVerse()

static enrichVerse(verse, bookName, bookAbbreviation, moduleName?, moduleAbbreviation?): EnrichedVerse

Defined in: Services/BibleTextService.ts:181

Creates enriched verse data from a BibleVerse model. This helper combines verse data with book/chapter context.

Parameters

verse

BibleVerse

The BibleVerse from the database

bookName

string

The full name of the book (e.g., "John")

bookAbbreviation

string

The abbreviation (e.g., "Jn")

moduleName?

string

The module name (e.g., "King James Version")

moduleAbbreviation?

string

The module abbreviation (e.g., "KJV")

Returns

EnrichedVerse

Enriched verse data ready for template rendering


formatReference()

static formatReference(bookName, startChapter, startVerse, endChapter?, endVerse?): string

Defined in: Services/BibleTextService.ts:234

Generates a standard reference string for a passage.

Parameters

bookName

string

The book name

startChapter

number

Starting chapter

startVerse

number

Starting verse

endChapter?

number

Ending chapter (optional, if different from start)

endVerse?

number

Ending verse (optional, for ranges)

Returns

string

A formatted reference string