view_component 3.11.0 → 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 +322 -2
- 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/component_generator.rb +15 -3
- 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 +54 -59
- data/lib/view_component/collection.rb +18 -3
- data/lib/view_component/compiler.rb +164 -240
- data/lib/view_component/config.rb +39 -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/slot.rb +11 -1
- data/lib/view_component/slotable.rb +29 -15
- 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,13 +0,0 @@
|
|
1
|
-
Description:
|
2
|
-
============
|
3
|
-
Creates a new component and test.
|
4
|
-
Pass the component name, either CamelCased or under_scored, and an optional list of attributes as arguments.
|
5
|
-
|
6
|
-
Example:
|
7
|
-
========
|
8
|
-
bin/rails generate component Profile name age
|
9
|
-
|
10
|
-
creates a Profile component and test:
|
11
|
-
Component: app/components/profile_component.rb
|
12
|
-
Template: app/components/profile_component.html.erb
|
13
|
-
Test: test/components/profile_component_test.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
---
|
2
|
-
layout: default
|
3
|
-
title: API reference
|
4
|
-
nav_order: 3
|
5
|
-
---
|
6
|
-
|
7
|
-
<!-- Warning: AUTO-GENERATED file, don't edit. Add code comments to your Ruby instead <3 -->
|
8
|
-
|
9
|
-
# API
|
10
|
-
|
11
|
-
<% @sections.each do |section| %>
|
12
|
-
## <%= section.heading %>
|
13
|
-
|
14
|
-
<% section.methods.each do |method| %>
|
15
|
-
### <%== render ViewComponent::DocsBuilderComponent::MethodDoc.new(method, section.show_types) %>
|
16
|
-
|
17
|
-
<% end %>
|
18
|
-
<% section.error_klasses.each do |error_klass| %>
|
19
|
-
### <%== render ViewComponent::DocsBuilderComponent::ErrorKlassDoc.new(error_klass, section.show_types) %>
|
20
|
-
|
21
|
-
<% end %>
|
22
|
-
<% end %>
|
@@ -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
|