Skip to content

Document Creator 0.3.0: Image placeholders and Estonian and Russian translations

Document Creator 0.3.0 lets a Google Docs template hold image placeholders next to its text variables, filled from the PhoenixKit media library when a document is created. The module also ships its own translations for the first time.

Image placeholders

A template can now contain {{ image: name }} for one image and {{ images: name }} for an ordered list of images. The module detects them separately from text variables, so a placeholder like {{ image: logo }} is never mistaken for a text field.

When creating a document from such a template, the create-document window shows a Choose image button for a single image and Choose images for a list, both opening PhoenixKit’s media browser. A badge shows when an image is selected, or how many. Choosing more images one after another adds to the earlier picks instead of replacing them. Each image slot has a default width of 400 pixels, and a list can have a separator and a maximum number of images. When the document is created, the text variables are filled first, then the images.

Image placeholders are found at the right position even when Cyrillic text, other non-Latin text or emoji come before them.

Translations

The module’s admin pages now use their own translation files, in English, Estonian and Russian, instead of PhoenixKit’s shared ones. Page titles are set after the admin’s language is known, so they come out translated.

Upgrading

No migration. Code that calls Documents.detect_variables/1 or Variable.extract_variables/1 must be updated: both now return text and image variables separately (%{text: [...], image: [...]}) instead of a flat list.

Full release notes: Document Creator 0.3.0

0.3.0 · 11 May 2026

Added

  • Image placeholders in templates: {{ image: name }} for single images and {{ images: name }} for ordered lists. Variables detected via forked extract_variables/1 returning %{text: [...], image: [...]}. Filled via PhoenixKit MediaBrowser selector in the create-document modal. Per-variable config (default_width_px, separator, max_count) editable via the VariableConfigForm component (read-only in v1; admin persistence is a follow-up). Substitution is a two-pass batchUpdate: text-first via replaceAllText, then images via documents.get + DeleteContentRange + InsertInlineImage. find_image_tag_ranges/2 correctly handles multi-byte (UTF-16) prefix text via codepoint counting.
  • Variable.extract_string_variables/1 and Variable.extract_image_variables/1 — public leaf detectors; extract_variables/1 now returns %{text: [...], image: [...]} (breaking change within this module’s public API).
  • Variable struct gains a config field: %{default_width_px: 400} for :image, plus separator and max_count for :image_list. Stored in the existing variables jsonb column.
  • GoogleDocsClient.substitute_images/2 — walks documents.get content, finds every image tag occurrence by UTF-16 code unit offset, then issues a single batchUpdate with DeleteContentRange + InsertInlineImage per occurrence. Handles both single and list cases; inserts are ordered from last to first occurrence to preserve indices.
  • Errors atoms: :image_not_found, :image_url_not_public, :image_insert_failed, :image_tag_not_found.
  • Admin fill form: :image variables render a “Choose image” button; :image_list variables render “Choose images” (multi-select). Sequential media picks accumulate via picking_existing URL param so earlier selections are not lost when returning from the MediaBrowser.
  • Persistence for image-variable config edits: Documents.update_template_variable_config/3 writes per-variable config (default_width_px, separator, max_count) back to phoenix_kit_doc_templates.variables jsonb on phx-change from the modal form. Per-template scope, broadcasted via broadcast_files_changed/0. VariableConfigForm is now rendered inside CreateDocumentModal for :image and :image_list variables.

Changed

  • Documents.detect_variables/1 now returns {:ok, %{text: [...], image: [...]}} — callers that expected a flat list must be updated.
  • Documents.create_document_from_template/3 orchestrates two ordered batchUpdate passes: text substitution first, image substitution second.
  • Text-variable regex gains explicit negative-lookahead (?!images?\s*:) to encode the invariant that {{ image: x }} tags are never captured as text variables.

Fixed

  • UTF-16 code unit offset bug in match_to_range/4: Regex.scan returns byte offsets; arithmetic now converts the prefix-and-match bytes through :unicode.characters_to_binary(_, :utf8, :utf16) so both BMP characters (Cyrillic, Latin extended, common CJK) and supplementary-plane codepoints (emoji, rare CJK extensions) contribute the correct number of startIndex units to the Drive document.
  • Errors: dropped two unemitted atoms (:image_too_large, :missing_required_value) plus their message/1 clauses — neither was returned by any module and the gettext entries would have shown up as obsolete on the next extract.
  • VariableConfigForm.separator_options/1: replaced raw-HTML Phoenix.HTML.raw/1 interpolation with HEEx <option> tags so gettext-resolved labels go through automatic escaping.
  • DocumentsLive: media-picker round-trip JSON now uses the built-in JSON module (Elixir 1.18+) instead of Jason, matching the rest of the codebase.

Known limitations (deferred to follow-ups)

  • No telemetry / observability around the image batch operations.
  • E2E integration test (test/integration/image_substitution_integration_test.exs) requires PHOENIX_KIT_DOC_CREATOR_DEV_OAUTH and a real dev Google account to run.
  • The image-variable regex ~r/\{\{\s*(image|images)\s*:\s*(\w+)\s*\}\}/ is intentionally duplicated between Variable and GoogleDocsClient — each module owns its own parsing to avoid a shared dependency.

Document Creator 0.3.0. Install or update: {:phoenix_kit_document_creator, "~> 0.3"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.