feat(page): DocsUI::Endpoint + FieldTable/ErrorTable — the endpoint-reference kit#30
Merged
Merged
Conversation
…eference kit
## Summary
The gem had zero API-documentation vocabulary, so every consuming API page
hand-rolled a method+path badge, a fields table, and an error table with
drifting per-page row helpers. This adds three thin, composable pieces plus a
Section extension so documenting an endpoint's reference material is declarative
and renders identically across every site.
- `DocsUI::Endpoint.new(method, path)` — verb badge (GET→success, POST→primary,
PATCH/PUT→warning, DELETE→error via a frozen Hash of LITERAL class strings the
CSS scan sees; unknown verb → neutral badge, no raise) + monospace path,
rendered inline so it drops into a Section description or a run of prose.
- `Section#description` now also accepts a Phlex component instance (matched
before the callable branch, since a component also responds to #call). The
existing String/proc forms are untouched.
- `DocsUI::FieldTable` / `DocsUI::ErrorTable` — keyword-schema presets over Table.
FieldTable: Name (code) / Type / Required (✓ or canonical em-dash —) /
Description. ErrorTable: Scenario / Status / Type (code) / Param (code); the
Param column is auto-hidden when no row names a param.
Descriptions honour Table's cell convention, so `[:md, …]` renders inline
Markdown today.
## Test Coverage
- spec/docs_ui/endpoint_spec.rb — badge class per verb, path monospace, upcasing,
unknown verb → neutral (no raise), inline rendering, HTML escaping.
- spec/docs_ui/field_table_spec.rb — name code-styled, required tick vs canonical
em-dash, [:md, …] description, composition over Table, escaping.
- spec/docs_ui/error_table_spec.rb — type code-styled, Param column present iff
any row has a param (td-count asserted), composition, escaping.
- spec/docs_ui/section_spec.rb — a Phlex component instance description renders in
place; existing String/proc specs untouched (backwards compatible).
## Verification
- [x] bundle exec rspec — 187 examples, 0 failures (92% line coverage)
- [x] bundle exec rubocop — no offenses
- [x] bun run build:css — badge-success/primary/warning/error/neutral all present
in the compiled CSS (the literal frozen-Hash classes were scanned)
Closes #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #14. Part of #8 (Phase 2).
Problem
The gem had zero API-documentation vocabulary. Every API page in a consuming site repeated the same shape by hand — an HTTP-method badge + path, a parameters table, and an error table — with per-page row helpers (
err_row,field_row,scope_row,event_row) redefined across files with drifting arities and inconsistent "no value" placeholders ("-"vs"—").What this adds
Three thin, composable pieces plus a
Sectionextension. Documenting an endpoint's reference material is now declarative and renders identically across every site.1.
DocsUI::Endpoint.new(method, path)A method badge + monospace path, rendered inline so it drops straight into a
Sectiondescription or a run of prose.GET→badge-success,POST→badge-primary,PATCH/PUT→badge-warning,DELETE→badge-error.2.
Section#descriptionaccepts a Phlex componentA component instance is matched before the callable branch (a Phlex component also responds to
#call, so order matters). The existing String and proc forms are untouched — covered by unchanged passing specs.3.
DocsUI::FieldTable+DocsUI::ErrorTableKeyword-schema presets over
Table:FieldTable.new(fields)— each{ name:, type:, required: false, description: }→ Name (code-styled) / Type / Required (✓or the canonical em-dash—) / Description.ErrorTable.new(errors)— each{ scenario:, status:, type:, param: nil }→ Scenario / Status / Type (code) / Param (code). The Param column is auto-hidden when no row names a param.Descriptions honour
Table's cell convention, so[:md, "…"]renders inline Markdown today.Test plan
endpoint_spec.rbfield_table_spec.rb[:md, …]description; composition overTable; escapingerror_table_spec.rb<td>count); composition; escapingsection_spec.rbVerification
bundle exec rspec— 187 examples, 0 failures (92% line coverage)bundle exec rubocop— no offensescd docs && bun run build:css—badge-success/badge-primary/badge-warning/badge-error/badge-neutralall present in the compiled CSS, proving the scan caught the literal frozen-Hash classesSectiondescription forms are covered by untouched passing specsDogfood
The components reference page (
docs/) gains an "Endpoint, FieldTable & ErrorTable" section rendering a realisticPOST /api/webhook_endpointsexample live, and the README component table lists all three.Out of scope (per the issue)