view_component 3.12.1 → 3.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/concerns/view_component/preview_actions.rb +8 -1
- data/app/helpers/preview_helper.rb +1 -1
- data/app/views/view_components/_preview_source.html.erb +1 -1
- data/docs/CHANGELOG.md +299 -5
- data/lib/rails/generators/abstract_generator.rb +9 -1
- data/lib/rails/generators/component/component_generator.rb +2 -1
- data/lib/rails/generators/component/templates/component.rb.tt +3 -2
- data/lib/rails/generators/erb/component_generator.rb +1 -1
- data/lib/rails/generators/preview/templates/component_preview.rb.tt +2 -0
- data/lib/rails/generators/rspec/templates/component_spec.rb.tt +1 -1
- data/lib/rails/generators/stimulus/component_generator.rb +8 -3
- data/lib/rails/generators/stimulus/templates/component_controller.ts.tt +9 -0
- data/lib/rails/generators/test_unit/templates/component_test.rb.tt +1 -1
- data/lib/view_component/base.rb +52 -59
- data/lib/view_component/collection.rb +18 -3
- data/lib/view_component/compiler.rb +164 -240
- data/lib/view_component/config.rb +26 -2
- data/lib/view_component/configurable.rb +17 -0
- data/lib/view_component/engine.rb +21 -11
- data/lib/view_component/errors.rb +7 -5
- data/lib/view_component/instrumentation.rb +1 -1
- data/lib/view_component/preview.rb +1 -1
- data/lib/view_component/rails/tasks/view_component.rake +8 -2
- data/lib/view_component/slotable.rb +28 -14
- data/lib/view_component/slotable_default.rb +20 -0
- data/lib/view_component/template.rb +134 -0
- data/lib/view_component/test_helpers.rb +29 -2
- data/lib/view_component/use_helpers.rb +32 -10
- data/lib/view_component/version.rb +2 -2
- metadata +112 -19
- data/lib/rails/generators/component/USAGE +0 -13
- data/lib/view_component/docs_builder_component.html.erb +0 -22
- data/lib/view_component/docs_builder_component.rb +0 -96
- data/lib/yard/mattr_accessor_handler.rb +0 -19
@@ -1,96 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ViewComponent
|
4
|
-
class DocsBuilderComponent < Base
|
5
|
-
class Section < Struct.new(:heading, :methods, :error_klasses, :show_types, keyword_init: true)
|
6
|
-
def initialize(heading: nil, methods: [], error_klasses: [], show_types: true)
|
7
|
-
methods.sort_by! { |method| method[:name] }
|
8
|
-
error_klasses.sort!
|
9
|
-
super
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class ErrorKlassDoc < ViewComponent::Base
|
14
|
-
def initialize(error_klass, _show_types)
|
15
|
-
@error_klass = error_klass
|
16
|
-
end
|
17
|
-
|
18
|
-
def klass_name
|
19
|
-
@error_klass.gsub("ViewComponent::", "").gsub("::MESSAGE", "")
|
20
|
-
end
|
21
|
-
|
22
|
-
def error_message
|
23
|
-
ViewComponent.const_get(@error_klass)
|
24
|
-
end
|
25
|
-
|
26
|
-
def call
|
27
|
-
<<~DOCS.chomp
|
28
|
-
`#{klass_name}`
|
29
|
-
|
30
|
-
#{error_message}
|
31
|
-
DOCS
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class MethodDoc < ViewComponent::Base
|
36
|
-
def initialize(method, show_types = true)
|
37
|
-
@method = method
|
38
|
-
@show_types = show_types
|
39
|
-
end
|
40
|
-
|
41
|
-
def deprecated?
|
42
|
-
@method.tag(:deprecated).present?
|
43
|
-
end
|
44
|
-
|
45
|
-
def suffix
|
46
|
-
" (Deprecated)" if deprecated?
|
47
|
-
end
|
48
|
-
|
49
|
-
def types
|
50
|
-
" → [#{@method.tag(:return).types.join(",")}]" if @method.tag(:return)&.types && @show_types
|
51
|
-
end
|
52
|
-
|
53
|
-
def signature_or_name
|
54
|
-
@method.signature ? @method.signature.gsub("def ", "") : @method.name
|
55
|
-
end
|
56
|
-
|
57
|
-
def separator
|
58
|
-
@method.sep
|
59
|
-
end
|
60
|
-
|
61
|
-
def docstring
|
62
|
-
@method.docstring
|
63
|
-
end
|
64
|
-
|
65
|
-
def deprecation_text
|
66
|
-
@method.tag(:deprecated)&.text
|
67
|
-
end
|
68
|
-
|
69
|
-
def docstring_and_deprecation_text
|
70
|
-
<<~DOCS.strip
|
71
|
-
#{docstring}
|
72
|
-
|
73
|
-
#{"_#{deprecation_text}_" if deprecated?}
|
74
|
-
DOCS
|
75
|
-
end
|
76
|
-
|
77
|
-
def call
|
78
|
-
<<~DOCS.chomp
|
79
|
-
`#{separator}#{signature_or_name}`#{types}#{suffix}
|
80
|
-
|
81
|
-
#{docstring_and_deprecation_text}
|
82
|
-
DOCS
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# { heading: String, public_only: Boolean, show_types: Boolean}
|
87
|
-
def initialize(sections: [])
|
88
|
-
@sections = sections
|
89
|
-
end
|
90
|
-
|
91
|
-
# deprecation
|
92
|
-
# return
|
93
|
-
# only public methods
|
94
|
-
# sig with types or name
|
95
|
-
end
|
96
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module YARD
|
4
|
-
# YARD Handler to parse `mattr_accessor` calls.
|
5
|
-
class MattrAccessorHandler < YARD::Handlers::Ruby::Base
|
6
|
-
handles method_call(:mattr_accessor)
|
7
|
-
namespace_only
|
8
|
-
|
9
|
-
process do
|
10
|
-
name = statement.parameters.first.jump(:tstring_content, :ident).source
|
11
|
-
object = YARD::CodeObjects::MethodObject.new(namespace, name)
|
12
|
-
register(object)
|
13
|
-
parse_block(statement.last, owner: object)
|
14
|
-
|
15
|
-
object.dynamic = true
|
16
|
-
object[:mattr_accessor] = true
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|