vident 0.7.0 → 0.8.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 +51 -28
- data/Rakefile +1 -12
- data/lib/tasks/vident_tasks.rake +4 -0
- data/lib/vident/attributes/not_typed.rb +3 -0
- data/lib/vident/base.rb +8 -29
- data/lib/vident/component.rb +0 -2
- data/lib/vident/engine.rb +15 -0
- data/lib/vident/root_component.rb +235 -0
- data/lib/vident/version.rb +1 -1
- data/lib/vident.rb +3 -36
- metadata +11 -30
- data/.standard.yml +0 -3
- data/CHANGELOG.md +0 -79
- data/CODE_OF_CONDUCT.md +0 -84
- data/Gemfile +0 -35
- data/LICENSE.txt +0 -21
- data/examples/avatar.png +0 -0
- data/examples/ex1.gif +0 -0
- data/lib/tasks/vident.rake +0 -37
- data/lib/vident/attributes/typed.rb +0 -229
- data/lib/vident/attributes/typed_niling_struct.rb +0 -27
- data/lib/vident/attributes/types.rb +0 -16
- data/lib/vident/caching/cache_key.rb +0 -144
- data/lib/vident/railtie.rb +0 -10
- data/lib/vident/root_component/base.rb +0 -237
- data/lib/vident/root_component/using_better_html.rb +0 -41
- data/lib/vident/root_component/using_phlex_html.rb +0 -50
- data/lib/vident/root_component/using_view_component.rb +0 -51
- data/lib/vident/tailwind.rb +0 -12
- data/lib/vident/test_case.rb +0 -8
- data/lib/vident/testing/attributes_tester.rb +0 -176
- data/lib/vident/testing/auto_test.rb +0 -70
- data/lib/vident/typed_component.rb +0 -48
- data/sig/vident.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6907ba81655f5cf18c500edcdfa43c8786d8b2463573a1dadd0dd51ba1637ea3
|
4
|
+
data.tar.gz: 72964008e3a0c64172726f4edfe2ba030f66018a08713e8bad529eae4dda45d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dea9a3d4e70478870b829fe050cfbbcd89dad15866a4a4334d8661d217f56e30a47b81285f279008bfaf762a406e7356ca33d56c607e98a34ddde6b2bf26df13
|
7
|
+
data.tar.gz: ea963a8ba620e0c510c8e4fadf02eb0293159398c576dbd9554bffc01fd7bb930e7b9d31e2011710ab7a4c41a2929a2e8964cceee2bdfe35827a8dedcad148b4
|
data/README.md
CHANGED
@@ -1,20 +1,30 @@
|
|
1
1
|
# Vident
|
2
2
|
|
3
|
-
Vident
|
3
|
+
**Vident** is a collection of gems that help you create **flexible** & **maintainable** component libraries for your Rails application.
|
4
4
|
|
5
|
-
|
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>
|
6
|
+
|
7
|
+
Vident also provides a neat Ruby DSL to make wiring up **Stimulus easier & less error prone** in your view components.
|
8
|
+
|
9
|
+
[`ViewComponent`](https://viewcomponent.org/) and [`Phlex`](https://phlex.fun) supported.
|
6
10
|
|
7
11
|
# Motivation
|
8
12
|
|
9
13
|
I love working with Stimulus, but I find manually crafting the data attributes for
|
10
14
|
targets and actions error prone and tedious. Vident aims to make this process easier
|
11
|
-
and keep me thinking in Ruby.
|
15
|
+
and keep me thinking in Ruby.
|
12
16
|
|
13
|
-
I have been using Vident with `ViewComponent` in production apps for a while now and
|
14
|
-
evolving.
|
17
|
+
I have been using Vident with `ViewComponent` in production apps for a while now (and recently `Phlex`!)
|
18
|
+
and it has been constantly evolving.
|
15
19
|
|
16
20
|
This gem is a work in progress and I would love to get your feedback and contributions!
|
17
21
|
|
22
|
+
|
23
|
+
|
24
|
+
**The docs below need updating**
|
25
|
+
|
26
|
+
|
27
|
+
|
18
28
|
## What does Vident provide?
|
19
29
|
|
20
30
|
- `Vident::Component`: A mixin for your `ViewComponent` components or `Phlex` components that provides the a helper to create the
|
@@ -25,7 +35,7 @@ This gem is a work in progress and I would love to get your feedback and contrib
|
|
25
35
|
### Various utilities
|
26
36
|
|
27
37
|
- `Vident::Tailwind`: a mixin for your vident component which uses [tailwind_merge](https://github.com/gjtorikian/tailwind_merge) to merge TailwindCSS classes
|
28
|
-
so you can easily override classes when rendering a component.
|
38
|
+
so you can easily override classes when rendering a component.
|
29
39
|
|
30
40
|
- `Vident::Caching::CacheKey`: a mixin for your vident component which provides a `cache_key` method that can be used to generate a cache key for
|
31
41
|
fragment caching or etag generation.
|
@@ -40,7 +50,7 @@ This gem is a work in progress and I would love to get your feedback and contrib
|
|
40
50
|
- Component arguments are defined using the `attribute` method which allows you to define default values, (optionally) types and
|
41
51
|
if blank or nil values should be allowed.
|
42
52
|
- You can use the same component in multiple contexts and configure the root element differently in each context by passing
|
43
|
-
options to the component when instantiating it.
|
53
|
+
options to the component when instantiating it.
|
44
54
|
- Stimulus support is built in and sets a default controller name based on the component name.
|
45
55
|
- Stimulus actions, targets and classes can be setup using a simple DSL to avoid hand crafting the data attributes.
|
46
56
|
- Since data attribute names are generated from the component class name, you can rename easily refactor and move components without
|
@@ -61,10 +71,10 @@ This is a work in progress. Here's what's left to do for first release:
|
|
61
71
|
- Add tests
|
62
72
|
- Make the gem more configurable to fit more use cases
|
63
73
|
- Create an example library of a few components for some design system
|
64
|
-
|
74
|
+
- Create a demo app with `lookbook` and those components
|
65
75
|
- Add more documentation
|
66
76
|
- split `vident` into `vident` + `vident-rails` gems (and maybe `vident-rspec`) (Phlex can be used outside of Rails)
|
67
|
-
|
77
|
+
- possibly also split into `vident-phlex` and `vident-view_component` gems ?
|
68
78
|
|
69
79
|
|
70
80
|
|
@@ -89,9 +99,9 @@ and visit http://localhost:3000
|
|
89
99
|
|
90
100
|
## A Vident component example (without Stimulus)
|
91
101
|
|
92
|
-
First is an example component that uses `Vident::TypedComponent` but no Stimulus features.
|
102
|
+
First is an example component that uses `Vident::TypedComponent` but no Stimulus features.
|
93
103
|
|
94
|
-
It is an avatar component that can either be displayed as an image or as initials.
|
104
|
+
It is an avatar component that can either be displayed as an image or as initials.
|
95
105
|
|
96
106
|
It supports numerous sizes and shapes and can optionally have a border. It also generates a cache key for use in fragment caching or etag generation.
|
97
107
|
|
@@ -420,31 +430,44 @@ export default class extends Controller {
|
|
420
430
|
|
421
431
|
## Installation
|
422
432
|
|
423
|
-
|
433
|
+
This gem (`vident`) provides only base functionality but there are a number of gems that provide additional functionality
|
434
|
+
or a "out of the box" experience.
|
424
435
|
|
425
|
-
|
426
|
-
|
427
|
-
```
|
436
|
+
It's a "pick your own adventure" approach. You decide what frameworks and features you want to use
|
437
|
+
and add the gems as needed.
|
428
438
|
|
429
|
-
|
439
|
+
Start by asking yorself these questions:
|
430
440
|
|
431
|
-
|
432
|
-
gem 'view_component'
|
433
|
-
```
|
441
|
+
_Q1. Do you want to use [`ViewComponent`](https://viewcomponent.org/) or [`Phlex`](https://www.phlex.fun/) for your view components?_
|
434
442
|
|
435
|
-
or
|
443
|
+
_Q2. Do you want to use attributes with runtime type checking (powered by [`dry-types`](https://github.com/dry-rb/dry-types)), or not?_
|
436
444
|
|
437
|
-
|
438
|
-
|
439
|
-
```
|
445
|
+
Depending on your answer to Q1, you can choose from either the `*-view_component` or `*-phlex` gems,
|
446
|
+
then depending on your answer to Q2, you can choose from either the untyped or `*-typed-*` gems.
|
440
447
|
|
441
|
-
or
|
448
|
+
Note you can also use some or all of them in the same app.
|
442
449
|
|
443
|
-
|
450
|
+
- [`vident-view_component`](https://github.com/stevegeek/vident-view_component) for using with `ViewComponent` and untyped attributes
|
451
|
+
- [`vident-typed-view_component`](https://github.com/stevegeek/vident-typed-view_component) for using with `ViewComponent` and typed attributes
|
452
|
+
- [`vident-phlex`](https://github.com/stevegeek/vident-phlex) for using with `Phlex` and untyped attributes
|
453
|
+
- [`vident-typed-phlex`](https://github.com/stevegeek/vident-typed-phlex) for using with `Phlex` and typed attributes
|
454
|
+
|
455
|
+
_Q3. Do you use or want to use [BetterHTML](https://github.com/Shopify/better-html) in your Rails project?_
|
456
|
+
|
457
|
+
If yes, then include [`vident-better_html`](https://github.com/stevegeek/vident-better_html) in your Gemfile alongside `better_html` and your vident gems of choice.
|
458
|
+
Note that `vident-better_html` automatically enables `better_html` support in Vident root components.
|
459
|
+
|
460
|
+
_Q4. Do you use or want to use [TailwindCSS](https://tailwindcss.com/)?_
|
461
|
+
|
462
|
+
If yes, then consider adding [`vident-tailwind`](https://github.com/stevegeek/vident-tailwind) to your Gemfile alongside your vident gems of choice. When creating
|
463
|
+
your components you can then include `Vident::Tailwind` to get all the benefits of the amazing [`tailwind_merge`](https://github.com/gjtorikian/tailwind_merge/).
|
464
|
+
|
465
|
+
Finally if none of the above gems suit your needs, you can always just use base `vident` gems to roll your own
|
466
|
+
solution:
|
467
|
+
|
468
|
+
- [`vident`](https://github.com/stevegeek/vident) to get the base functionality to mix with your own view component system
|
469
|
+
- [`vident-typed`](https://github.com/stevegeek/vident-typed) to define typed attributes for your own view component system
|
444
470
|
|
445
|
-
```ruby
|
446
|
-
gem 'dry-struct'
|
447
|
-
```
|
448
471
|
|
449
472
|
And then execute:
|
450
473
|
|
data/Rakefile
CHANGED
@@ -1,14 +1,3 @@
|
|
1
|
-
|
1
|
+
require "bundler/setup"
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
|
-
require "rake/testtask"
|
5
|
-
|
6
|
-
Rake::TestTask.new(:test) do |t|
|
7
|
-
t.libs << "test"
|
8
|
-
t.libs << "lib"
|
9
|
-
t.test_files = FileList["test/**/*_test.rb"]
|
10
|
-
end
|
11
|
-
|
12
|
-
require "standard/rake"
|
13
|
-
|
14
|
-
task default: %i[test standard]
|
@@ -15,6 +15,7 @@ module Vident
|
|
15
15
|
options = self.class.attribute_options
|
16
16
|
default = options&.dig(attr_name, :default)
|
17
17
|
allow_nil = options[attr_name] ? options[attr_name].fetch(:allow_nil, true) : true
|
18
|
+
|
18
19
|
if attributes&.include? attr_name
|
19
20
|
value = attributes[attr_name]
|
20
21
|
@__attributes[attr_name] = (value.nil? && default) ? default : value
|
@@ -41,6 +42,8 @@ module Vident
|
|
41
42
|
class_methods do
|
42
43
|
def inherited(subclass)
|
43
44
|
subclass.instance_variable_set(:@attribute_ivar_names, @attribute_ivar_names.clone)
|
45
|
+
subclass.instance_variable_set(:@attribute_names, @attribute_names.clone)
|
46
|
+
subclass.instance_variable_set(:@attribute_options, @attribute_options.clone)
|
44
47
|
super
|
45
48
|
end
|
46
49
|
|
data/lib/vident/base.rb
CHANGED
@@ -33,15 +33,7 @@ module Vident
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def identifier_name_path
|
36
|
-
|
37
|
-
name.remove("Views::").underscore
|
38
|
-
else
|
39
|
-
name.underscore
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def phlex_component?
|
44
|
-
@phlex_component ||= ancestors.map(&:name).include?("Phlex::HTML")
|
36
|
+
name.underscore
|
45
37
|
end
|
46
38
|
|
47
39
|
private
|
@@ -52,7 +44,7 @@ module Vident
|
|
52
44
|
def #{attr_name}
|
53
45
|
#{@attribute_ivar_names[attr_name]}
|
54
46
|
end
|
55
|
-
|
47
|
+
|
56
48
|
def #{attr_name}?
|
57
49
|
#{@attribute_ivar_names[attr_name]}.present?
|
58
50
|
end
|
@@ -95,25 +87,6 @@ module Vident
|
|
95
87
|
|
96
88
|
# HTML and attribute definition and creation
|
97
89
|
|
98
|
-
# Helper to create the main element
|
99
|
-
def parent_element(**options)
|
100
|
-
@parent_element ||= begin
|
101
|
-
# Note: we cant mix phlex and view_component render contexts
|
102
|
-
klass = if self.class.phlex_component?
|
103
|
-
RootComponent::UsingPhlexHTML
|
104
|
-
else
|
105
|
-
RootComponent::UsingViewComponent
|
106
|
-
end
|
107
|
-
element_attrs = options
|
108
|
-
.except(:id, :element_tag, :html_options, :controller, :controllers, :actions, :targets, :named_classes, :data_maps)
|
109
|
-
.merge(
|
110
|
-
stimulus_options_for_component(options)
|
111
|
-
)
|
112
|
-
klass.new(**element_attrs)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
alias_method :root, :parent_element
|
116
|
-
|
117
90
|
# FIXME: if we call them before `root` we will setup the root element before we intended
|
118
91
|
# The separation between component and root element is a bit messy. Might need rethinking.
|
119
92
|
delegate :action, :target, :named_classes, to: :root
|
@@ -155,6 +128,12 @@ module Vident
|
|
155
128
|
|
156
129
|
private
|
157
130
|
|
131
|
+
def parent_element_attributes(options)
|
132
|
+
options
|
133
|
+
.except(:id, :element_tag, :html_options, :controller, :controllers, :actions, :targets, :named_classes, :data_maps)
|
134
|
+
.merge(stimulus_options_for_component(options))
|
135
|
+
end
|
136
|
+
|
158
137
|
# Prepare the stimulus attributes for a StimulusComponent
|
159
138
|
def stimulus_options_for_component(options)
|
160
139
|
{
|
data/lib/vident/component.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Vident
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
lib_path = File.expand_path("../../../lib/", __FILE__)
|
4
|
+
config.autoload_paths << lib_path
|
5
|
+
config.eager_load_paths << lib_path
|
6
|
+
|
7
|
+
config.before_initialize do
|
8
|
+
Rails.autoloaders.each do |autoloader|
|
9
|
+
autoloader.inflector.inflect(
|
10
|
+
"version" => "VERSION"
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,235 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Vident
|
4
|
+
module RootComponent
|
5
|
+
def initialize(
|
6
|
+
controllers: nil,
|
7
|
+
actions: nil,
|
8
|
+
targets: nil,
|
9
|
+
named_classes: nil, # https://stimulus.hotwired.dev/reference/css-classes
|
10
|
+
data_maps: nil,
|
11
|
+
element_tag: nil,
|
12
|
+
id: nil,
|
13
|
+
html_options: nil
|
14
|
+
)
|
15
|
+
@element_tag = element_tag
|
16
|
+
@html_options = html_options
|
17
|
+
@id = id
|
18
|
+
@controllers = Array.wrap(controllers)
|
19
|
+
@actions = actions
|
20
|
+
@targets = targets
|
21
|
+
@named_classes = named_classes
|
22
|
+
@data_map_kvs = {}
|
23
|
+
@data_maps = data_maps
|
24
|
+
end
|
25
|
+
|
26
|
+
# The view component's helpers for setting stimulus data-* attributes on this component.
|
27
|
+
|
28
|
+
# TODO: rename
|
29
|
+
# Create a Stimulus action string, and returns it
|
30
|
+
# examples:
|
31
|
+
# action(:my_thing) => "current_controller#myThing"
|
32
|
+
# action(:click, :my_thing) => "click->current_controller#myThing"
|
33
|
+
# action("click->current_controller#myThing") => "click->current_controller#myThing"
|
34
|
+
# action("path/to/current", :my_thing) => "path--to--current_controller#myThing"
|
35
|
+
# action(:click, "path/to/current", :my_thing) => "click->path--to--current_controller#myThing"
|
36
|
+
def action(*args)
|
37
|
+
part1, part2, part3 = args
|
38
|
+
(args.size == 1) ? parse_action_arg(part1) : parse_multiple_action_args(part1, part2, part3)
|
39
|
+
end
|
40
|
+
|
41
|
+
def action_data_attribute(*actions)
|
42
|
+
{action: parse_actions(actions).join(" ")}
|
43
|
+
end
|
44
|
+
|
45
|
+
# TODO: rename & make stimulus Target class instance and returns it, which can convert to String
|
46
|
+
# Create a Stimulus Target and returns it
|
47
|
+
# examples:
|
48
|
+
# target(:my_target) => {controller: 'current_controller' name: 'myTarget'}
|
49
|
+
# target("path/to/current", :my_target) => {controller: 'path--to--current_controller', name: 'myTarget'}
|
50
|
+
def target(name, part2 = nil)
|
51
|
+
if part2.nil?
|
52
|
+
{controller: implied_controller_name, name: js_name(name)}
|
53
|
+
else
|
54
|
+
{controller: stimulize_path(name), name: js_name(part2)}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def target_data_attribute(name)
|
59
|
+
build_target_data_attributes([target(name)])
|
60
|
+
end
|
61
|
+
|
62
|
+
# Getter for a named classes list so can be used in view to set initial state on SSR
|
63
|
+
# Returns a String of classes that can be used in a `class` attribute.
|
64
|
+
def named_classes(*names)
|
65
|
+
names.map { |name| convert_classes_list_to_string(@named_classes[name]) }.join(" ")
|
66
|
+
end
|
67
|
+
|
68
|
+
# Helpers for generating the Stimulus data-* attributes directly
|
69
|
+
|
70
|
+
# Return the HTML `data-controller` attribute for the given controllers
|
71
|
+
def with_controllers(*controllers_to_set)
|
72
|
+
"data-controller=\"#{controller_list(controllers_to_set)}\"".html_safe
|
73
|
+
end
|
74
|
+
|
75
|
+
# Return the HTML `data-target` attribute for the given targets
|
76
|
+
def as_targets(*targets)
|
77
|
+
attrs = build_target_data_attributes(parse_targets(targets))
|
78
|
+
attrs.map { |dt, n| "data-#{dt}=\"#{n}\"" }.join(" ").html_safe
|
79
|
+
end
|
80
|
+
alias_method :as_target, :as_targets
|
81
|
+
|
82
|
+
# Return the HTML `data-action` attribute for the given actions
|
83
|
+
def with_actions(*actions_to_set)
|
84
|
+
"data-action='#{parse_actions(actions_to_set).join(" ")}'".html_safe
|
85
|
+
end
|
86
|
+
alias_method :with_action, :with_actions
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
# An implicit Stimulus controller name is built from the implicit controller path
|
91
|
+
def implied_controller_name
|
92
|
+
stimulize_path(implied_controller_path)
|
93
|
+
end
|
94
|
+
|
95
|
+
# When using the DSL if you dont specify, the first controller is implied
|
96
|
+
def implied_controller_path
|
97
|
+
@controllers&.first || raise(StandardError, "No controllers have been specified")
|
98
|
+
end
|
99
|
+
|
100
|
+
# A complete list of Stimulus controllers for this component
|
101
|
+
def controller_list(controllers_to_set)
|
102
|
+
controllers_to_set&.map { |c| stimulize_path(c) }&.join(" ")
|
103
|
+
end
|
104
|
+
|
105
|
+
# Complete list of actions ready to be use in the data-action attribute
|
106
|
+
def action_list(actions_to_parse)
|
107
|
+
return nil unless actions_to_parse&.size&.positive?
|
108
|
+
parse_actions(actions_to_parse).join(" ")
|
109
|
+
end
|
110
|
+
|
111
|
+
# Complete list of targets ready to be use in the data attributes
|
112
|
+
def target_list
|
113
|
+
return {} unless @targets&.size&.positive?
|
114
|
+
build_target_data_attributes(parse_targets(@targets))
|
115
|
+
end
|
116
|
+
|
117
|
+
def named_classes_list
|
118
|
+
return {} unless @named_classes&.size&.positive?
|
119
|
+
build_named_classes_data_attributes(@named_classes)
|
120
|
+
end
|
121
|
+
|
122
|
+
# stimulus "data-*" attributes map for this component
|
123
|
+
def tag_data_attributes
|
124
|
+
{controller: controller_list(@controllers), action: action_list(@actions)}
|
125
|
+
.merge!(target_list)
|
126
|
+
.merge!(named_classes_list)
|
127
|
+
.merge!(data_map_attributes)
|
128
|
+
.compact_blank!
|
129
|
+
end
|
130
|
+
|
131
|
+
# Actions can be specified as a symbol, in which case they imply an action on the primary
|
132
|
+
# controller, or as a string in which case it implies an action that is already fully qualified
|
133
|
+
# stimulus action.
|
134
|
+
# 1 Symbol: :my_action => "my_controller#myAction"
|
135
|
+
# 1 String: "my_controller#myAction"
|
136
|
+
# 2 Symbols: [:click, :my_action] => "click->my_controller#myAction"
|
137
|
+
# 1 String, 1 Symbol: ["path/to/controller", :my_action] => "path--to--controller#myAction"
|
138
|
+
# 1 Symbol, 1 String, 1 Symbol: [:hover, "path/to/controller", :my_action] => "hover->path--to--controller#myAction"
|
139
|
+
|
140
|
+
def parse_action_arg(part1)
|
141
|
+
if part1.is_a?(Symbol)
|
142
|
+
# 1 symbol arg, name of method on this controller
|
143
|
+
"#{implied_controller_name}##{js_name(part1)}"
|
144
|
+
elsif part1.is_a?(String)
|
145
|
+
# 1 string arg, fully qualified action
|
146
|
+
part1
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def parse_multiple_action_args(part1, part2, part3)
|
151
|
+
if part3.nil? && part1.is_a?(Symbol)
|
152
|
+
# 2 symbol args = event + action
|
153
|
+
"#{part1}->#{implied_controller_name}##{js_name(part2)}"
|
154
|
+
elsif part3.nil?
|
155
|
+
# 1 string arg, 1 symbol = controller + action
|
156
|
+
"#{stimulize_path(part1)}##{js_name(part2)}"
|
157
|
+
else
|
158
|
+
# 1 symbol, 1 string, 1 symbol = as above but with event
|
159
|
+
"#{part1}->#{stimulize_path(part2)}##{js_name(part3)}"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# Parse actions, targets and attributes that are passed in as symbols or strings
|
164
|
+
|
165
|
+
def parse_targets(targets)
|
166
|
+
targets.map { |n| parse_target(n) }
|
167
|
+
end
|
168
|
+
|
169
|
+
def parse_target(raw_target)
|
170
|
+
return raw_target if raw_target.is_a?(String)
|
171
|
+
return raw_target if raw_target.is_a?(Hash)
|
172
|
+
target(raw_target)
|
173
|
+
end
|
174
|
+
|
175
|
+
def build_target_data_attributes(targets)
|
176
|
+
targets.map { |t| ["#{t[:controller]}-target".to_sym, t[:name]] }.to_h
|
177
|
+
end
|
178
|
+
|
179
|
+
def parse_actions(actions)
|
180
|
+
actions.map! { |a| a.is_a?(String) ? a : action(*a) }
|
181
|
+
end
|
182
|
+
|
183
|
+
def parse_attributes(attrs, controller = nil)
|
184
|
+
attrs.transform_keys { |k| "#{controller || implied_controller_name}-#{k}" }
|
185
|
+
end
|
186
|
+
|
187
|
+
def data_map_attributes
|
188
|
+
return {} unless @data_maps
|
189
|
+
@data_maps.each_with_object({}) do |m, obj|
|
190
|
+
if m.is_a?(Hash)
|
191
|
+
obj.merge!(parse_attributes(m))
|
192
|
+
elsif m.is_a?(Array)
|
193
|
+
controller_path = m.first
|
194
|
+
data = m.last
|
195
|
+
obj.merge!(parse_attributes(data, stimulize_path(controller_path)))
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def parse_named_classes_hash(named_classes)
|
201
|
+
named_classes.map do |name, classes|
|
202
|
+
logical_name = name.to_s.dasherize
|
203
|
+
classes_str = convert_classes_list_to_string(classes)
|
204
|
+
if classes.is_a?(Hash)
|
205
|
+
{controller: stimulize_path(classes[:controller_path]), name: logical_name, classes: classes_str}
|
206
|
+
else
|
207
|
+
{controller: implied_controller_name, name: logical_name, classes: classes_str}
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def build_named_classes_data_attributes(named_classes)
|
213
|
+
parse_named_classes_hash(named_classes)
|
214
|
+
.map { |c| ["#{c[:controller]}-#{c[:name]}-class", c[:classes]] }
|
215
|
+
.to_h
|
216
|
+
end
|
217
|
+
|
218
|
+
def convert_classes_list_to_string(classes)
|
219
|
+
return "" if classes.nil?
|
220
|
+
return classes if classes.is_a?(String)
|
221
|
+
return classes.join(" ") if classes.is_a?(Array)
|
222
|
+
classes[:classes].is_a?(Array) ? classes[:classes].join(" ") : classes[:classes]
|
223
|
+
end
|
224
|
+
|
225
|
+
# Convert a file path to a stimulus controller name
|
226
|
+
def stimulize_path(path)
|
227
|
+
path.split("/").map { |p| p.to_s.dasherize }.join("--")
|
228
|
+
end
|
229
|
+
|
230
|
+
# Convert a Ruby 'snake case' string to a JavaScript camel case strings
|
231
|
+
def js_name(name)
|
232
|
+
name.to_s.camelize(:lower)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
data/lib/vident/version.rb
CHANGED
data/lib/vident.rb
CHANGED
@@ -1,41 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require "vident/version"
|
4
|
+
require "vident/engine"
|
5
5
|
|
6
6
|
module Vident
|
7
|
-
|
8
|
-
def configuration
|
9
|
-
@configuration ||= Configuration.new
|
10
|
-
end
|
11
|
-
|
12
|
-
def configure
|
13
|
-
yield(configuration) if block_given?
|
14
|
-
configuration
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class Configuration
|
19
|
-
attr_accessor :include_i18n_helpers
|
20
|
-
|
21
|
-
def initialize
|
22
|
-
@include_i18n_helpers = true
|
23
|
-
end
|
24
|
-
end
|
7
|
+
# Your code goes here...
|
25
8
|
end
|
26
|
-
|
27
|
-
require_relative "vident/stable_id"
|
28
|
-
require_relative "vident/root_component/base"
|
29
|
-
require_relative "vident/root_component/using_better_html"
|
30
|
-
require_relative "vident/root_component/using_phlex_html"
|
31
|
-
require_relative "vident/root_component/using_view_component"
|
32
|
-
require_relative "vident/base"
|
33
|
-
require_relative "vident/component"
|
34
|
-
require_relative "vident/typed_component"
|
35
|
-
require_relative "vident/caching/cache_key"
|
36
|
-
require_relative "vident/tailwind" if Gem.loaded_specs.has_key? "tailwind_merge"
|
37
|
-
require_relative "vident/testing/attributes_tester"
|
38
|
-
require_relative "vident/testing/auto_test"
|
39
|
-
|
40
|
-
# TODO: what if not using view_component?
|
41
|
-
require_relative "vident/test_case"
|
metadata
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vident
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Ierodiaconou
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '7'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '8'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '7'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '8'
|
@@ -40,43 +40,24 @@ executables: []
|
|
40
40
|
extensions: []
|
41
41
|
extra_rdoc_files: []
|
42
42
|
files:
|
43
|
-
- ".standard.yml"
|
44
|
-
- CHANGELOG.md
|
45
|
-
- CODE_OF_CONDUCT.md
|
46
|
-
- Gemfile
|
47
|
-
- LICENSE.txt
|
48
43
|
- README.md
|
49
44
|
- Rakefile
|
50
|
-
-
|
51
|
-
- examples/ex1.gif
|
52
|
-
- lib/tasks/vident.rake
|
45
|
+
- lib/tasks/vident_tasks.rake
|
53
46
|
- lib/vident.rb
|
54
47
|
- lib/vident/attributes/not_typed.rb
|
55
|
-
- lib/vident/attributes/typed.rb
|
56
|
-
- lib/vident/attributes/typed_niling_struct.rb
|
57
|
-
- lib/vident/attributes/types.rb
|
58
48
|
- lib/vident/base.rb
|
59
|
-
- lib/vident/caching/cache_key.rb
|
60
49
|
- lib/vident/component.rb
|
61
|
-
- lib/vident/
|
62
|
-
- lib/vident/root_component
|
63
|
-
- lib/vident/root_component/using_better_html.rb
|
64
|
-
- lib/vident/root_component/using_phlex_html.rb
|
65
|
-
- lib/vident/root_component/using_view_component.rb
|
50
|
+
- lib/vident/engine.rb
|
51
|
+
- lib/vident/root_component.rb
|
66
52
|
- lib/vident/stable_id.rb
|
67
|
-
- lib/vident/tailwind.rb
|
68
|
-
- lib/vident/test_case.rb
|
69
|
-
- lib/vident/testing/attributes_tester.rb
|
70
|
-
- lib/vident/testing/auto_test.rb
|
71
|
-
- lib/vident/typed_component.rb
|
72
53
|
- lib/vident/version.rb
|
73
|
-
- sig/vident.rbs
|
74
54
|
homepage: https://github.com/stevegeek/vident
|
75
55
|
licenses:
|
76
56
|
- MIT
|
77
57
|
metadata:
|
78
58
|
homepage_uri: https://github.com/stevegeek/vident
|
79
59
|
source_code_uri: https://github.com/stevegeek/vident
|
60
|
+
changelog_uri: https://github.com/stevegeek/vident/blob/main/CHANGELOG.md
|
80
61
|
post_install_message:
|
81
62
|
rdoc_options: []
|
82
63
|
require_paths:
|
@@ -92,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
73
|
- !ruby/object:Gem::Version
|
93
74
|
version: '0'
|
94
75
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
76
|
+
rubygems_version: 3.4.6
|
96
77
|
signing_key:
|
97
78
|
specification_version: 4
|
98
79
|
summary: Vident is the base of your design system implementation, which provides helpers
|
data/.standard.yml
DELETED