Document Creator 0.4.0: Image placeholders that work, template categories and composing
Document Creator 0.4.0 makes image placeholders in templates insert their images, lets admins set how each image slot behaves, adds a category to templates, and gives host apps a way to build one document from several templates.
Images are inserted
Image placeholders ({{ image: name }} and {{ images: name }}) came in 0.3.0, but every image insert was rejected by Google Docs because the size was sent in a unit the API does not accept, so no image ever reached a document. Sizes are now sent in points, and images are inserted.
Image slot settings
When creating a document from a template, each image slot in the create-document window now shows its settings: Default width (px), and for image lists a Separator (New line, Space or None) and Max images (blank = unlimited). Changes are saved on the template, so the next document starts from them. A blank or invalid number is ignored instead of causing an error.
A category for templates
Each template card, in both the card and list views, gets a category picker: No category, Financial or Technical. Until a category is chosen it reads Set category. Changing it is recorded in the activity log, and other open admin pages update.
Composing documents from several templates
Host apps can now build one Google Doc from several template sections, each with its own variable values and images (Documents.create_composed_document/2). The same variable name in two sections is filled separately for each. The sections are stored with the document, so the recipe survives later template edits. Named presets save such a recipe for reuse. Both are for code in this release; there is no admin page for them yet.
Upgrading
The new columns and tables (the template category, document sections and template presets) come from PhoenixKit core’s migration V117: run mix phoenix_kit.update on a core that includes it. No configuration change.
Full release notes: Document Creator 0.4.0
0.4.0 · 13 May 2026
Added
- Document composition. Build a single Google Doc from N template sections, each with its own variable map and image config. Public API:
Documents.create_composed_document/2. Sections are persisted asDocumentSectionrows (template_uuid,position,variable_values,image_params) so the recipe survives template edits. Per-section variable substitution is range-scoped — identical{{name}}keys in different sections resolve independently (GoogleDocsClient.substitute_in_range/5). Whole flow is wrapped inEcto.Multiwith best-effort Google Doc cleanup on rollback. - Template presets. Named, reusable composition recipes scoped via
scope_type+scope_idand optionally categorized. New schemaTemplatePreset(jsonbsectionsarray). API:Documents.save_preset/1,list_presets/1,apply_preset/1,recipe_for/1.apply_preset/1returns{:ok, sections} | {:error, :not_found}and drops sections referencing deleted templates with a warning. - Template category. New
categorystring column onphoenix_kit_doc_templates(V117). Admin UI gains a popover category picker on each template card (cards + list views). API:Documents.update_template_category/3— emitstemplate.category_updatedactivity row and broadcasts:files_changed. Documents.image_slots_for_template/1— extracts{{ image: name }}/{{ images: name }}slot names + kinds from a template’s Google Doc text via the injectable docs client.Documents.update_template_variable_config/3— persists per-variableconfigedits (default_width_px,separator,max_count) intophoenix_kit_doc_templates.variablesjsonb. Coerces empty / non-integer form inputs to skip rather than crash onString.to_integer/1. Used by theVariableConfigForminsideCreateDocumentModalfor:imageand:image_listvariables (debounced 500ms onphx-change).ImagePickerLiveComponent — generic, parameterised by(scope_type, scope_id, mode, current_selection, files). Server-side pagination (page size 50) and name-substring filter. Host owns file resolution and receives{:image_picker_changed, picker_id, selection}messages.- Migration V117 —
categorycolumn on templates,phoenix_kit_doc_document_sections(unique on(document_uuid, position)),phoenix_kit_doc_template_presetstables. PhoenixKitDocumentCreator.Application— module-application registered viamix.exs :mod. Starts conditional Oban supervision when the host app supplies:phoenix_kit_document_creator, Obanconfig; otherwise an empty supervisor. Does not startPhoenixKit.Supervisor(the host app owns it).- Test scaffolding —
StubDocsClient+StubDocsClientHelpersfor call-order assertions without HTTP traffic;LiveCase.render_live/2+ComponentHostLivefor isolated LiveComponent testing.
Changed
Composer.compose/2returns{:error, {:unsupported_separator, sep}}for separators other than:page_break(MVP scope), instead of raisingArgumentError. Uniform tagged-tuple contract across the module andDocuments.create_composed_document/2.Documents.create_composed_document/2broadcasts:files_changedon success so connected admin LiveViews resync, matching every other mutation path in the context.mix.exs:compilers— extendsMix.compilers()([:phoenix_kit_css_sources] ++ Mix.compilers()) instead of replacing it. Fixes parent apps consuming this library as a path dep —.beamfiles were not being written, soDocuments.create_composed_document/2etc. appeared undefined.
Fixed
GoogleDocsClient.insertInlineImageUnit — switched fromEMUtoPT(1 px = 0.75 pt). The Docs API only acceptsPTorUNIT_UNSPECIFIED; the previousEMUmade every image-substitutionbatchUpdate400 withINVALID_ARGUMENT, so image-variable substitution never actually inserted anything in real usage.DocumentsLiveempty-render crash —render_category_picker/1was called as a plain function in HEEx and triedassign/3on a hand-built map, crashingArgumentErroron every render. Now matches the convention used byrender_language_picker/1just above it (callscategory_options()inline).Composermerge precedence — earlier section positions now win on key collision (Map.merge(vals, acc)rather than the reverse) so a section-0 value isn’t overwritten by a section-1 value during multi-section substitution.config/config.exsOban block gated onconfig_env() != :testso the library’s standalone test suite can boot. Host apps overriding the entire:phoenix_kit_document_creator, Obankeyword are unaffected.
Removed
createPositionedObjectfrom image inserts. Research against the Google Docs API reference confirmedcreatePositionedObjectis not a validbatchUpdaterequest type — positioned objects can only be created interactively in the editor UI. The path was never reachable from any caller (defaultz_indexis 0) so production traffic was unaffected.z_index > 0andopacity != 1.0now log a warning and fall back toinsertInlineImage.
Known limitations (deferred to follow-ups)
image_params.opacityandimage_params.z_indexare stored onDocumentSectionand accepted byImagePicker‘s config, but currently no-op at render time — the Google Docs API has no surface for image opacity, and positioned objects can’t be created viabatchUpdate. Stored for future activation if/when the API gains support.TemplatePreset.sectionsis an unschema’d{:array, :map}— typos in section descriptor keys are silent at save time and surface as “dropped section” warnings atapply_preset/1time. An embedded schema would tighten this.- Orphan-doc sweeper (
TODO(orphan-doc-sweeper)incomposer.ex) not yet implemented — when aMultirolls back after:google_docsucceeds, the best-effortdelete_document/1only logs on failure; no periodic reconciliation yet. - Standalone dev/prod Oban config in
config/config.exsstill references a non-existentPhoenixKitDocumentCreator.Repo. Harmless when this library runs as a dependency (host overrides), but should be either repaired or removed. - The PubSub topic
"document_creator:files"is not tenant-scoped. Fine for single-tenant hosts; a multi-tenant host should scope by tenant id.
Document Creator 0.4.0. Install or update: {:phoenix_kit_document_creator, "~> 0.4"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.