MishkaCmsCore. Runtime. Resources. Changes. BlankTemplateStartsEmpty
(Mishka CMS Core v0.0.1)
Copy Markdown
View Source
Lets a document be created without any markup, by giving a blank one the empty starter container.
Add it to a create action, before the validations that demand a template:
create :create do
change MishkaCmsCore.Runtime.Resources.Changes.BlankTemplateStartsEmpty
validate present([:template])
...
endA layout wraps a page, so it takes the starter that already has @inner_content in it:
change {MishkaCmsCore.Runtime.Resources.Changes.BlankTemplateStartsEmpty, starter: :layout}Why a change and not a relaxed attribute
template is NOT NULL in Postgres with a length(template) >= 3 check and a no_empty_strings
constraint. Making the column nullable to allow an empty page would weaken a guarantee every other
reader of that column relies on — including the runtime compiler, which has no meaningful answer
for nil. Filling the blank instead keeps the column's promise exactly as it was and moves the
choice to where it belongs: what an empty page means.
It means one centred container. MishkaCmsCore.Runtime.PageBuilder.PageStarter.blank/0 owns that
answer so the form, the API and the seeds all create the same empty page.
Why it runs everywhere, not just in the form
A page created through JSON:API or a seed with no template used to be a validation error. There is no reason it should be: the visual editor opens an empty document perfectly well, and the author who left the field alone plainly meant "I will build it there". Putting the default in the action rather than in the form is what makes that true for every caller.
Whitespace counts as blank. A template of " " was already refused by the actions' own
emptiness check; now it is simply treated as "none given".