view_component 3.21.0 → 3.23.0
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 +75 -1
- data/lib/view_component/base.rb +8 -1
- data/lib/view_component/config.rb +1 -1
- data/lib/view_component/configurable.rb +17 -0
- data/lib/view_component/errors.rb +3 -3
- data/lib/view_component/slotable.rb +1 -2
- data/lib/view_component/template.rb +2 -2
- data/lib/view_component/version.rb +1 -1
- metadata +20 -25
- 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/view_component/rails/tasks/view_component.rake +0 -20
- 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: 6d542616afad25462cb50efaacaaf191bfc59fdff6aa54132536fc5f9baaa13f
|
4
|
+
data.tar.gz: 8f229412d38d65593a377a215923828772a2c2a75e3f2786dcac35ba9d778932
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '082d994fdaf93ec868207edc94d51bd36f873f8601da1ee9ee9aeaf28dc40cfa17da79625d60c15caeb4bc86079e22aa791e16c8db052cb5e5ce4a81df7e5594'
|
7
|
+
data.tar.gz: 8ddf8b136dc0b14492493609fb6a0f0206865eeca43149eaceb4255c3adf85dd5e6cfd4f75ab4393d0f8e233bd7c06a455ae7c28644a5f9870b76a04c29ef03b
|
@@ -14,7 +14,14 @@ module ViewComponent
|
|
14
14
|
|
15
15
|
# Including helpers here ensures that we're loading the
|
16
16
|
# latest version of helpers if code-reloading is enabled
|
17
|
-
|
17
|
+
if include_all_helpers
|
18
|
+
helper :all
|
19
|
+
else
|
20
|
+
# :nocov:
|
21
|
+
# Always provide the #view_source helper
|
22
|
+
helper PreviewHelper
|
23
|
+
# :nocov:
|
24
|
+
end
|
18
25
|
end
|
19
26
|
|
20
27
|
def index
|
@@ -22,7 +22,7 @@ module PreviewHelper
|
|
22
22
|
serve_static_preview_assets? ? asset_path("prism.min.js", skip_pipeline: true) : "https://cdn.jsdelivr.net/npm/prismjs@1.28.0/prism.min.js"
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def find_template_data_for_preview_source(lookup_context:, template_identifier:)
|
26
26
|
template = lookup_context.find_template(template_identifier)
|
27
27
|
|
28
28
|
if Rails.version.to_f >= 6.1 || template.source.present?
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<%= h @preview.preview_source(@example_name) %>
|
8
8
|
</code>
|
9
9
|
<% else %>
|
10
|
-
<% template_data =
|
10
|
+
<% template_data = find_template_data_for_preview_source(lookup_context: @view_renderer.lookup_context, template_identifier: @render_args[:template]) %>
|
11
11
|
<code class="language-<%= template_data[:prism_language_name] %>">
|
12
12
|
<%= h template_data[:source] %>
|
13
13
|
</code>
|
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,76 @@ nav_order: 5
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 3.23.0
|
14
|
+
|
15
|
+
* Add docs about Slack channel in Ruby Central workspace. (Join us! #oss-view-component). Email joelhawksley@github.com for an invite.
|
16
|
+
|
17
|
+
*Joel Hawksley
|
18
|
+
|
19
|
+
* Do not include internal `DocsBuilderComponent` or `YARD::MattrAccessorHandler` in published gem.
|
20
|
+
|
21
|
+
*Joel Hawksley*
|
22
|
+
|
23
|
+
* Only lock to `concurrent-ruby` `1.3.4` for Rails 6.1.
|
24
|
+
|
25
|
+
*Joel Hawksley*
|
26
|
+
|
27
|
+
* Fix generation of ViewComponent documentation that was broken due to HTML safety issues.
|
28
|
+
|
29
|
+
*Simon Fish*
|
30
|
+
|
31
|
+
* Add documentation on how ViewComponent works.
|
32
|
+
|
33
|
+
*Joel Hawksley*
|
34
|
+
|
35
|
+
* Clarify that `config.use_deprecated_instrumentation_name` will be removed in v4.
|
36
|
+
|
37
|
+
*Joel Hawksley*
|
38
|
+
|
39
|
+
* Run RSpec tests in CI.
|
40
|
+
|
41
|
+
*Joel Hawksley*
|
42
|
+
|
43
|
+
## 3.22.0
|
44
|
+
|
45
|
+
* Rewrite `ViewComponents at GitHub` documentation as more general `Best practices`.
|
46
|
+
|
47
|
+
*Phil Schalm*, *Joel Hawksley*
|
48
|
+
|
49
|
+
* Add unused mechanism for inheriting config from parent modules to enable future engine-local configuration.
|
50
|
+
|
51
|
+
*Simon Fish*
|
52
|
+
|
53
|
+
* Improve handling of malformed component edge case when mocking components in tests.
|
54
|
+
|
55
|
+
*Martin Meyerhoff*, *Joel Hawksley*
|
56
|
+
|
57
|
+
* Add Content Harmony & Learn To Be to list of companies using ViewComponent.
|
58
|
+
|
59
|
+
*Kane Jamison*
|
60
|
+
|
61
|
+
* Clarify error message about render-dependent logic.
|
62
|
+
|
63
|
+
Error messages about render-dependent logic were sometimes inaccurate, saying `during initialization` despite also being raised after a component had been initialized but before it was rendered.
|
64
|
+
|
65
|
+
*Joel Hawksley*
|
66
|
+
|
67
|
+
* Remove JS and CSS docs as they proved difficult to maintain and lacked consensus.
|
68
|
+
|
69
|
+
*Joel Hawksley*
|
70
|
+
|
71
|
+
* Do not prefix release tags with `v`, per recommendation from @bkuhlmann.
|
72
|
+
|
73
|
+
*Joel Hawksley*
|
74
|
+
|
75
|
+
* Add ruby 3.4 support to CI.
|
76
|
+
|
77
|
+
*Reegan Viljoen*
|
78
|
+
|
79
|
+
* Add HomeStyler AI to list of companies using ViewComponent.
|
80
|
+
|
81
|
+
*JP Balarini*
|
82
|
+
|
13
83
|
## 3.21.0
|
14
84
|
|
15
85
|
* Updates testing docs to include an example of how to use with RSpec.
|
@@ -218,6 +288,10 @@ nav_order: 5
|
|
218
288
|
|
219
289
|
*Reegan Viljoen*
|
220
290
|
|
291
|
+
* Fix a bug where component previews would crash with "undefined local variable or method `preview_source`."
|
292
|
+
|
293
|
+
*Henning Koch*
|
294
|
+
|
221
295
|
## 3.12.1
|
222
296
|
|
223
297
|
* Ensure content is rendered correctly for forwarded slots.
|
data/lib/view_component/base.rb
CHANGED
@@ -25,6 +25,11 @@ module ViewComponent
|
|
25
25
|
#
|
26
26
|
# @return [ActiveSupport::OrderedOptions]
|
27
27
|
def config
|
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
|
32
|
+
end
|
28
33
|
ViewComponent::Config.current
|
29
34
|
end
|
30
35
|
end
|
@@ -191,6 +196,8 @@ module ViewComponent
|
|
191
196
|
true
|
192
197
|
end
|
193
198
|
|
199
|
+
# Override the ActionView::Base initializer so that components
|
200
|
+
# do not need to define their own initializers.
|
194
201
|
# @private
|
195
202
|
def initialize(*)
|
196
203
|
end
|
@@ -247,7 +254,7 @@ module ViewComponent
|
|
247
254
|
raise e, <<~MESSAGE.chomp if view_context && e.is_a?(NameError) && helpers.respond_to?(method_name)
|
248
255
|
#{e.message}
|
249
256
|
|
250
|
-
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}`?
|
251
258
|
MESSAGE
|
252
259
|
|
253
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
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ViewComponent
|
4
|
+
module Configurable
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
next if respond_to?(:config) && config.respond_to?(:view_component) && config.respond_to_missing?(:test_controller)
|
9
|
+
|
10
|
+
include ActiveSupport::Configurable
|
11
|
+
|
12
|
+
configure do |config|
|
13
|
+
config.view_component ||= ActiveSupport::InheritableOptions.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -177,7 +177,7 @@ module ViewComponent
|
|
177
177
|
|
178
178
|
class TranslateCalledBeforeRenderError < BaseError
|
179
179
|
MESSAGE =
|
180
|
-
"`#translate` can't be used
|
180
|
+
"`#translate` can't be used before rendering as it depends " \
|
181
181
|
"on the view context that only exists once a ViewComponent is passed to " \
|
182
182
|
"the Rails render pipeline.\n\n" \
|
183
183
|
"It's sometimes possible to fix this issue by moving code dependent on " \
|
@@ -186,7 +186,7 @@ module ViewComponent
|
|
186
186
|
|
187
187
|
class HelpersCalledBeforeRenderError < BaseError
|
188
188
|
MESSAGE =
|
189
|
-
"`#helpers` can't be used
|
189
|
+
"`#helpers` can't be used before rendering as it depends " \
|
190
190
|
"on the view context that only exists once a ViewComponent is passed to " \
|
191
191
|
"the Rails render pipeline.\n\n" \
|
192
192
|
"It's sometimes possible to fix this issue by moving code dependent on " \
|
@@ -195,7 +195,7 @@ module ViewComponent
|
|
195
195
|
|
196
196
|
class ControllerCalledBeforeRenderError < BaseError
|
197
197
|
MESSAGE =
|
198
|
-
"`#controller` can't be used
|
198
|
+
"`#controller` can't be used before rendering, as it depends " \
|
199
199
|
"on the view context that only exists once a ViewComponent is passed to " \
|
200
200
|
"the Rails render pipeline.\n\n" \
|
201
201
|
"It's sometimes possible to fix this issue by moving code dependent on " \
|
@@ -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
|
|
@@ -63,8 +63,8 @@ module ViewComponent
|
|
63
63
|
return safe_method_name unless inline_call?
|
64
64
|
|
65
65
|
"maybe_escape_html(#{safe_method_name}) " \
|
66
|
-
"{ Kernel.warn(
|
67
|
-
"The output will be automatically escaped, but you may want to investigate
|
66
|
+
"{ Kernel.warn(\"WARNING: The #{@component} component rendered HTML-unsafe output. " \
|
67
|
+
"The output will be automatically escaped, but you may want to investigate.\") } "
|
68
68
|
end
|
69
69
|
|
70
70
|
def requires_compiled_superclass?
|
metadata
CHANGED
@@ -1,14 +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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ViewComponent Team
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activesupport
|
@@ -50,14 +49,14 @@ dependencies:
|
|
50
49
|
requirements:
|
51
50
|
- - "~>"
|
52
51
|
- !ruby/object:Gem::Version
|
53
|
-
version: '1
|
52
|
+
version: '1'
|
54
53
|
type: :runtime
|
55
54
|
prerelease: false
|
56
55
|
version_requirements: !ruby/object:Gem::Requirement
|
57
56
|
requirements:
|
58
57
|
- - "~>"
|
59
58
|
- !ruby/object:Gem::Version
|
60
|
-
version: '1
|
59
|
+
version: '1'
|
61
60
|
- !ruby/object:Gem::Dependency
|
62
61
|
name: allocation_stats
|
63
62
|
requirement: !ruby/object:Gem::Requirement
|
@@ -548,8 +547,20 @@ dependencies:
|
|
548
547
|
- - ">="
|
549
548
|
- !ruby/object:Gem::Version
|
550
549
|
version: '0'
|
551
|
-
|
552
|
-
|
550
|
+
- !ruby/object:Gem::Dependency
|
551
|
+
name: propshaft
|
552
|
+
requirement: !ruby/object:Gem::Requirement
|
553
|
+
requirements:
|
554
|
+
- - "~>"
|
555
|
+
- !ruby/object:Gem::Version
|
556
|
+
version: 1.1.0
|
557
|
+
type: :development
|
558
|
+
prerelease: false
|
559
|
+
version_requirements: !ruby/object:Gem::Requirement
|
560
|
+
requirements:
|
561
|
+
- - "~>"
|
562
|
+
- !ruby/object:Gem::Version
|
563
|
+
version: 1.1.0
|
553
564
|
executables: []
|
554
565
|
extensions: []
|
555
566
|
extra_rdoc_files: []
|
@@ -569,27 +580,16 @@ files:
|
|
569
580
|
- app/views/view_components/previews.html.erb
|
570
581
|
- docs/CHANGELOG.md
|
571
582
|
- lib/rails/generators/abstract_generator.rb
|
572
|
-
- lib/rails/generators/component/USAGE
|
573
583
|
- lib/rails/generators/component/component_generator.rb
|
574
|
-
- lib/rails/generators/component/templates/component.rb.tt
|
575
584
|
- lib/rails/generators/erb/component_generator.rb
|
576
|
-
- lib/rails/generators/erb/templates/component.html.erb.tt
|
577
585
|
- lib/rails/generators/haml/component_generator.rb
|
578
|
-
- lib/rails/generators/haml/templates/component.html.haml.tt
|
579
586
|
- lib/rails/generators/locale/component_generator.rb
|
580
587
|
- lib/rails/generators/preview/component_generator.rb
|
581
|
-
- lib/rails/generators/preview/templates/component_preview.rb.tt
|
582
588
|
- lib/rails/generators/rspec/component_generator.rb
|
583
|
-
- lib/rails/generators/rspec/templates/component_spec.rb.tt
|
584
589
|
- lib/rails/generators/slim/component_generator.rb
|
585
|
-
- lib/rails/generators/slim/templates/component.html.slim.tt
|
586
590
|
- lib/rails/generators/stimulus/component_generator.rb
|
587
|
-
- lib/rails/generators/stimulus/templates/component_controller.js.tt
|
588
|
-
- lib/rails/generators/stimulus/templates/component_controller.ts.tt
|
589
591
|
- lib/rails/generators/tailwindcss/component_generator.rb
|
590
|
-
- lib/rails/generators/tailwindcss/templates/component.html.erb.tt
|
591
592
|
- lib/rails/generators/test_unit/component_generator.rb
|
592
|
-
- lib/rails/generators/test_unit/templates/component_test.rb.tt
|
593
593
|
- lib/view_component.rb
|
594
594
|
- lib/view_component/base.rb
|
595
595
|
- lib/view_component/capture_compatibility.rb
|
@@ -598,15 +598,13 @@ files:
|
|
598
598
|
- lib/view_component/compiler.rb
|
599
599
|
- lib/view_component/component_error.rb
|
600
600
|
- lib/view_component/config.rb
|
601
|
+
- lib/view_component/configurable.rb
|
601
602
|
- lib/view_component/deprecation.rb
|
602
|
-
- lib/view_component/docs_builder_component.html.erb
|
603
|
-
- lib/view_component/docs_builder_component.rb
|
604
603
|
- lib/view_component/engine.rb
|
605
604
|
- lib/view_component/errors.rb
|
606
605
|
- lib/view_component/inline_template.rb
|
607
606
|
- lib/view_component/instrumentation.rb
|
608
607
|
- lib/view_component/preview.rb
|
609
|
-
- lib/view_component/rails/tasks/view_component.rake
|
610
608
|
- lib/view_component/render_component_helper.rb
|
611
609
|
- lib/view_component/render_component_to_string_helper.rb
|
612
610
|
- lib/view_component/render_monkey_patch.rb
|
@@ -625,7 +623,6 @@ files:
|
|
625
623
|
- lib/view_component/use_helpers.rb
|
626
624
|
- lib/view_component/version.rb
|
627
625
|
- lib/view_component/with_content_helper.rb
|
628
|
-
- lib/yard/mattr_accessor_handler.rb
|
629
626
|
homepage: https://viewcomponent.org
|
630
627
|
licenses:
|
631
628
|
- MIT
|
@@ -633,7 +630,6 @@ metadata:
|
|
633
630
|
allowed_push_host: https://rubygems.org
|
634
631
|
source_code_uri: https://github.com/viewcomponent/view_component
|
635
632
|
changelog_uri: https://github.com/ViewComponent/view_component/blob/main/docs/CHANGELOG.md
|
636
|
-
post_install_message:
|
637
633
|
rdoc_options: []
|
638
634
|
require_paths:
|
639
635
|
- lib
|
@@ -648,8 +644,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
648
644
|
- !ruby/object:Gem::Version
|
649
645
|
version: '0'
|
650
646
|
requirements: []
|
651
|
-
rubygems_version: 3.
|
652
|
-
signing_key:
|
647
|
+
rubygems_version: 3.6.8
|
653
648
|
specification_version: 4
|
654
649
|
summary: A framework for building reusable, testable & encapsulated view components
|
655
650
|
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,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
task stats: "view_component:statsetup"
|
4
|
-
|
5
|
-
namespace :view_component do
|
6
|
-
task :statsetup do
|
7
|
-
# :nocov:
|
8
|
-
require "rails/code_statistics"
|
9
|
-
|
10
|
-
if Rails.root.join(ViewComponent::Base.view_component_path).directory?
|
11
|
-
::STATS_DIRECTORIES << ["ViewComponents", ViewComponent::Base.view_component_path]
|
12
|
-
end
|
13
|
-
|
14
|
-
if Rails.root.join("test/components").directory?
|
15
|
-
::STATS_DIRECTORIES << ["ViewComponent tests", "test/components"]
|
16
|
-
CodeStatistics::TEST_TYPES << "ViewComponent tests"
|
17
|
-
end
|
18
|
-
# :nocov:
|
19
|
-
end
|
20
|
-
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
|