vident 0.5.1 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a81f442775cc3413603ea1770059483978615f37809502245cca2f1ac8ddd868
4
- data.tar.gz: 37ce0a04d8a8e37cfdc10f5b5174f771e93ecb2c8dd8909eb58ef842866d0ae2
3
+ metadata.gz: e4d88cce5b38bd6e4c19016a7bad835cd25b8e4453284fc5795d039e7b48d145
4
+ data.tar.gz: f63eca71787e977e9204336b16f8cd32e3fa5c73ee88977ff3befdd8a5f8a33a
5
5
  SHA512:
6
- metadata.gz: ec38a1d6550386705dd6de2374d650ee890c147c9cf97cca299b01bf27616f2becccdebe273efa51153ad74ace43faef8006464a5a2418e9991ca3642fdb8dca
7
- data.tar.gz: a1b01b01507a70e276ec14b6a358c520f1bc11aca8c713fe32bb5a0091230caf9fd38e8f4ef22beed50ed8a1f72c0bb48c40cd5e10cdfaa546dafe80780af337
6
+ metadata.gz: 3845320ed4eef3e3b3919ef970e93e9ed2c09332ccf14db2224b1d98402b43471e6a543690249fb42a64b52a50f35314f05844f460c702af60c5cc8cf0bc083a
7
+ data.tar.gz: d167a0e66951777bbde64f657d97e68804ca15bc6890604e0d4015d27a4ee4b17a252574f5e0dcd5cc9f9864929f20bc24ad5689f98e1c853b7cb4da36c293a7
data/CHANGELOG.md ADDED
@@ -0,0 +1,48 @@
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
+ ## [Unreleased]
9
+
10
+ ### Added
11
+
12
+ ### Changed
13
+
14
+ ### Fixed
15
+
16
+ ## [0.6.0] - 2023-02-20
17
+
18
+ ### Added
19
+
20
+ - Experimental support for `better_html` in the root components (the stimulus attributes are generated with `html_attributes`)
21
+
22
+
23
+
24
+ ## [0.5.1] - 2023-02-17
25
+
26
+ ### Added
27
+
28
+ - N/A
29
+
30
+ ### Changed
31
+
32
+ - N/A
33
+
34
+ ### Fixed
35
+
36
+ - Typed attributes was not always using custom coercion methods if they were defined
37
+
38
+ ### Removed
39
+
40
+ - N/A
41
+
42
+ ### Deprecated
43
+
44
+ - N/A
45
+
46
+ ### Security
47
+
48
+ - N/A
data/Gemfile CHANGED
@@ -18,6 +18,7 @@ gem "stimulus-rails"
18
18
  gem "dry-struct"
19
19
 
20
20
  gem "phlex-rails"
21
+ gem "better_html"
21
22
 
22
23
  # FIXME: versions greater than 2.74 cause issues: https://github.com/ViewComponent/view_component/pull/1571
23
24
  gem "view_component", "2.74.1"
@@ -68,23 +68,21 @@ module Vident
68
68
 
69
69
  # Helpers for generating the Stimulus data-* attributes directly
70
70
 
71
- # Return the HTML `data-controller` attribute
72
- def with_controllers
73
- "data-controller='#{controller_list}'".html_safe
71
+ # Return the HTML `data-controller` attribute for the given controllers
72
+ def with_controllers(*controllers_to_set)
73
+ "data-controller=\"#{controller_list(controllers_to_set)}\"".html_safe
74
74
  end
75
75
 
76
- # Return the HTML `data-target` attribute
76
+ # Return the HTML `data-target` attribute for the given targets
77
77
  def as_targets(*targets)
78
- build_target_data_attributes(parse_targets(targets))
79
- .map { |dt, n| "data-#{dt}=\"#{n}\"" }
80
- .join(" ")
81
- .html_safe
78
+ attrs = build_target_data_attributes(parse_targets(targets))
79
+ attrs.map { |dt, n| "data-#{dt}=\"#{n}\"" }.join(" ").html_safe
82
80
  end
83
81
  alias_method :as_target, :as_targets
84
82
 
85
- # Return the HTML `data-action` attribute to add these actions
86
- def with_actions(*actions)
87
- "data-action='#{parse_actions(actions).join(" ")}'".html_safe
83
+ # Return the HTML `data-action` attribute for the given actions
84
+ def with_actions(*actions_to_set)
85
+ "data-action='#{parse_actions(actions_to_set).join(" ")}'".html_safe
88
86
  end
89
87
  alias_method :with_action, :with_actions
90
88
 
@@ -101,14 +99,14 @@ module Vident
101
99
  end
102
100
 
103
101
  # A complete list of Stimulus controllers for this component
104
- def controller_list
105
- @controllers&.map { |c| stimulize_path(c) }&.join(" ")
102
+ def controller_list(controllers_to_set)
103
+ controllers_to_set&.map { |c| stimulize_path(c) }&.join(" ")
106
104
  end
107
105
 
108
106
  # Complete list of actions ready to be use in the data-action attribute
109
- def action_list
110
- return nil unless @actions&.size&.positive?
111
- parse_actions(@actions).join(" ")
107
+ def action_list(actions_to_parse)
108
+ return nil unless actions_to_parse&.size&.positive?
109
+ parse_actions(actions_to_parse).join(" ")
112
110
  end
113
111
 
114
112
  # Complete list of targets ready to be use in the data attributes
@@ -124,7 +122,7 @@ module Vident
124
122
 
125
123
  # stimulus "data-*" attributes map for this component
126
124
  def tag_data_attributes
127
- {controller: controller_list, action: action_list}
125
+ {controller: controller_list(@controllers), action: action_list(@actions)}
128
126
  .merge!(target_list)
129
127
  .merge!(named_classes_list)
130
128
  .merge!(data_map_attributes)
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ if Gem.loaded_specs.has_key? "better_html"
4
+ require "better_html"
5
+ require "cgi/util"
6
+
7
+ module Vident
8
+ module RootComponent
9
+ module UsingBetterHTML
10
+ # Return the HTML `data-controller` attribute for the given controllers
11
+ def with_controllers(*controllers_to_set)
12
+ helpers.html_attributes("data-controller" => controller_list(controllers_to_set)&.html_safe)
13
+ end
14
+
15
+ # Return the HTML `data-target` attribute for the given targets
16
+ def as_targets(*targets)
17
+ attrs = build_target_data_attributes(parse_targets(targets))
18
+ helpers.html_attributes(attrs.transform_keys! { |k| "data-#{k}" })
19
+ end
20
+
21
+ # Return the HTML `data-action` attribute for the given actions
22
+ def with_actions(*actions_to_set)
23
+ actions_str = action_list(actions_to_set)
24
+ actions_str.present? ? helpers.html_attributes("data-action" => actions_str) : nil
25
+ end
26
+
27
+ private
28
+
29
+ # Complete list of actions ready to be use in the data-action attribute
30
+ def action_list(actions_to_parse)
31
+ return nil unless actions_to_parse&.size&.positive?
32
+ # `html_attributes` will escape '->' thus breaking the stimulus action, so we need to do our own escaping
33
+ actions_str_raw = parse_actions(actions_to_parse).join(" ")
34
+ CGI.escapeHTML(actions_str_raw).gsub("->", "->").html_safe
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -7,6 +7,9 @@ if Gem.loaded_specs.has_key? "phlex"
7
7
  module RootComponent
8
8
  class UsingPhlexHTML < Phlex::HTML
9
9
  include Base
10
+ if Gem.loaded_specs.has_key? "better_html"
11
+ include UsingBetterHTML
12
+ end
10
13
 
11
14
  VALID_TAGS = Set[*(Phlex::HTML::VOID_ELEMENTS.keys + Phlex::HTML::STANDARD_ELEMENTS.keys)].freeze
12
15
 
@@ -7,6 +7,9 @@ if Gem.loaded_specs.has_key? "view_component"
7
7
  module RootComponent
8
8
  class UsingViewComponent < ::ViewComponent::Base
9
9
  include Base
10
+ if Gem.loaded_specs.has_key? "better_html"
11
+ include UsingBetterHTML
12
+ end
10
13
 
11
14
  SELF_CLOSING_TAGS = Set[:area, :base, :br, :col, :embed, :hr, :img, :input, :link, :meta, :param, :source, :track, :wbr].freeze
12
15
 
@@ -19,25 +22,28 @@ if Gem.loaded_specs.has_key? "view_component"
19
22
  end
20
23
 
21
24
  def call
22
- # Capture inner block content
23
- # It's important that we capture the block content before generating the tag options.
24
- # This is because the content could contain calls to `s.data_map`.
25
- # These calls add key-value pairs to the internal data_map, which can then be translated into
26
- # the correct `data-*` attrs by the tag options.
27
- generated = content
28
-
29
25
  # Generate outer tag options and render
30
- tag_type = @element_tag.presence || :div
31
- options = @html_options&.dup || {}
32
- data_attrs = tag_data_attributes
33
- options[:data] = options[:data].present? ? data_attrs.merge(options[:data]) : data_attrs
34
- options = options.merge(id: @id) if @id
26
+ tag_type = content_tag_type
27
+ options = content_tag_options
35
28
  if SELF_CLOSING_TAGS.include?(tag_type)
36
29
  view_context.tag(tag_type, options)
37
30
  else
38
- view_context.content_tag(tag_type, generated, options)
31
+ view_context.content_tag(tag_type, content, options)
39
32
  end
40
33
  end
34
+
35
+ private
36
+
37
+ def content_tag_options
38
+ options = @html_options&.dup || {}
39
+ data_attrs = tag_data_attributes
40
+ options[:data] = options[:data].present? ? data_attrs.merge(options[:data]) : data_attrs
41
+ options.merge(id: @id) if @id
42
+ end
43
+
44
+ def content_tag_type
45
+ @element_tag.presence || :div
46
+ end
41
47
  end
42
48
  end
43
49
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vident
4
- VERSION = "0.5.1"
4
+ VERSION = "0.6.0"
5
5
  end
data/lib/vident.rb CHANGED
@@ -26,6 +26,7 @@ end
26
26
 
27
27
  require_relative "vident/stable_id"
28
28
  require_relative "vident/root_component/base"
29
+ require_relative "vident/root_component/using_better_html"
29
30
  require_relative "vident/root_component/using_phlex_html"
30
31
  require_relative "vident/root_component/using_view_component"
31
32
  require_relative "vident/base"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vident
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-17 00:00:00.000000000 Z
11
+ date: 2023-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -31,8 +31,9 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '8'
33
33
  description: Vident makes using Stimulus with your `ViewComponent` or `Phlex` view
34
- components as easy as writing Ruby. It also provides a base class for your components
35
- to inherit from.
34
+ components as easy as writing Ruby. Vident is the base of your design system implementation,
35
+ which provides helpers for working with Stimulus. For component libraries with ViewComponent
36
+ or Phlex.
36
37
  email:
37
38
  - stevegeek@gmail.com
38
39
  executables: []
@@ -40,6 +41,7 @@ extensions: []
40
41
  extra_rdoc_files: []
41
42
  files:
42
43
  - ".standard.yml"
44
+ - CHANGELOG.md
43
45
  - CODE_OF_CONDUCT.md
44
46
  - Gemfile
45
47
  - LICENSE.txt
@@ -57,6 +59,7 @@ files:
57
59
  - lib/vident/component.rb
58
60
  - lib/vident/railtie.rb
59
61
  - lib/vident/root_component/base.rb
62
+ - lib/vident/root_component/using_better_html.rb
60
63
  - lib/vident/root_component/using_phlex_html.rb
61
64
  - lib/vident/root_component/using_view_component.rb
62
65
  - lib/vident/stable_id.rb
@@ -90,6 +93,6 @@ requirements: []
90
93
  rubygems_version: 3.3.26
91
94
  signing_key:
92
95
  specification_version: 4
93
- summary: Vident is a view component base class for your design system implementation,
94
- which provides helpers for working with Stimulus. For ViewComponent and Phlex.
96
+ summary: Vident is the base of your design system implementation, which provides helpers
97
+ for working with Stimulus. For component libraries with ViewComponent or Phlex.
95
98
  test_files: []