stimulux 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 062733471325a76083d3861ebc60e24de61c9ca6825f5c1f67a12f5fa5a1426f
4
+ data.tar.gz: e0558fe1ed34f8acca66e8ea69e2da281818425f233befffb58b8de708800eb7
5
+ SHA512:
6
+ metadata.gz: 5dbcd1ac7939a7839512db3db717a109631050faf6c9413539e7804488e90fea1f17725bf1091726ea444a9456adab66edc7089b8b1b941cb929dd1cfa3036b8
7
+ data.tar.gz: d442c75a097ac2a2fd73281828c64ef0b39c8339603508201573caa755109cec41c08db4fb5475a2640ac515946e0967da01e6c1485b73cbf6c583dcfbe2289e
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stimulux
4
+ VERSION = '0.1.0'
5
+ end
data/lib/stimulux.rb ADDED
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'stimulux/version'
4
+
5
+ module Stimulux
6
+ extend self
7
+
8
+ def controllers(*args)
9
+ controller_names = []
10
+ value_attributes = {}
11
+
12
+ args.each do |arg|
13
+ case arg
14
+ when String, Symbol
15
+ controller_names << kebabize(arg)
16
+ when Array
17
+ name, values = arg
18
+ controller_name = kebabize(name)
19
+ controller_names << controller_name
20
+
21
+ if values.is_a?(Hash)
22
+ values.each do |key, value|
23
+ value_key = "data-#{controller_name}-#{kebabize(key)}-value"
24
+ value_attributes[value_key] = value
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ { 'data-controller' => controller_names.join(' ') }.merge(value_attributes)
31
+ end
32
+
33
+ def targets(*names)
34
+ names.each_with_object({}) do |name, hash|
35
+ controller, target_name = name.to_s.split('#')
36
+ hash["data-#{kebabize(controller)}-target"] = target_name
37
+ end
38
+ end
39
+
40
+ def actions(*names)
41
+ { 'data-action' => names.join(' ') }
42
+ end
43
+
44
+ def classes(*definitions)
45
+ definitions.each_with_object({}) do |(name, classes_hash), hash|
46
+ controller_name = kebabize(name)
47
+ classes_hash.each do |key, value|
48
+ class_key = "data-#{controller_name}-#{kebabize(key)}-class"
49
+ hash[class_key] = value
50
+ end
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def kebabize(str)
57
+ return '' if str.nil? || str.empty?
58
+
59
+ s = str.to_s
60
+
61
+ s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1-\2')
62
+ .gsub(/([a-z\d])([A-Z])/, '\1-\2')
63
+ .tr('_', '-')
64
+ .downcase
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stimulux
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - henrique-ft
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2026-01-03 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: 'Stimulus, without brain gymnastics: helpers for Phlex and HtmlSlice
13
+ ''data-'' atributes generation'
14
+ email:
15
+ - hriqueft@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/stimulux.rb
21
+ - lib/stimulux/version.rb
22
+ licenses:
23
+ - MIT
24
+ metadata:
25
+ source_code_uri: https://github.com/henrique-ft/stimulux
26
+ changelog_uri: https://github.com/henrique-ft/stimulux/blob/master/CHANGELOG.md
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 3.1.0
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.6.6
42
+ specification_version: 4
43
+ summary: 'Stimulus, without brain gymnastics: helpers for Phlex and HtmlSlice ''data-''
44
+ atributes generation'
45
+ test_files: []