forked from ViewComponent/view_component
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
158 lines (127 loc) · 3.75 KB
/
Rakefile
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rake/testtask"
require "yard"
require "yard/mattr_accessor_handler"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end
desc "Runs benchmarks against components"
task :benchmark do
ruby "./performance/benchmark.rb"
end
desc "Runs benchmarks against component content area/ slot implementations"
task :slotable_benchmark do
ruby "./performance/slotable_benchmark.rb"
end
task :translatable_benchmark do
ruby "./performance/translatable_benchmark.rb"
end
namespace :coverage do
task :report do
require "simplecov"
require "simplecov-console"
SimpleCov.minimum_coverage 100
SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"], "rails" do
formatter SimpleCov::Formatter::Console
end
end
end
namespace :docs do
# Build api.md documentation page from YARD comments.
task :build do
YARD::Rake::YardocTask.new
puts "Building YARD documentation."
Rake::Task["yard"].execute
puts "Converting YARD documentation to Markdown files."
registry = YARD::RegistryStore.new
registry.load!(".yardoc")
meths =
registry.
get("ViewComponent::Base").
meths.
select do |method|
!method.tag(:private) &&
method.path.include?("ViewComponent::Base") &&
method.visibility == :public
end.sort_by { |method| method[:name] }
instance_methods_to_document = meths.select { |method| method.scope != :class }
class_methods_to_document = meths.select { |method| method.scope == :class }
File.open("docs/api.md", "w") do |f|
f.puts("---")
f.puts("layout: default")
f.puts("title: API")
f.puts("---")
f.puts
f.puts("<!-- Warning: AUTO-GENERATED file, do not edit. Add code comments to your Ruby instead <3 -->")
f.puts
f.puts("# API")
f.puts
f.puts("## Class methods")
class_methods_to_document.each do |method|
suffix =
if method.tag(:deprecated)
" (Deprecated)"
end
types =
if method.tag(:return)&.types
" → [#{method.tag(:return).types.join(',')}]"
end
f.puts
f.puts("### #{method.sep}#{method.signature.gsub('def ', '')}#{types}#{suffix}")
f.puts
f.puts(method.docstring)
if method.tag(:deprecated)
f.puts
f.puts("_#{method.tag(:deprecated).text}_")
end
end
f.puts
f.puts("## Instance methods")
instance_methods_to_document.each do |method|
suffix =
if method.tag(:deprecated)
" (Deprecated)"
end
types =
if method.tag(:return)&.types
" → [#{method.tag(:return).types.join(',')}]"
end
f.puts
f.puts("### #{method.sep}#{method.signature.gsub('def ', '')}#{types}#{suffix}")
f.puts
f.puts(method.docstring)
if method.tag(:deprecated)
f.puts
f.puts("_#{method.tag(:deprecated).text}_")
end
end
f.puts
f.puts("## Configuration")
registry.
get("ViewComponent::Base").
meths.
select { |method| method[:mattr_accessor] }.
sort_by { |method| method[:name] }.
each do |method|
suffix =
if method.tag(:deprecated)
" (Deprecated)"
end
f.puts
f.puts("### #{method.sep}#{method.name}#{suffix}")
if method.docstring.length > 0
f.puts
f.puts(method.docstring)
end
if method.tag(:deprecated)
f.puts
f.puts("_#{method.tag(:deprecated).text}_")
end
end
end
end
end
task default: :test