Skip to content

Commit e5ed46a

Browse files
committed
Extract headline components
1 parent 9feb330 commit e5ed46a

File tree

6 files changed

+51
-12
lines changed

6 files changed

+51
-12
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Docs::Headline < ViewComponent::Base
2+
def call
3+
content_tag(tag, content, class: classes)
4+
end
5+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Docs::Headline::H1 < Docs::Headline
2+
def classes
3+
"mb-4 text-4xl tracking-tight font-bold text-gray-900 dark:text-white"
4+
end
5+
6+
def tag
7+
:h1
8+
end
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Docs::Headline::H2 < Docs::Headline
2+
def classes
3+
"mt-8 text-2xl font-bold"
4+
end
5+
6+
def tag
7+
:h2
8+
end
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Docs::Headline::H3 < Docs::Headline
2+
def classes
3+
"mt-4 text-xl font-bold"
4+
end
5+
6+
def tag
7+
:h3
8+
end
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Docs::Headline::H4 < Docs::Headline
2+
def classes
3+
"mt-4 text-md font-bold"
4+
end
5+
6+
def tag
7+
:h4
8+
end
9+
end

demo/app/views/docs/components/show.html.erb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</nav>
2727

2828
<main class="py-4 flex-1 space-y-8">
29-
<h1 class="mb-4 text-4xl tracking-tight font-bold text-gray-900 dark:text-white"><%= @code_object.path %></h1>
29+
<%= render(Docs::Headline::H1.new) { @code_object.path } %>
3030

3131
<section class="format dark:format-invert">
3232
<%= render_docstring(@code_object.docstring_introduction, code_object: @code_object) %>
@@ -45,20 +45,19 @@
4545
<% if @examples.any? %>
4646
<section>
4747
<%- @examples.each do |example| %>
48-
<h2 class="mt-8 text-2xl font-bold"><%= example.name %></h2>
48+
<%= render(Docs::Headline::H2.new) { example.name } %>
4949
<%= render(Docs::CodeExample.new) do %><%= example.text %><% end %>
5050
<% end %>
5151
</section>
5252
<% end %>
5353

5454
<% if @previews.any? %>
5555
<section>
56-
<h2 class="mt-8 text-2xl font-bold">Examples</h2>
56+
<%= render(Docs::Headline::H2.new) { "Examples" } %>
5757

5858
<% @previews.each do |scenario_group| %>
5959
<div class="mt-8">
60-
<h3 class="mt-4 text-xl font-bold"><%= scenario_group.label %></h3>
61-
60+
<%= render(Docs::Headline::H3.new) { scenario_group.label } %>
6261
<div class="my-4">
6362
<%= render_docstring(scenario_group.scenarios.map { |s| s.notes.presence }.compact.join("\n\n"), code_object: @code_object) %>
6463
</div>
@@ -68,7 +67,7 @@
6867
</section>
6968
<% end %>
7069

71-
<h2 class="mt-8 text-2xl font-bold">API reference</h2>
70+
<%= render(Docs::Headline::H2.new) { "API reference" } %>
7271

7372
<% if @code_object.type == :class && @code_object.parent && !@code_object.parent.root? %>
7473
<section>
@@ -81,7 +80,7 @@
8180

8281
<% if @child_classes.any? %>
8382
<section>
84-
<h3 class="mb-4 mt-8 text-xl font-bold">In namespace</h3>
83+
<%= render(Docs::Headline::H3.new) { "In namespace" } %>
8584
<ul class="list-disc list-inside space-y-2">
8685
<% @child_classes.each do |subclass| %>
8786
<li>
@@ -94,8 +93,7 @@
9493

9594
<% if @viewcomponent_slots.any? %>
9695
<section>
97-
<h3 class="mt-8 text-xl font-bold">Slots</h3>
98-
96+
<%= render(Docs::Headline::H3.new) { "Slots" } %>
9997
<table>
10098
<% @viewcomponent_slots.each do |slot_tag| %>
10199
<tr>
@@ -110,12 +108,12 @@
110108

111109
<% if @constructor %>
112110
<section>
113-
<h3 class="mb-4 mt-8 text-xl font-bold">Constructor</h3>
111+
<%= render(Docs::Headline::H3.new) { "Constructor" } %>
114112

115113
<code><%= @constructor.signature %></code>
116114

117115
<% if @constructor_arguments.any? %>
118-
<h4 class="mt-4 text-md font-bold">Parameters</h4>
116+
<%= render(Docs::Headline::H4.new) { "Parameters" } %>
119117
<table>
120118
<% @constructor_arguments.each do |param| %>
121119
<tr>
@@ -130,7 +128,7 @@
130128
<% end %>
131129

132130
<section>
133-
<h3 class="mb-4 mt-8 text-xl font-bold">See also</h3>
131+
<%= render(Docs::Headline::H3.new) { "See also" } %>
134132
<%= render(Flowbite::Link.new(href: rubydoc_url(@code_object), data: {turbo: false})) do %>
135133
Ruby API documentation for
136134
<code><%= @code_object.type %> <%= @code_object.path %></code>

0 commit comments

Comments
 (0)