vident 0.9.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +116 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +105 -4
- data/lib/vident/base.rb +7 -1
- data/lib/vident/component.rb +1 -0
- data/lib/vident/root_component.rb +23 -3
- data/lib/vident/stable_id.rb +12 -3
- data/lib/vident/version.rb +1 -1
- data/sig/vident.rbs +4 -0
- data/vident.gemspec +30 -0
- metadata +33 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a56c925065ab67c7c41493cd5ab9a1c19fedde171ebc2fcc60477359318ef258
|
4
|
+
data.tar.gz: 595d0ae7292a2548aece9749cbd7dc4e8f177faa6ea49aebfe90a1864c0014ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0ee94c716fee4aa83d496beac7f2d7053e82742006ca1483dbd6ba38ba5ec32fc6f8c8b9f0ca691b05ff2c42947f52aa7937a35c5aef6cfd1bacc6454a7d90c
|
7
|
+
data.tar.gz: 399b0db4d117ee191f871eb5bb23d5419065ca083a58ba778e9a871839e9de1950837868b4b4043a8d72b7e97f18138678f41ef12813905543bc4c4a1619428a
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.0
|
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
|
2
|
+
# Change Log
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
|
+
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
|
+
|
8
|
+
|
9
|
+
## [Unreleased]
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
|
17
|
+
## [0.10.1] - 2024-02-21
|
18
|
+
|
19
|
+
### Added
|
20
|
+
|
21
|
+
- `outlets` option now accepts either a string stimulus controller identifier, a component instance, or a tuple of
|
22
|
+
identifier and CSS selector for the outlet.
|
23
|
+
|
24
|
+
|
25
|
+
## [0.10.0] - 2024-02-21
|
26
|
+
|
27
|
+
### Added
|
28
|
+
|
29
|
+
- `outlets` option for components, used to specify Stimulus outlets
|
30
|
+
|
31
|
+
## [0.9.0] - 2023-08-11
|
32
|
+
|
33
|
+
### Added
|
34
|
+
|
35
|
+
- `#cache_key` support is now part of the core gem, and can be added to components using `Vident::Caching` module
|
36
|
+
|
37
|
+
## [0.8.0] - 2023-03-31
|
38
|
+
|
39
|
+
### Added
|
40
|
+
|
41
|
+
- new gems for Vident related functionality, eg `vident-typed` and `vident-tailwind`
|
42
|
+
- `vident` is now the core gem which can be used with any component system. Gems for Phlex and ViewComponent are available, `vident-phlex` and `vident-view_component`, and `vident-typed-phlex` and `vident-typed-view_component` are available with typed attributes support.
|
43
|
+
|
44
|
+
### Changed
|
45
|
+
|
46
|
+
- removed functionality for `better_html`, `dry-types`, `view_component`, and `phlex` from the core gem
|
47
|
+
- gem is now a Rails Engine and supports eager and autoloading
|
48
|
+
|
49
|
+
### Fixed
|
50
|
+
|
51
|
+
- Fix untyped attributes inheritance
|
52
|
+
|
53
|
+
## [0.7.0] - 2023-03-08
|
54
|
+
|
55
|
+
### Added
|
56
|
+
|
57
|
+
- new `Vident::Tailwind` module which uses [tailwind_merge](https://github.com/gjtorikian/tailwind_merge) to merge TailwindCSS classes
|
58
|
+
|
59
|
+
### Changed
|
60
|
+
|
61
|
+
- Removed a dependency on intenal constants from `phlex`
|
62
|
+
|
63
|
+
## [0.6.3] - 2023-03-03
|
64
|
+
|
65
|
+
### Fixed
|
66
|
+
|
67
|
+
- Fix for changes to HTML tag collection in Phlex
|
68
|
+
|
69
|
+
|
70
|
+
## [0.6.2] - 2023-02-23
|
71
|
+
|
72
|
+
### Fixed
|
73
|
+
|
74
|
+
- Element tag options are not set when no ID is provided
|
75
|
+
|
76
|
+
|
77
|
+
## [0.6.1] - 2023-02-20
|
78
|
+
|
79
|
+
### Fixed
|
80
|
+
|
81
|
+
- `better_html` support fix for aliased dsl methods
|
82
|
+
|
83
|
+
|
84
|
+
## [0.6.0] - 2023-02-20
|
85
|
+
|
86
|
+
### Added
|
87
|
+
|
88
|
+
- Experimental support for `better_html` in the root components (the stimulus attributes are generated with `html_attributes`)
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
## [0.5.1] - 2023-02-17
|
93
|
+
|
94
|
+
### Added
|
95
|
+
|
96
|
+
- N/A
|
97
|
+
|
98
|
+
### Changed
|
99
|
+
|
100
|
+
- N/A
|
101
|
+
|
102
|
+
### Fixed
|
103
|
+
|
104
|
+
- Typed attributes was not always using custom coercion methods if they were defined
|
105
|
+
|
106
|
+
### Removed
|
107
|
+
|
108
|
+
- N/A
|
109
|
+
|
110
|
+
### Deprecated
|
111
|
+
|
112
|
+
- N/A
|
113
|
+
|
114
|
+
### Security
|
115
|
+
|
116
|
+
- N/A
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at stevegeek@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Stephen Ierodiaconou
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
**Vident** is a collection of gems that help you create **flexible** & **maintainable** component libraries for your Rails application.
|
4
4
|
|
5
|
-
<a href="https://github.com/stevegeek/vident"><img alt="Vident logo" src="https://raw.githubusercontent.com/stevegeek/vident/main/logo-by-sd-256-colors.png" width="180" /></a>
|
5
|
+
<a href="https://github.com/stevegeek/vident"><img alt="Vident logo" src="https://raw.githubusercontent.com/stevegeek/vident/main/docs/images/logo-by-sd-256-colors.png" width="180" /></a>
|
6
6
|
|
7
7
|
Vident also provides a neat Ruby DSL to make wiring up **Stimulus easier & less error prone** in your view components.
|
8
8
|
|
@@ -14,10 +14,111 @@ I love working with Stimulus, but I find manually crafting the data attributes f
|
|
14
14
|
targets and actions error-prone and tedious. Vident aims to make this process easier
|
15
15
|
and keep me thinking in Ruby.
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
Vident has been used with `ViewComponent` and `Phlex` in production apps for a while now
|
18
|
+
but is still evolving.
|
19
19
|
|
20
|
-
|
20
|
+
I would love to get your feedback and contributions!
|
21
|
+
|
22
|
+
## Example
|
23
|
+
|
24
|
+
The Greeter ViewComponent (that uses Vident):
|
25
|
+
|
26
|
+
![docs/images/ex1.gif](docs/images/ex1.gif)
|
27
|
+
|
28
|
+
Consider a component, the `GreeterComponent`:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# app/components/greeter_component.rb
|
32
|
+
|
33
|
+
class GreeterComponent < ::Vident::ViewComponent::Base
|
34
|
+
renders_one :trigger, ButtonComponent
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
with ERB as follows:
|
39
|
+
|
40
|
+
```erb
|
41
|
+
<%# app/components/greeter_component.html.erb %>
|
42
|
+
|
43
|
+
<%# Rendering the `root` element creates a tag which has stimulus `data-*`s, a unique id & other attributes set. %>
|
44
|
+
<%# The stimulus controller name (identifier) is derived from the component name, and then used to generate the relavent data attribute names. %>
|
45
|
+
|
46
|
+
<%= render root named_classes: {
|
47
|
+
pre_click: "text-md text-gray-500", # named classes are exposed to Stimulus as `data-<controller>-<name>-class` attributes
|
48
|
+
post_click: "text-xl text-blue-700",
|
49
|
+
html_options: {class: "py-2"}
|
50
|
+
} do |greeter| %>
|
51
|
+
<%# `greeter` is the root element and exposes methods to generate stimulus targets and actions %>
|
52
|
+
<input type="text"
|
53
|
+
<%= greeter.as_target(:name) %>
|
54
|
+
class="shadow appearance-none border rounded py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
|
55
|
+
|
56
|
+
<%# Render the slot %>
|
57
|
+
<%= trigger %>
|
58
|
+
|
59
|
+
<%# you can also use the `target_tag` helper to render targets %>
|
60
|
+
<%= greeter.target_tag(
|
61
|
+
:span,
|
62
|
+
:output,
|
63
|
+
# Stimulus named classes can be referenced to set class attributes at render time
|
64
|
+
class: "ml-4 #{greeter.named_classes(:pre_click)}"
|
65
|
+
) do %>
|
66
|
+
...
|
67
|
+
<% end %>
|
68
|
+
<% end %>
|
69
|
+
```
|
70
|
+
|
71
|
+
Now, imagine we render it in a view, and render a `ButtonComponent` in the `trigger` slot:
|
72
|
+
|
73
|
+
```erb
|
74
|
+
<%= render ::GreeterComponent.new(cta: "Hey!", html_options: {class: "my-4"}) do |greeter| %>
|
75
|
+
<%# this component has a slot called `trigger` that renders a `ButtonComponent` (which also uses Vident) %>
|
76
|
+
<% greeter.with_trigger(
|
77
|
+
|
78
|
+
# The button component has attributes that are typed
|
79
|
+
before_clicked: "Greet",
|
80
|
+
after_clicked: "Greeted! Reset?",
|
81
|
+
|
82
|
+
# A stimulus action is added to the button that triggers the `greet` action on the greeter stimulus controller.
|
83
|
+
# This action will be added to any defined on the button component itself
|
84
|
+
actions: [
|
85
|
+
greeter.action(:click, :greet),
|
86
|
+
],
|
87
|
+
|
88
|
+
# We can also override the default button classes of our component, or set other HTML attributes
|
89
|
+
html_options: {
|
90
|
+
class: "bg-red-500 hover:bg-red-700"
|
91
|
+
}
|
92
|
+
) %>
|
93
|
+
<% end %>
|
94
|
+
```
|
95
|
+
|
96
|
+
The output HTML of the above, using Vident, is:
|
97
|
+
|
98
|
+
```html
|
99
|
+
<div class="greeter-component py-2 my-4"
|
100
|
+
data-controller="greeter-component"
|
101
|
+
data-greeter-component-pre-click-class="text-md text-gray-500"
|
102
|
+
data-greeter-component-post-click-class="text-xl text-blue-700"
|
103
|
+
id="greeter-component-1599855-6">
|
104
|
+
<input type="text"
|
105
|
+
data-greeter-component-target="name"
|
106
|
+
class="shadow appearance-none border rounded py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
|
107
|
+
<button class="button-component ml-4 whitespace-no-wrap bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded bg-red-500 hover:bg-red-700"
|
108
|
+
data-controller="button-component"
|
109
|
+
data-action="click->greeter-component#greet button-component#changeMessage"
|
110
|
+
data-button-component-after-clicked-message="Greeted! Reset?"
|
111
|
+
data-button-component-before-clicked-message="Greet"
|
112
|
+
id="button-component-7799479-7">Hey!</button>
|
113
|
+
<!-- you can also use the `target_tag` helper to render targets -->
|
114
|
+
<span class="ml-4 text-md text-gray-500"
|
115
|
+
data-greeter-component-target="output">
|
116
|
+
...
|
117
|
+
</span>
|
118
|
+
</div>
|
119
|
+
```
|
120
|
+
|
121
|
+
To see this example in more detail, see the [vident-typed-view_component](https://github.com/stevegeek/vident-typed-view_component/tree/main/test/dummy/app/components) test dummy app.
|
21
122
|
|
22
123
|
# Vident is a collection of gems
|
23
124
|
|
data/lib/vident/base.rb
CHANGED
@@ -80,6 +80,11 @@ module Vident
|
|
80
80
|
@id.presence || random_id
|
81
81
|
end
|
82
82
|
|
83
|
+
# If connecting an outlet to this specific component instance, use this ID
|
84
|
+
def outlet_id
|
85
|
+
@outlet_id ||= [stimulus_identifier, "##{id}"]
|
86
|
+
end
|
87
|
+
|
83
88
|
# Methods to use in component views
|
84
89
|
# ---------------------------------
|
85
90
|
|
@@ -145,6 +150,7 @@ module Vident
|
|
145
150
|
) + Array.wrap(options[:controllers]) + attribute(:controllers),
|
146
151
|
actions: attribute(:actions) + Array.wrap(options[:actions]),
|
147
152
|
targets: attribute(:targets) + Array.wrap(options[:targets]),
|
153
|
+
outlets: attribute(:outlets) + Array.wrap(options[:outlets]),
|
148
154
|
named_classes: merge_stimulus_option(options, :named_classes),
|
149
155
|
data_maps: prepare_stimulus_option(options, :data_maps)
|
150
156
|
}
|
@@ -184,7 +190,7 @@ module Vident
|
|
184
190
|
end
|
185
191
|
|
186
192
|
def random_id
|
187
|
-
@random_id ||= "#{
|
193
|
+
@random_id ||= "#{component_class_name}-#{StableId.next_id_in_sequence}"
|
188
194
|
end
|
189
195
|
|
190
196
|
CLASSNAME_SEPARATOR = " "
|
data/lib/vident/component.rb
CHANGED
@@ -16,6 +16,7 @@ module Vident
|
|
16
16
|
attribute :controllers, default: [], delegates: false
|
17
17
|
attribute :actions, default: [], delegates: false
|
18
18
|
attribute :targets, default: [], delegates: false
|
19
|
+
attribute :outlets, default: [], delegates: false
|
19
20
|
attribute :data_maps, default: [], delegates: false
|
20
21
|
attribute :named_classes, delegates: false
|
21
22
|
end
|
@@ -6,6 +6,7 @@ module Vident
|
|
6
6
|
controllers: nil,
|
7
7
|
actions: nil,
|
8
8
|
targets: nil,
|
9
|
+
outlets: nil,
|
9
10
|
named_classes: nil, # https://stimulus.hotwired.dev/reference/css-classes
|
10
11
|
data_maps: nil,
|
11
12
|
element_tag: nil,
|
@@ -18,6 +19,7 @@ module Vident
|
|
18
19
|
@controllers = Array.wrap(controllers)
|
19
20
|
@actions = actions
|
20
21
|
@targets = targets
|
22
|
+
@outlets = outlets
|
21
23
|
@named_classes = named_classes
|
22
24
|
@data_map_kvs = {}
|
23
25
|
@data_maps = data_maps
|
@@ -123,11 +125,29 @@ module Vident
|
|
123
125
|
def tag_data_attributes
|
124
126
|
{controller: controller_list(@controllers), action: action_list(@actions)}
|
125
127
|
.merge!(target_list)
|
128
|
+
.merge!(outlet_list)
|
126
129
|
.merge!(named_classes_list)
|
127
130
|
.merge!(data_map_attributes)
|
128
131
|
.compact_blank!
|
129
132
|
end
|
130
133
|
|
134
|
+
def outlet_list
|
135
|
+
return {} unless @outlets&.size&.positive?
|
136
|
+
|
137
|
+
@outlets.each_with_object({}) do |outlet_config, obj|
|
138
|
+
identifier, css_selector = if outlet_config.is_a?(String)
|
139
|
+
[outlet_config, "[data-controller~=#{outlet_config}]"]
|
140
|
+
elsif outlet_config.is_a?(Array)
|
141
|
+
outlet_config[..1]
|
142
|
+
elsif respond_to?(:stimulus_identifier)
|
143
|
+
[outlet_config.stimulus_identifier, "[data-controller~=#{outlet_config.stimulus_identifier}]"]
|
144
|
+
else
|
145
|
+
raise ArgumentError, "Invalid outlet config: #{outlet_config}"
|
146
|
+
end
|
147
|
+
obj[:"#{implied_controller_name}-#{identifier}-outlet"] = css_selector
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
131
151
|
# Actions can be specified as a symbol, in which case they imply an action on the primary
|
132
152
|
# controller, or as a string in which case it implies an action that is already fully qualified
|
133
153
|
# stimulus action.
|
@@ -173,7 +193,7 @@ module Vident
|
|
173
193
|
end
|
174
194
|
|
175
195
|
def build_target_data_attributes(targets)
|
176
|
-
targets.map { |t| ["#{t[:controller]}-target"
|
196
|
+
targets.map { |t| [:"#{t[:controller]}-target", t[:name]] }.to_h
|
177
197
|
end
|
178
198
|
|
179
199
|
def parse_actions(actions)
|
@@ -181,7 +201,7 @@ module Vident
|
|
181
201
|
end
|
182
202
|
|
183
203
|
def parse_attributes(attrs, controller = nil)
|
184
|
-
attrs.transform_keys { |k| "#{controller || implied_controller_name}-#{k}" }
|
204
|
+
attrs.transform_keys { |k| :"#{controller || implied_controller_name}-#{k}" }
|
185
205
|
end
|
186
206
|
|
187
207
|
def data_map_attributes
|
@@ -211,7 +231,7 @@ module Vident
|
|
211
231
|
|
212
232
|
def build_named_classes_data_attributes(named_classes)
|
213
233
|
parse_named_classes_hash(named_classes)
|
214
|
-
.map { |c| ["#{c[:controller]}-#{c[:name]}-class", c[:classes]] }
|
234
|
+
.map { |c| [:"#{c[:controller]}-#{c[:name]}-class", c[:classes]] }
|
215
235
|
.to_h
|
216
236
|
end
|
217
237
|
|
data/lib/vident/stable_id.rb
CHANGED
@@ -1,23 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "random/formatter"
|
4
|
+
|
3
5
|
module Vident
|
4
6
|
class StableId
|
5
7
|
class << self
|
6
8
|
def set_current_sequence_generator
|
7
9
|
::Thread.current[:vident_number_sequence_generator] = id_sequence_generator
|
8
10
|
end
|
11
|
+
alias_method :new_current_sequence_generator, :set_current_sequence_generator
|
12
|
+
|
13
|
+
def clear_current_sequence_generator
|
14
|
+
::Thread.current[:vident_number_sequence_generator] = nil
|
15
|
+
end
|
9
16
|
|
10
17
|
def next_id_in_sequence
|
11
18
|
generator = ::Thread.current[:vident_number_sequence_generator]
|
12
|
-
|
19
|
+
# When no generator exists, use a random value. This means we loose the stability of the ID sequence but
|
20
|
+
# at least generate unique IDs for the current render.
|
21
|
+
return Random.hex(16) unless generator
|
13
22
|
generator.next.join("-")
|
14
23
|
end
|
15
24
|
|
16
25
|
private
|
17
26
|
|
18
27
|
def id_sequence_generator
|
19
|
-
number_generator = Random.new(
|
20
|
-
Enumerator.produce { number_generator.
|
28
|
+
number_generator = Random.new(42)
|
29
|
+
Enumerator.produce { number_generator.hex(16) }.with_index
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
data/lib/vident/version.rb
CHANGED
data/sig/vident.rbs
ADDED
data/vident.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/vident/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "vident"
|
7
|
+
spec.version = Vident::VERSION
|
8
|
+
spec.authors = ["Stephen Ierodiaconou"]
|
9
|
+
spec.email = ["stevegeek@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Vident is the base of your design system implementation, which provides helpers for working with Stimulus. For component libraries with ViewComponent or Phlex."
|
12
|
+
spec.description = "Vident makes using Stimulus with your `ViewComponent` or `Phlex` view components as easy as writing Ruby. Vident is the base of your design system implementation, which provides helpers for working with Stimulus. For component libraries with ViewComponent or Phlex."
|
13
|
+
spec.homepage = "https://github.com/stevegeek/vident"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = spec.homepage + "/blob/main/CHANGELOG.md"
|
20
|
+
|
21
|
+
spec.files = Dir.chdir(__dir__) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
(File.expand_path(f) == __FILE__) ||
|
24
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ examples/ docs/ .git .github appveyor Gemfile])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.add_dependency "railties", ">= 7", "< 8.0"
|
29
|
+
spec.add_dependency "activesupport", ">= 7", "< 8.0"
|
30
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vident
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Ierodiaconou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '7'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '8'
|
22
|
+
version: '8.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,27 @@ dependencies:
|
|
29
29
|
version: '7'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '8'
|
32
|
+
version: '8.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activesupport
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '7'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '8.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '7'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '8.0'
|
33
53
|
description: Vident makes using Stimulus with your `ViewComponent` or `Phlex` view
|
34
54
|
components as easy as writing Ruby. Vident is the base of your design system implementation,
|
35
55
|
which provides helpers for working with Stimulus. For component libraries with ViewComponent
|
@@ -40,6 +60,11 @@ executables: []
|
|
40
60
|
extensions: []
|
41
61
|
extra_rdoc_files: []
|
42
62
|
files:
|
63
|
+
- ".ruby-version"
|
64
|
+
- ".standard.yml"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- LICENSE.txt
|
43
68
|
- README.md
|
44
69
|
- Rakefile
|
45
70
|
- lib/tasks/vident_tasks.rake
|
@@ -52,6 +77,8 @@ files:
|
|
52
77
|
- lib/vident/root_component.rb
|
53
78
|
- lib/vident/stable_id.rb
|
54
79
|
- lib/vident/version.rb
|
80
|
+
- sig/vident.rbs
|
81
|
+
- vident.gemspec
|
55
82
|
homepage: https://github.com/stevegeek/vident
|
56
83
|
licenses:
|
57
84
|
- MIT
|
@@ -74,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
101
|
- !ruby/object:Gem::Version
|
75
102
|
version: '0'
|
76
103
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
104
|
+
rubygems_version: 3.5.3
|
78
105
|
signing_key:
|
79
106
|
specification_version: 4
|
80
107
|
summary: Vident is the base of your design system implementation, which provides helpers
|