# `MishkaCmsCore.Runtime.PageBuilder.Examples`
[🔗](https://github.com/mishka-group/mishka_cms_core/blob/v0.0.1/lib/mishka_cms_core/runtime/page_builder/examples.ex#L5)

The example list behind a component's Examples modal — curated out of the two sets a kit bundle
ships, which are not the same thing and were never reconciled.

## The two sets

`extra.examples` is the kit's own catalogue: one entry per option, generated from the component's
variants. It is exhaustive and it is dull — `<.component variant="base">Base</.component>` twelve
times over, with the content replaced by the name of the thing being demonstrated.

`extra.demo_examples` is every real usage on the kit's documentation site, with the surrounding
content intact: `"Here is a gentle confirmation that your action was successful."` rather than
`"Base"`. There are 3,084 of them across the bundle and, until this module, **nothing read them**.

## What curation means here

Three rules, in this order:

  1. **Prefer composed.** Where both sets demonstrate the same options, the documentation one wins:
     identical markup, real content. A preview whose body reads "Base" tells the author nothing
     about what the component looks like in a page.
  2. **Dedup by what an example SAYS.** Two entries setting the same attributes on the same
     component are one example however differently they are labelled — and the demo set repeats
     itself heavily, because a docs page shows the same alert under several headings.
  3. **Keep the base first.** The unmodified component is what someone opening the modal wants to
     see before any variant of it.

Every surviving example gets a stable `id` (so a selection survives a re-render), a `title` and a
`description` that says what it actually demonstrates — read off the attributes it sets rather
than copied from a label, because the labels upstream are frequently just the section name.

# `example`

```elixir
@type example() :: %{
  id: String.t(),
  title: String.t(),
  description: String.t(),
  source: String.t(),
  composed?: boolean(),
  base?: boolean(),
  section: String.t() | nil,
  requires: map()
}
```

# `count`

```elixir
@spec count(map()) :: non_neg_integer()
```

How many examples a component would offer — what the palette's badge counts.

# `for_component`

```elixir
@spec for_component(map()) :: [example()]
```

The curated example list for one component row (or palette entry).

Returns `[]` when the component ships none, which is what the modal's empty state is for.

# `for_name`

```elixir
@spec for_name(String.t(), String.t() | nil) :: [example()]
```

The curated examples of ONE component, read fresh from the database by name.

The palette deliberately carries no examples: curating all 183 components parses every example
each one ships and cost 7.8 seconds at editor open, to fill a modal that is opened for a single
component. Both readers of that modal — the panel and the preview iframe — come through here
instead, and only when the modal is opened.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
