polaris_view_components 2.5.1 → 3.1.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/README.md +12 -0
- data/app/assets/javascripts/polaris_view_components/modal_controller.js +4 -0
- data/app/assets/javascripts/polaris_view_components.js +4 -0
- data/app/components/polaris/action_list/section_component.html.erb +1 -1
- data/app/components/polaris/avatar_component.html.erb +1 -1
- data/app/components/polaris/character_count.rb +3 -3
- data/app/components/polaris/divider_component.rb +24 -1
- data/app/components/polaris/empty_state_component.html.erb +1 -1
- data/app/components/polaris/index_table_component.html.erb +4 -4
- data/lib/polaris/view_components/version.rb +1 -1
- data/lib/tasks/polaris_view_components_tasks.rake +0 -14
- metadata +12 -17
- data/lib/polaris/view_components/codemods/v3_slot_setters.rb +0 -222
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ca5d44863ed4e92c96355b43938b83e3d6c35faf836f21ec8d30cfbe4bf955a3
|
|
4
|
+
data.tar.gz: 569be82094984c0afb8ebaa30950aef78f11e5365ebcdebeb3d1bde5da03311e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f9cac7d32e9bce452bdd695c371fe9a91cd6ce79be8579abdf01b6d73deecda3f347370931343ee932c79e7ab093eb5989006c6e02014f80a9e35b403d66a605
|
|
7
|
+
data.tar.gz: 4350c590a31131ec013cfe3982c397005d05e52bee58b996bb6cfa48553605765bcbd97dcd183c9b6dea8475f2bc6a8f49eee95d86053ee9e1717caf31875d4c
|
data/README.md
CHANGED
|
@@ -73,6 +73,18 @@ npm run release
|
|
|
73
73
|
|
|
74
74
|
After that make sure to commit changes in package.json.
|
|
75
75
|
|
|
76
|
+
## Deploy
|
|
77
|
+
|
|
78
|
+
Before deploying make sure to:
|
|
79
|
+
|
|
80
|
+
1. Copy `demo/config/master.key` from 1Password
|
|
81
|
+
2. Set `KAMAL_REGISTRY_PASSWORD` in `.env`
|
|
82
|
+
|
|
83
|
+
Then run:
|
|
84
|
+
```bash
|
|
85
|
+
kamal deploy
|
|
86
|
+
```
|
|
87
|
+
|
|
76
88
|
## License
|
|
77
89
|
|
|
78
90
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -17,10 +17,14 @@ export default class extends Controller {
|
|
|
17
17
|
const dropElement = `<div class="${this.backdropClass}" data-controller="polaris" data-target="#${this.element.id}" data-action="click->polaris#closeModal"></div>`
|
|
18
18
|
this.element.insertAdjacentHTML('afterend', dropElement)
|
|
19
19
|
this.backdrop = this.element.nextElementSibling
|
|
20
|
+
const event = new CustomEvent("polarisModalOpened");
|
|
21
|
+
window.dispatchEvent(event);
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
close() {
|
|
23
25
|
this.element.classList.add(this.hiddenClass)
|
|
24
26
|
this.backdrop.remove()
|
|
27
|
+
const event = new CustomEvent("polarisModalClosed");
|
|
28
|
+
window.dispatchEvent(event);
|
|
25
29
|
}
|
|
26
30
|
}
|
|
@@ -839,10 +839,14 @@ class Modal extends Controller {
|
|
|
839
839
|
const dropElement = `<div class="${this.backdropClass}" data-controller="polaris" data-target="#${this.element.id}" data-action="click->polaris#closeModal"></div>`;
|
|
840
840
|
this.element.insertAdjacentHTML("afterend", dropElement);
|
|
841
841
|
this.backdrop = this.element.nextElementSibling;
|
|
842
|
+
const event = new CustomEvent("polarisModalOpened");
|
|
843
|
+
window.dispatchEvent(event);
|
|
842
844
|
}
|
|
843
845
|
close() {
|
|
844
846
|
this.element.classList.add(this.hiddenClass);
|
|
845
847
|
this.backdrop.remove();
|
|
848
|
+
const event = new CustomEvent("polarisModalClosed");
|
|
849
|
+
window.dispatchEvent(event);
|
|
846
850
|
}
|
|
847
851
|
}
|
|
848
852
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%= render Polaris::BaseComponent.new(**system_arguments) do %>
|
|
2
2
|
<% if @source %>
|
|
3
|
-
<img src="<%= @source %>" class="Polaris-Avatar__Image" role="presentation" onerror="this.src=''"
|
|
3
|
+
<img src="<%= @source %>" class="Polaris-Avatar__Image" role="presentation" onerror="this.src=''" alt="">
|
|
4
4
|
<% else %>
|
|
5
5
|
<span class="Polaris-Avatar__Initials">
|
|
6
6
|
<% if @initials %>
|
|
@@ -22,9 +22,9 @@ module Polaris
|
|
|
22
22
|
def label_template
|
|
23
23
|
if max_length?
|
|
24
24
|
"{count} of #{@max_length} characters used"
|
|
25
|
+
else
|
|
26
|
+
"{count} characters"
|
|
25
27
|
end
|
|
26
|
-
|
|
27
|
-
"{count} characters"
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def text_template
|
|
@@ -40,7 +40,7 @@ module Polaris
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def normalized_value
|
|
43
|
-
@text_field.value.to_s
|
|
43
|
+
@text_field.value.to_s
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def count
|
|
@@ -2,9 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
module Polaris
|
|
4
4
|
class DividerComponent < Polaris::Component
|
|
5
|
+
include ActiveModel::Validations
|
|
6
|
+
|
|
7
|
+
SUPPORTED_DIRECTIONS = %w[inline block].freeze
|
|
8
|
+
|
|
9
|
+
validates :direction, inclusion: {in: SUPPORTED_DIRECTIONS}
|
|
10
|
+
|
|
5
11
|
def initialize(
|
|
6
12
|
border_color: "border-subdued",
|
|
7
13
|
border_width: "1",
|
|
14
|
+
direction: "inline",
|
|
8
15
|
**system_arguments
|
|
9
16
|
)
|
|
10
17
|
@system_arguments = system_arguments.tap do |args|
|
|
@@ -15,7 +22,7 @@ module Polaris
|
|
|
15
22
|
)
|
|
16
23
|
args[:style] = styles_list(
|
|
17
24
|
args[:style],
|
|
18
|
-
|
|
25
|
+
**border_styles(direction, border_color, border_width)
|
|
19
26
|
)
|
|
20
27
|
end
|
|
21
28
|
end
|
|
@@ -31,5 +38,21 @@ module Polaris
|
|
|
31
38
|
return "transparent" if border_color == "transparent"
|
|
32
39
|
"var(--p-color-#{fetch_or_fallback(Tokens::Color::BORDER_ALIAS, border_color)})"
|
|
33
40
|
end
|
|
41
|
+
|
|
42
|
+
def border_styles(direction, border_color, border_width)
|
|
43
|
+
border_direction = fetch_or_fallback(SUPPORTED_DIRECTIONS, direction, "inline")
|
|
44
|
+
|
|
45
|
+
if border_direction == "block"
|
|
46
|
+
{
|
|
47
|
+
"border-inline-start": "var(--p-border-width-#{fetch_or_fallback(Tokens::Border::WIDTH_SCALE, border_width)}) solid #{border_color_value(border_color)}",
|
|
48
|
+
"inline-size": "auto",
|
|
49
|
+
"min-block-size": "100%"
|
|
50
|
+
}
|
|
51
|
+
else
|
|
52
|
+
{
|
|
53
|
+
"border-block-start": "var(--p-border-width-#{fetch_or_fallback(Tokens::Border::WIDTH_SCALE, border_width)}) solid #{border_color_value(border_color)}"
|
|
54
|
+
}
|
|
55
|
+
end
|
|
56
|
+
end
|
|
34
57
|
end
|
|
35
58
|
end
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
**@system_arguments
|
|
7
7
|
) do %>
|
|
8
8
|
<%= polaris_vertical_stack(inline_align: :center) do %>
|
|
9
|
-
<img src="<%= @image %>" role="presentation" class="<%= @image_contained_class %>">
|
|
9
|
+
<img src="<%= @image %>" role="presentation" class="<%= @image_contained_class %>" alt="">
|
|
10
10
|
|
|
11
11
|
<%= polaris_box(max_width: @full_width? "100%" : "400px") do %>
|
|
12
12
|
<%= polaris_vertical_stack(inline_align: :center) do %>
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
require "polaris/view_components/codemods/v3_slot_setters"
|
|
2
|
-
|
|
3
1
|
namespace :polaris_view_components do
|
|
4
2
|
desc "Setup Polaris::ViewComponents for the app"
|
|
5
3
|
task :install do
|
|
6
4
|
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/install.rb", __dir__)}"
|
|
7
5
|
end
|
|
8
|
-
|
|
9
|
-
task detect_legacy_slots: :environment do
|
|
10
|
-
ARGV.each { |a| task a.to_sym {} }
|
|
11
|
-
custom_paths = ARGV.compact.map { |path| Rails.root.join(path) }
|
|
12
|
-
Polaris::ViewComponents::Codemods::V3SlotSetters.new(view_path: custom_paths).call
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
task migrate_legacy_slots: :environment do
|
|
16
|
-
ARGV.each { |a| task a.to_sym {} }
|
|
17
|
-
custom_paths = ARGV.compact.map { |path| Rails.root.join(path) }
|
|
18
|
-
Polaris::ViewComponents::Codemods::V3SlotSetters.new(view_path: custom_paths, migrate: true).call
|
|
19
|
-
end
|
|
20
6
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: polaris_view_components
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dan Gamble
|
|
8
8
|
- Kirill Platonov
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: rails
|
|
@@ -17,14 +16,14 @@ dependencies:
|
|
|
17
16
|
requirements:
|
|
18
17
|
- - ">="
|
|
19
18
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
19
|
+
version: 7.1.0
|
|
21
20
|
type: :runtime
|
|
22
21
|
prerelease: false
|
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
23
|
requirements:
|
|
25
24
|
- - ">="
|
|
26
25
|
- !ruby/object:Gem::Version
|
|
27
|
-
version:
|
|
26
|
+
version: 7.1.0
|
|
28
27
|
- !ruby/object:Gem::Dependency
|
|
29
28
|
name: view_component
|
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -34,7 +33,7 @@ dependencies:
|
|
|
34
33
|
version: 3.0.0
|
|
35
34
|
- - "<"
|
|
36
35
|
- !ruby/object:Gem::Version
|
|
37
|
-
version: 4.
|
|
36
|
+
version: 4.2.0
|
|
38
37
|
type: :runtime
|
|
39
38
|
prerelease: false
|
|
40
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -44,7 +43,7 @@ dependencies:
|
|
|
44
43
|
version: 3.0.0
|
|
45
44
|
- - "<"
|
|
46
45
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 4.
|
|
46
|
+
version: 4.2.0
|
|
48
47
|
- !ruby/object:Gem::Dependency
|
|
49
48
|
name: webdrivers
|
|
50
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -65,14 +64,14 @@ dependencies:
|
|
|
65
64
|
requirements:
|
|
66
65
|
- - "~>"
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
|
-
version:
|
|
67
|
+
version: 4.9.0
|
|
69
68
|
type: :development
|
|
70
69
|
prerelease: false
|
|
71
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
72
71
|
requirements:
|
|
73
72
|
- - "~>"
|
|
74
73
|
- !ruby/object:Gem::Version
|
|
75
|
-
version:
|
|
74
|
+
version: 4.9.0
|
|
76
75
|
- !ruby/object:Gem::Dependency
|
|
77
76
|
name: minitest
|
|
78
77
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -121,14 +120,14 @@ dependencies:
|
|
|
121
120
|
requirements:
|
|
122
121
|
- - "~>"
|
|
123
122
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: 2.
|
|
123
|
+
version: '2.8'
|
|
125
124
|
type: :development
|
|
126
125
|
prerelease: false
|
|
127
126
|
version_requirements: !ruby/object:Gem::Requirement
|
|
128
127
|
requirements:
|
|
129
128
|
- - "~>"
|
|
130
129
|
- !ruby/object:Gem::Version
|
|
131
|
-
version: 2.
|
|
130
|
+
version: '2.8'
|
|
132
131
|
- !ruby/object:Gem::Dependency
|
|
133
132
|
name: dotenv
|
|
134
133
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -143,7 +142,6 @@ dependencies:
|
|
|
143
142
|
- - ">="
|
|
144
143
|
- !ruby/object:Gem::Version
|
|
145
144
|
version: '0'
|
|
146
|
-
description:
|
|
147
145
|
email:
|
|
148
146
|
- dan@dangamble.co.uk
|
|
149
147
|
executables: []
|
|
@@ -929,7 +927,6 @@ files:
|
|
|
929
927
|
- config/locales/en.yml
|
|
930
928
|
- lib/install/install.rb
|
|
931
929
|
- lib/polaris/view_components.rb
|
|
932
|
-
- lib/polaris/view_components/codemods/v3_slot_setters.rb
|
|
933
930
|
- lib/polaris/view_components/engine.rb
|
|
934
931
|
- lib/polaris/view_components/version.rb
|
|
935
932
|
- lib/polaris_view_components.rb
|
|
@@ -939,7 +936,6 @@ licenses:
|
|
|
939
936
|
- MIT
|
|
940
937
|
metadata:
|
|
941
938
|
allowed_push_host: https://rubygems.org
|
|
942
|
-
post_install_message:
|
|
943
939
|
rdoc_options: []
|
|
944
940
|
require_paths:
|
|
945
941
|
- lib
|
|
@@ -947,15 +943,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
947
943
|
requirements:
|
|
948
944
|
- - ">="
|
|
949
945
|
- !ruby/object:Gem::Version
|
|
950
|
-
version: 2.
|
|
946
|
+
version: 3.2.0
|
|
951
947
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
952
948
|
requirements:
|
|
953
949
|
- - ">="
|
|
954
950
|
- !ruby/object:Gem::Version
|
|
955
951
|
version: '0'
|
|
956
952
|
requirements: []
|
|
957
|
-
rubygems_version:
|
|
958
|
-
signing_key:
|
|
953
|
+
rubygems_version: 4.0.3
|
|
959
954
|
specification_version: 4
|
|
960
955
|
summary: ViewComponents for Polaris Design System
|
|
961
956
|
test_files: []
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Polaris
|
|
4
|
-
module ViewComponents
|
|
5
|
-
# Usage:
|
|
6
|
-
#
|
|
7
|
-
# Run via rake task:
|
|
8
|
-
#
|
|
9
|
-
# bin/rails polaris_view_components:detect_legacy_slots
|
|
10
|
-
# bin/rails polaris_view_components:migrate_legacy_slots
|
|
11
|
-
# bin/rails polaris_view_components:migrate_legacy_slots app/views
|
|
12
|
-
#
|
|
13
|
-
# Or run via rails console if you need to pass custom paths:
|
|
14
|
-
#
|
|
15
|
-
# Polaris::ViewComponents::Codemods::V3SlotSetters.new(
|
|
16
|
-
# view_path: Rails.root.join("app/views"),
|
|
17
|
-
# ).call
|
|
18
|
-
module Codemods
|
|
19
|
-
class V3SlotSetters
|
|
20
|
-
TEMPLATE_LANGUAGES = %w[erb slim haml].join(",").freeze
|
|
21
|
-
RENDER_REGEX = /render[( ](?<component>\w+(?:::\w+)*)\.new[) ]+(do|\{) \|(?<arg>\w+)\b/ # standard:disable Lint/MixedRegexpCaptureTypes
|
|
22
|
-
|
|
23
|
-
Suggestion = Struct.new(:file, :line, :message)
|
|
24
|
-
|
|
25
|
-
def initialize(view_component_path: [], view_path: [], migrate: false)
|
|
26
|
-
Rails.application.eager_load!
|
|
27
|
-
|
|
28
|
-
@view_component_path = view_component_path
|
|
29
|
-
@view_path = view_path
|
|
30
|
-
@migrate = migrate
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def call
|
|
34
|
-
puts "Using ViewComponent path: #{view_component_paths.join(", ")}"
|
|
35
|
-
puts "Using Views path: #{view_paths.join(", ")}"
|
|
36
|
-
puts "#{view_components.size} ViewComponents found"
|
|
37
|
-
puts "#{slottable_components.size} ViewComponents using Slots found"
|
|
38
|
-
puts "#{view_component_files.size} ViewComponent templates found"
|
|
39
|
-
puts "#{view_files.size} view files found"
|
|
40
|
-
process_all_files
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def process_all_files
|
|
44
|
-
all_files.each do |file|
|
|
45
|
-
process_file(file)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def process_file(file)
|
|
50
|
-
@suggestions = []
|
|
51
|
-
@suggestions += scan_exact_matches(file)
|
|
52
|
-
@suggestions += scan_uncertain_matches(file)
|
|
53
|
-
|
|
54
|
-
if @suggestions.any?
|
|
55
|
-
puts
|
|
56
|
-
puts "File: #{file}"
|
|
57
|
-
@suggestions.each do |s|
|
|
58
|
-
puts "=> line #{s.line}: #{s.message}"
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
private
|
|
64
|
-
|
|
65
|
-
def scan_exact_matches(file)
|
|
66
|
-
[].tap do |suggestions|
|
|
67
|
-
rendered_components = []
|
|
68
|
-
content = File.read(file)
|
|
69
|
-
|
|
70
|
-
if (render_match = content.match(RENDER_REGEX))
|
|
71
|
-
component = render_match[:component]
|
|
72
|
-
arg = render_match[:arg]
|
|
73
|
-
|
|
74
|
-
if registered_slots.key?(component.constantize)
|
|
75
|
-
used_slots_names = registered_slots[component.constantize]
|
|
76
|
-
rendered_components << {component: component, arg: arg, slots: used_slots_names}
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
File.open(file, "r+") do |f|
|
|
81
|
-
lines = []
|
|
82
|
-
f.each_line do |line|
|
|
83
|
-
rendered_components.each do |rendered_component|
|
|
84
|
-
arg = rendered_component[:arg]
|
|
85
|
-
slots = rendered_component[:slots]
|
|
86
|
-
|
|
87
|
-
if (matches = line.scan(/#{arg}\.#{Regexp.union(slots)}/))
|
|
88
|
-
matches.each do |match|
|
|
89
|
-
new_value = match.gsub("#{arg}.", "#{arg}.with_")
|
|
90
|
-
message = if @migrate
|
|
91
|
-
"replaced `#{match}` with `#{new_value}`"
|
|
92
|
-
else
|
|
93
|
-
"probably replace `#{match}` with `#{new_value}`"
|
|
94
|
-
end
|
|
95
|
-
suggestions << Suggestion.new(file, f.lineno, message)
|
|
96
|
-
if @migrate
|
|
97
|
-
line.gsub!("#{arg}.", "#{arg}.with_")
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
lines << line
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
if @migrate
|
|
106
|
-
f.rewind
|
|
107
|
-
f.write(lines.join)
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def scan_uncertain_matches(file)
|
|
114
|
-
[].tap do |suggestions|
|
|
115
|
-
File.open(file, "r+") do |f|
|
|
116
|
-
lines = []
|
|
117
|
-
f.each_line do |line|
|
|
118
|
-
if (matches = line.scan(/(?<!\s)\.(?<slot>#{Regexp.union(all_registered_slot_names)})\b/))
|
|
119
|
-
matches.flatten.each do |match|
|
|
120
|
-
next if @suggestions.find { |s| s.file == file && s.line == f.lineno }
|
|
121
|
-
|
|
122
|
-
message = if @migrate
|
|
123
|
-
"replaced `#{match}` with `with_#{match}`"
|
|
124
|
-
else
|
|
125
|
-
"maybe replace `#{match}` with `with_#{match}`"
|
|
126
|
-
end
|
|
127
|
-
suggestions << Suggestion.new(file, f.lineno, message)
|
|
128
|
-
if @migrate
|
|
129
|
-
line.gsub!(/(?<!\s)\.(#{match})\b/, ".with_\\1")
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
lines << line
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
if @migrate
|
|
137
|
-
f.rewind
|
|
138
|
-
f.write(lines.join)
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def view_components
|
|
145
|
-
ViewComponent::Base.descendants
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def slottable_components
|
|
149
|
-
view_components.select do |comp|
|
|
150
|
-
comp.registered_slots.any?
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
def registered_slots
|
|
155
|
-
@registered_slots ||= {}.tap do |slots|
|
|
156
|
-
puts
|
|
157
|
-
puts "Detected slots:"
|
|
158
|
-
slottable_components.each do |comp|
|
|
159
|
-
puts "- `#{comp}` has slots: #{comp.registered_slots.keys.join(", ")}"
|
|
160
|
-
slots[comp] = comp.registered_slots.map do |slot_name, slot|
|
|
161
|
-
normalized_slot_name(slot_name, slot)
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
def all_registered_slot_names
|
|
168
|
-
@all_registered_slot_names ||= registered_slots.values.flatten.uniq
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
def view_component_files
|
|
172
|
-
Dir.glob(Pathname.new(File.join(view_component_path_glob, "**", "*.{rb,#{TEMPLATE_LANGUAGES}}")))
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def view_files
|
|
176
|
-
Dir.glob(Pathname.new(File.join(view_path_glob, "**", "*.{#{TEMPLATE_LANGUAGES}}")))
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def all_files
|
|
180
|
-
view_component_files + view_files
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
def view_component_paths
|
|
184
|
-
@view_component_paths ||= [
|
|
185
|
-
Rails.application.config.view_component.view_component_path,
|
|
186
|
-
@view_component_path
|
|
187
|
-
].flatten.compact.uniq
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
def view_component_path_glob
|
|
191
|
-
return view_component_paths.first if view_component_paths.size == 1
|
|
192
|
-
|
|
193
|
-
"{#{view_component_paths.join(",")}}"
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def rails_view_paths
|
|
197
|
-
ActionController::Base.view_paths.select do |path|
|
|
198
|
-
path.to_s.include?(Rails.root.to_s)
|
|
199
|
-
end.map(&:to_s)
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
def view_paths
|
|
203
|
-
@view_paths ||= [
|
|
204
|
-
rails_view_paths,
|
|
205
|
-
Rails.application.config.view_component.preview_paths,
|
|
206
|
-
@view_path
|
|
207
|
-
].flatten.compact.uniq
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
def view_path_glob
|
|
211
|
-
return view_paths.first if view_paths.size == 1
|
|
212
|
-
|
|
213
|
-
"{#{view_paths.join(",")}}"
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
def normalized_slot_name(slot_name, slot)
|
|
217
|
-
slot[:collection] ? ActiveSupport::Inflector.singularize(slot_name) : slot_name.to_s
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
end
|