-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents_controller.rb
More file actions
54 lines (45 loc) · 1.56 KB
/
components_controller.rb
File metadata and controls
54 lines (45 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module Docs
class ComponentsController < ApplicationController
class Yard
def code_object(class_name)
::YARD::Registry.load!(yardoc_path) if ::YARD::Registry.all.empty?
::YARD::Registry.at(class_name)
end
def yardoc_path
Rails.root.join(".yardoc")
end
end
def show
@code_object = Yard.new.code_object(params[:id])
raise ActiveRecord::RecordNotFound if @code_object.nil?
@child_classes = @code_object.children.select { |c| c.is_a?(YARD::CodeObjects::ClassObject) }.sort_by(&:name)
@constructor = @code_object.meths.find { |meth| meth.name == :initialize }
@constructor_arguments = if @constructor
@constructor.tags(:param)
else
[]
end
@examples = @code_object.tags(:example)
@lookbook_embeds = @code_object.tags(:lookbook_embed)
@viewcomponent_slots = @code_object.tags(:viewcomponent_slot)
respond_to do |format|
format.html
format.md
end
end
private
helper_method def all_components
return @all_components if @all_components
flowbite = Yard.new.code_object("Flowbite")
child_classes = flowbite.children.select { |child|
child.type == :class && child.inheritance_tree.map(&:path).include?("ViewComponent::Base")
}
@all_components = child_classes.sort_by(&:name)
end
helper_method def rubydoc_url(code_object)
name = code_object.path
slug = name.gsub("::", "/")
"https://www.rubydoc.info/gems/flowbite-components/#{slug}.html"
end
end
end