view_component 3.22.0 → 3.23.1
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/docs/CHANGELOG.md +37 -1
- data/lib/view_component/base.rb +7 -4
- data/lib/view_component/config.rb +1 -1
- data/lib/view_component/slotable.rb +1 -2
- data/lib/view_component/version.rb +2 -2
- metadata +7 -21
- data/lib/rails/generators/component/USAGE +0 -13
- data/lib/rails/generators/component/templates/component.rb.tt +0 -16
- data/lib/rails/generators/erb/templates/component.html.erb.tt +0 -1
- data/lib/rails/generators/haml/templates/component.html.haml.tt +0 -1
- data/lib/rails/generators/preview/templates/component_preview.rb.tt +0 -9
- data/lib/rails/generators/rspec/templates/component_spec.rb.tt +0 -15
- data/lib/rails/generators/slim/templates/component.html.slim.tt +0 -1
- data/lib/rails/generators/stimulus/templates/component_controller.js.tt +0 -7
- data/lib/rails/generators/stimulus/templates/component_controller.ts.tt +0 -9
- data/lib/rails/generators/tailwindcss/templates/component.html.erb.tt +0 -1
- data/lib/rails/generators/test_unit/templates/component_test.rb.tt +0 -12
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16a94da266921e0bd3ed59abdba704b4edf68873959d74c0d3caad66d3aac082
|
4
|
+
data.tar.gz: 0520dc669a3c0d1bda117d7a2f1932f6f2b31726a55e44be87062c49c004cd64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63ebe85255f6d35c49108590e6d939c1ea21971bfaa8bd476f5f5854073916692d602173e5f607db3aefbbc46cee3ef467232efb4c0231ca85a8c691b1a27ea5
|
7
|
+
data.tar.gz: 6e4cbef0047c2d3daf22f06b024bca4af0b12fdea8146f9bc1217bc27fa3d318049681b99f5e6030bf42017922fdb82ca0a1255b4aa367f43d793f9d4a0a8528
|
data/docs/CHANGELOG.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
layout: default
|
3
3
|
title: Changelog
|
4
|
-
nav_order:
|
4
|
+
nav_order: 6
|
5
5
|
---
|
6
6
|
|
7
7
|
<!-- Add unreleased changes under the "main" heading. -->
|
@@ -10,6 +10,42 @@ nav_order: 5
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 3.23.1
|
14
|
+
|
15
|
+
* Restore Rake tasks in published gem.
|
16
|
+
|
17
|
+
*Franz Liedke*
|
18
|
+
|
19
|
+
## 3.23.0
|
20
|
+
|
21
|
+
* Add docs about Slack channel in Ruby Central workspace. (Join us! #oss-view-component). Email joelhawksley@github.com for an invite.
|
22
|
+
|
23
|
+
*Joel Hawksley
|
24
|
+
|
25
|
+
* Do not include internal `DocsBuilderComponent` or `YARD::MattrAccessorHandler` in published gem.
|
26
|
+
|
27
|
+
*Joel Hawksley*
|
28
|
+
|
29
|
+
* Only lock to `concurrent-ruby` `1.3.4` for Rails 6.1.
|
30
|
+
|
31
|
+
*Joel Hawksley*
|
32
|
+
|
33
|
+
* Fix generation of ViewComponent documentation that was broken due to HTML safety issues.
|
34
|
+
|
35
|
+
*Simon Fish*
|
36
|
+
|
37
|
+
* Add documentation on how ViewComponent works.
|
38
|
+
|
39
|
+
*Joel Hawksley*
|
40
|
+
|
41
|
+
* Clarify that `config.use_deprecated_instrumentation_name` will be removed in v4.
|
42
|
+
|
43
|
+
*Joel Hawksley*
|
44
|
+
|
45
|
+
* Run RSpec tests in CI.
|
46
|
+
|
47
|
+
*Joel Hawksley*
|
48
|
+
|
13
49
|
## 3.22.0
|
14
50
|
|
15
51
|
* Rewrite `ViewComponents at GitHub` documentation as more general `Best practices`.
|
data/lib/view_component/base.rb
CHANGED
@@ -25,9 +25,10 @@ module ViewComponent
|
|
25
25
|
#
|
26
26
|
# @return [ActiveSupport::OrderedOptions]
|
27
27
|
def config
|
28
|
-
module_parents.each do |
|
29
|
-
|
30
|
-
|
28
|
+
module_parents.each do |module_parent|
|
29
|
+
next unless module_parent.respond_to?(:config)
|
30
|
+
module_parent_config = module_parent.config.try(:view_component)
|
31
|
+
return module_parent_config if module_parent_config
|
31
32
|
end
|
32
33
|
ViewComponent::Config.current
|
33
34
|
end
|
@@ -195,6 +196,8 @@ module ViewComponent
|
|
195
196
|
true
|
196
197
|
end
|
197
198
|
|
199
|
+
# Override the ActionView::Base initializer so that components
|
200
|
+
# do not need to define their own initializers.
|
198
201
|
# @private
|
199
202
|
def initialize(*)
|
200
203
|
end
|
@@ -251,7 +254,7 @@ module ViewComponent
|
|
251
254
|
raise e, <<~MESSAGE.chomp if view_context && e.is_a?(NameError) && helpers.respond_to?(method_name)
|
252
255
|
#{e.message}
|
253
256
|
|
254
|
-
You may be trying to call a method provided as a view helper. Did you mean `helpers.#{method_name}
|
257
|
+
You may be trying to call a method provided as a view helper. Did you mean `helpers.#{method_name}`?
|
255
258
|
MESSAGE
|
256
259
|
|
257
260
|
raise
|
@@ -123,7 +123,7 @@ module ViewComponent
|
|
123
123
|
# @return [Boolean]
|
124
124
|
# Whether ActiveSupport Notifications use the private name `"!render.view_component"`
|
125
125
|
# or are made more publicly available via `"render.view_component"`.
|
126
|
-
# Will
|
126
|
+
# Will be removed in next major version.
|
127
127
|
# Defaults to `true`.
|
128
128
|
|
129
129
|
# @!attribute render_monkey_patch_enabled
|
@@ -333,7 +333,6 @@ module ViewComponent
|
|
333
333
|
|
334
334
|
def raise_if_slot_registered(slot_name)
|
335
335
|
if registered_slots.key?(slot_name)
|
336
|
-
# TODO remove? This breaks overriding slots when slots are inherited
|
337
336
|
raise RedefinedSlotError.new(name, slot_name)
|
338
337
|
end
|
339
338
|
end
|
@@ -432,7 +431,7 @@ module ViewComponent
|
|
432
431
|
def set_polymorphic_slot(slot_name, poly_type = nil, *args, &block)
|
433
432
|
slot_definition = self.class.registered_slots[slot_name]
|
434
433
|
|
435
|
-
if !slot_definition[:collection] &&
|
434
|
+
if !slot_definition[:collection] && defined?(@__vc_set_slots) && @__vc_set_slots[slot_name]
|
436
435
|
raise ContentAlreadySetForPolymorphicSlotError.new(slot_name)
|
437
436
|
end
|
438
437
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.23.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ViewComponent Team
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|
@@ -47,16 +47,16 @@ dependencies:
|
|
47
47
|
name: concurrent-ruby
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
|
-
- -
|
50
|
+
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 1
|
52
|
+
version: '1'
|
53
53
|
type: :runtime
|
54
54
|
prerelease: false
|
55
55
|
version_requirements: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
|
-
- -
|
57
|
+
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1
|
59
|
+
version: '1'
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: allocation_stats
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
@@ -580,27 +580,16 @@ files:
|
|
580
580
|
- app/views/view_components/previews.html.erb
|
581
581
|
- docs/CHANGELOG.md
|
582
582
|
- lib/rails/generators/abstract_generator.rb
|
583
|
-
- lib/rails/generators/component/USAGE
|
584
583
|
- lib/rails/generators/component/component_generator.rb
|
585
|
-
- lib/rails/generators/component/templates/component.rb.tt
|
586
584
|
- lib/rails/generators/erb/component_generator.rb
|
587
|
-
- lib/rails/generators/erb/templates/component.html.erb.tt
|
588
585
|
- lib/rails/generators/haml/component_generator.rb
|
589
|
-
- lib/rails/generators/haml/templates/component.html.haml.tt
|
590
586
|
- lib/rails/generators/locale/component_generator.rb
|
591
587
|
- lib/rails/generators/preview/component_generator.rb
|
592
|
-
- lib/rails/generators/preview/templates/component_preview.rb.tt
|
593
588
|
- lib/rails/generators/rspec/component_generator.rb
|
594
|
-
- lib/rails/generators/rspec/templates/component_spec.rb.tt
|
595
589
|
- lib/rails/generators/slim/component_generator.rb
|
596
|
-
- lib/rails/generators/slim/templates/component.html.slim.tt
|
597
590
|
- lib/rails/generators/stimulus/component_generator.rb
|
598
|
-
- lib/rails/generators/stimulus/templates/component_controller.js.tt
|
599
|
-
- lib/rails/generators/stimulus/templates/component_controller.ts.tt
|
600
591
|
- lib/rails/generators/tailwindcss/component_generator.rb
|
601
|
-
- lib/rails/generators/tailwindcss/templates/component.html.erb.tt
|
602
592
|
- lib/rails/generators/test_unit/component_generator.rb
|
603
|
-
- lib/rails/generators/test_unit/templates/component_test.rb.tt
|
604
593
|
- lib/view_component.rb
|
605
594
|
- lib/view_component/base.rb
|
606
595
|
- lib/view_component/capture_compatibility.rb
|
@@ -611,8 +600,6 @@ files:
|
|
611
600
|
- lib/view_component/config.rb
|
612
601
|
- lib/view_component/configurable.rb
|
613
602
|
- lib/view_component/deprecation.rb
|
614
|
-
- lib/view_component/docs_builder_component.html.erb
|
615
|
-
- lib/view_component/docs_builder_component.rb
|
616
603
|
- lib/view_component/engine.rb
|
617
604
|
- lib/view_component/errors.rb
|
618
605
|
- lib/view_component/inline_template.rb
|
@@ -637,7 +624,6 @@ files:
|
|
637
624
|
- lib/view_component/use_helpers.rb
|
638
625
|
- lib/view_component/version.rb
|
639
626
|
- lib/view_component/with_content_helper.rb
|
640
|
-
- lib/yard/mattr_accessor_handler.rb
|
641
627
|
homepage: https://viewcomponent.org
|
642
628
|
licenses:
|
643
629
|
- MIT
|
@@ -659,7 +645,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
659
645
|
- !ruby/object:Gem::Version
|
660
646
|
version: '0'
|
661
647
|
requirements: []
|
662
|
-
rubygems_version: 3.6.
|
648
|
+
rubygems_version: 3.6.8
|
663
649
|
specification_version: 4
|
664
650
|
summary: A framework for building reusable, testable & encapsulated view components
|
665
651
|
in Ruby on Rails.
|
@@ -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,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
<% module_namespacing do -%>
|
4
|
-
class <%= class_name %><%= options[:skip_suffix] ? "" : "Component" %> < <%= parent_class %>
|
5
|
-
<%- if initialize_signature -%>
|
6
|
-
def initialize(<%= initialize_signature %>)
|
7
|
-
<%= initialize_body %>
|
8
|
-
end
|
9
|
-
<%- end -%>
|
10
|
-
<%- if initialize_call_method_for_inline? -%>
|
11
|
-
def call
|
12
|
-
content_tag :h1, "Hello world!"<%= ", data: { controller: \"#{stimulus_controller}\" }" if options["stimulus"] %>
|
13
|
-
end
|
14
|
-
<%- end -%>
|
15
|
-
end
|
16
|
-
<% end -%>
|
@@ -1 +0,0 @@
|
|
1
|
-
<div<%= data_attributes %>>Add <%= class_name %> template here</div>
|
@@ -1 +0,0 @@
|
|
1
|
-
%div Add <%= class_name %> template here
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails_helper"
|
4
|
-
|
5
|
-
RSpec.describe <%= namespaced? ? "#{namespace.name}::" : '' %><%= class_name %>Component, type: :component do
|
6
|
-
pending "add some examples to (or delete) #{__FILE__}"
|
7
|
-
|
8
|
-
# it "renders something useful" do
|
9
|
-
# expect(
|
10
|
-
# render_inline(described_class.new(attr: "value")) { "Hello, components!" }.css("p").to_html
|
11
|
-
# ).to include(
|
12
|
-
# "Hello, components!"
|
13
|
-
# )
|
14
|
-
# end
|
15
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
div Add <%= class_name %> template here
|
@@ -1 +0,0 @@
|
|
1
|
-
<div<%= data_attributes %>>Add <%= class_name %> template here</div>
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
class <%= namespaced? ? "#{namespace.name}::" : '' %><%= class_name %>ComponentTest < ViewComponent::TestCase
|
6
|
-
def test_component_renders_something_useful
|
7
|
-
# assert_equal(
|
8
|
-
# %(<span>Hello, components!</span>),
|
9
|
-
# render_inline(<%= class_name %>Component.new(message: "Hello, components!")).css("span").to_html
|
10
|
-
# )
|
11
|
-
end
|
12
|
-
end
|
@@ -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
|