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 forkedextract_variables/1returning%{text: [...], image: [...]}. Filled via PhoenixKitMediaBrowserselector in the create-document modal. Per-variable config (default_width_px,separator,max_count) editable via theVariableConfigFormcomponent (read-only in v1; admin persistence is a follow-up). Substitution is a two-pass batchUpdate: text-first viareplaceAllText, then images viadocuments.get+DeleteContentRange+InsertInlineImage.find_image_tag_ranges/2correctly handles multi-byte (UTF-16) prefix text via codepoint counting. Variable.extract_string_variables/1andVariable.extract_image_variables/1— public leaf detectors;extract_variables/1now returns%{text: [...], image: [...]}(breaking change within this module’s public API).Variablestruct gains aconfigfield:%{default_width_px: 400}for:image, plusseparatorandmax_countfor:image_list. Stored in the existingvariablesjsonb column.GoogleDocsClient.substitute_images/2— walksdocuments.getcontent, finds every image tag occurrence by UTF-16 code unit offset, then issues a singlebatchUpdatewithDeleteContentRange+InsertInlineImageper occurrence. Handles both single and list cases; inserts are ordered from last to first occurrence to preserve indices.Errorsatoms::image_not_found,:image_url_not_public,:image_insert_failed,:image_tag_not_found.- Admin fill form:
:imagevariables render a “Choose image” button;:image_listvariables render “Choose images” (multi-select). Sequential media picks accumulate viapicking_existingURL param so earlier selections are not lost when returning from theMediaBrowser. - Persistence for image-variable
configedits:Documents.update_template_variable_config/3writes per-variable config (default_width_px,separator,max_count) back tophoenix_kit_doc_templates.variablesjsonb onphx-changefrom the modal form. Per-template scope, broadcasted viabroadcast_files_changed/0.VariableConfigFormis now rendered insideCreateDocumentModalfor:imageand:image_listvariables.
Changed
Documents.detect_variables/1now returns{:ok, %{text: [...], image: [...]}}— callers that expected a flat list must be updated.Documents.create_document_from_template/3orchestrates two orderedbatchUpdatepasses: 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.scanreturns 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 ofstartIndexunits to the Drive document. Errors: dropped two unemitted atoms (:image_too_large,:missing_required_value) plus theirmessage/1clauses — 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-HTMLPhoenix.HTML.raw/1interpolation with HEEx<option>tags so gettext-resolved labels go through automatic escaping.DocumentsLive: media-picker round-trip JSON now uses the built-inJSONmodule (Elixir 1.18+) instead ofJason, 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) requiresPHOENIX_KIT_DOC_CREATOR_DEV_OAUTHand a real dev Google account to run. - The image-variable regex
~r/\{\{\s*(image|images)\s*:\s*(\w+)\s*\}\}/is intentionally duplicated betweenVariableandGoogleDocsClient— 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.