Skip to content

WIP refactor: inject bible rendering styles into textBlocks#65

Draft
davidfedor wants to merge 2 commits into
mainfrom
codex/refactor-bibleversionrendering-to-use-instance-styles
Draft

WIP refactor: inject bible rendering styles into textBlocks#65
davidfedor wants to merge 2 commits into
mainfrom
codex/refactor-bibleversionrendering-to-use-instance-styles

Conversation

@davidfedor
Copy link
Copy Markdown
Member

Motivation

  • Make the rendering style behavior pluggable so different style interpreters can control how block classes and inline text attributes are interpreted instead of relying on a single static helper.
  • Minimize call-site changes by threading a style instance through the existing rendering entry points and keeping the current default behavior intact.

Description

  • Add a BibleVersionRenderingStyleInterpreting protocol and convert BibleVersionRenderingStyles to a concrete, instantiable public implementation with a public initializer.
  • Extend BibleVersionRendering.textBlocks(...) with a styles: any BibleVersionRenderingStyleInterpreting = BibleVersionRenderingStyles() parameter and thread it through generateTextBlocks(...) and StateIn.
  • Replace static calls to BibleVersionRenderingStyles.interpretBlockClasses and interpretTextAttr with instance calls via stateIn.styles.interpretBlockClasses(...) and stateIn.styles.interpretTextAttr(...) so alternate interpreters can be injected.

Testing

  • Ran swift test and the test suite completed successfully (all tests passed).
  • Ran SwiftLint with LINUX_SOURCEKIT_LIB_PATH=... swiftlint --strict and linting finished with no violations.

Codex Task

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@davidfedor
Copy link
Copy Markdown
Member Author

@greptileai please review

@davidfedor
Copy link
Copy Markdown
Member Author

@greptileai please review, really.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 13, 2026

Greptile Summary

This PR introduces a BibleVersionRenderingStyleInterpreting protocol and converts BibleVersionRenderingStyles into a concrete, injectable implementation, making the Bible rendering pipeline's style interpretation pluggable. The styles parameter is cleanly threaded from textBlocks(...) down through generateTextBlocks(...) and into StateIn, with a backward-compatible default. The overall approach is well-structured and minimizes call-site changes.

Key changes:

  • New public protocol BibleVersionRenderingStyleInterpreting with interpretBlockClasses and interpretTextAttr requirements, enabling alternate style interpreters to be injected.
  • BibleVersionRenderingStyles promoted to a public final class with public init() and instance methods replacing former static methods.
  • BibleVersionRendering.textBlocks(...) gains a styles: parameter defaulting to BibleVersionRenderingStyles() to preserve existing behavior.
  • StateIn carries the styles instance for use throughout the recursive node-walking functions.
  • One inconsistency: interpretTextAttr is declared with public inside the protocol body while interpretBlockClasses is not — both are redundantly public and the mismatch produces a Swift compiler warning.

Confidence Score: 4/5

  • This PR is safe to merge with one minor fix — remove the redundant public modifier from interpretTextAttr inside the protocol definition.
  • The refactor is focused and correct: the protocol abstraction is well-designed, the threading of styles through the call chain is complete, and backward compatibility is preserved via the default parameter. The only issue is a redundant/inconsistent public access modifier on one protocol requirement, which produces a Swift compiler warning but does not affect runtime behavior.
  • Sources/YouVersionPlatformUI/Views/Rendering/BibleVersionRenderingStyles.swift — fix the redundant public modifier on the interpretTextAttr protocol requirement.

Important Files Changed

Filename Overview
Sources/YouVersionPlatformUI/Views/Rendering/BibleVersionRenderingStyles.swift Converts BibleVersionRenderingStyles from a final class with static methods to a public final class with instance methods, and introduces the BibleVersionRenderingStyleInterpreting protocol. One minor issue: interpretTextAttr is redundantly annotated with public inside the protocol body, while interpretBlockClasses is not — this inconsistency generates a Swift compiler warning.
Sources/YouVersionPlatformUI/Views/Rendering/BibleVersionRendering.swift Correctly threads the new styles: any BibleVersionRenderingStyleInterpreting parameter through textBlocks, generateTextBlocks, and StateIn. Static dispatch to BibleVersionRenderingStyles is replaced with instance dispatch via stateIn.styles. Default value preserves backward compatibility.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant textBlocks
    participant generateTextBlocks
    participant StateIn
    participant styles as styles: BibleVersionRenderingStyleInterpreting
    participant handleNodeBlock
    participant handleBlockChild

    Caller->>textBlocks: textBlocks(reference, fonts, styles?)
    textBlocks->>generateTextBlocks: generateTextBlocks(..., styles)
    generateTextBlocks->>StateIn: StateIn(..., styles: styles)
    generateTextBlocks->>handleNodeBlock: handleNodeBlock(stateIn, ...)
    handleNodeBlock->>styles: stateIn.styles.interpretBlockClasses(classes, ...)
    handleNodeBlock->>handleBlockChild: handleBlockChild(stateIn, ...)
    handleBlockChild->>styles: stateIn.styles.interpretTextAttr(node, ...)
Loading

Last reviewed commit: 4c7834f

Comment on lines +16 to +21
public func interpretTextAttr(
_ node: BibleTextNode,
stateIn: BibleVersionRendering.StateIn,
stateDown: inout BibleVersionRendering.StateDown,
stateUp: inout BibleVersionRendering.StateUp
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant public modifier on protocol requirement

In Swift, protocol requirements inherit the access level of the enclosing protocol — you cannot (and should not) annotate individual requirements with an access modifier. Writing public func inside a public protocol generates a Swift compiler warning: "Redundant access modifier 'public', since the protocol is also declared 'public'".

More importantly, this declaration is inconsistent with interpretBlockClasses immediately above it, which has no access modifier. Both methods are effectively public since the protocol is public.

Suggested change
public func interpretTextAttr(
_ node: BibleTextNode,
stateIn: BibleVersionRendering.StateIn,
stateDown: inout BibleVersionRendering.StateDown,
stateUp: inout BibleVersionRendering.StateUp
)
func interpretTextAttr(
_ node: BibleTextNode,
stateIn: BibleVersionRendering.StateIn,
stateDown: inout BibleVersionRendering.StateDown,
stateUp: inout BibleVersionRendering.StateUp
)

@davidfedor davidfedor changed the title refactor: inject bible rendering styles into textBlocks WIP refactor: inject bible rendering styles into textBlocks May 4, 2026
@davidfedor davidfedor marked this pull request as draft May 8, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant