MishkaCmsCore.Runtime.Resources.Validations.InterfaceDeclaration (Mishka CMS Core v0.0.1)

Copy Markdown View Source

Refuses a component whose declared attributes or slots could not compile.

Why this is on the resource and not in the editor

A component's attrs and slots reach the database from three places — the Components table's form, the builder's Interface tab, and any script or import that writes the columns — and the rule is the same everywhere: a name becomes an atom and is written into a def, so Size and my-size are not names, one name may not be declared twice, and Phoenix refuses required: true together with a default ("attributes should not have a default value if they are required").

Enforced in the editor alone, each of those surfaces would have needed its own copy, and the two that are not the editor would have had none. Here it is one answer at the action boundary, which is where MishkaCmsCore.Runtime.Resources.Validations.CodeChange and TemplateCompiles already sit for the same reason.

MishkaCmsCore.Runtime.PageBuilder.Interface.validate/2 holds the rules themselves, because the editor also wants them BEFORE a save — to mark the offending row while somebody is still typing in it. This is the half that makes them true of the record.

What it does not do

It says nothing about whether the template AGREES with the declaration. A component may legitimately be saved with an attribute its markup does not read yet, and a template that reads @size with no attr :size is advice the editor gives — see Interface.undeclared/3 — rather than a write to refuse. Half-finished work has to be storable.