Class: DocsUI::Endpoint

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
app/components/docs_ui/endpoint.rb

Overview

An HTTP endpoint reference line — a method badge followed by the path — in the kit's daisyUI look. This is the code(class: "badge …") lambda every API page was hand-rolling; compose it instead.

render DocsUI::Endpoint.new(:post, "/v1/messages")
# => POST /v1/messages   (POST as a primary badge, path monospace)

It renders INLINE (no block wrapper), so it drops straight into a Section description or a run of prose:

DocsUI::Section("Create a message", description: DocsUI::Endpoint.new(:post, "/v1/messages"))

The verb → badge-colour map is an explicit frozen Hash of LITERAL class strings so the Tailwind scan (which reads the gem's Ruby) sees every badge class and generates it. An unknown verb falls back to a neutral badge and never raises — a typo degrades gracefully rather than blowing up a render.

Constant Summary collapse

BADGE_CLASSES =

Each value is a single literal string (not interpolated) so Tailwind's source scan generates the colour. Keep these literal — see Critical Rule 6.

{
  "GET" => "badge badge-sm badge-success",
  "POST" => "badge badge-sm badge-primary",
  "PUT" => "badge badge-sm badge-warning",
  "PATCH" => "badge badge-sm badge-warning",
  "DELETE" => "badge badge-sm badge-error"
}.freeze
NEUTRAL_BADGE =
"badge badge-sm badge-neutral"

Instance Method Summary collapse

Constructor Details

#initialize(method, path) ⇒ Endpoint

Returns a new instance of Endpoint.



33
34
35
36
# File 'app/components/docs_ui/endpoint.rb', line 33

def initialize(method, path)
  @method = method.to_s.upcase
  @path = path
end

Instance Method Details

#view_templateObject



38
39
40
41
42
# File 'app/components/docs_ui/endpoint.rb', line 38

def view_template
  code(class: BADGE_CLASSES.fetch(@method, NEUTRAL_BADGE)) { plain @method }
  whitespace
  code { plain @path }
end