tag_options 0.9.3 → 1.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/CHANGELOG.md +10 -0
- data/README.md +92 -132
- data/Rakefile +5 -5
- data/lib/tag_options/configuration.rb +16 -13
- data/lib/tag_options/error.rb +4 -0
- data/lib/tag_options/errors/not_hash_error.rb +12 -0
- data/lib/tag_options/errors/resolver_error.rb +11 -0
- data/lib/tag_options/hash.rb +25 -125
- data/lib/tag_options/hash_at.rb +30 -0
- data/lib/tag_options/resolver.rb +17 -0
- data/lib/tag_options/resolvers/default.rb +11 -0
- data/lib/tag_options/resolvers/style.rb +26 -0
- data/lib/tag_options/version.rb +1 -3
- data/lib/tag_options.rb +3 -12
- metadata +16 -131
- data/lib/generators/tag_options/install/USAGE +0 -9
- data/lib/generators/tag_options/install/install_generator.rb +0 -13
- data/lib/generators/tag_options/install/templates/tag_options.rb +0 -18
- data/lib/tag_options/property_handler/base.rb +0 -36
- data/lib/tag_options/property_handler/generic.rb +0 -15
- data/lib/tag_options/property_handler/resolve_value.rb +0 -33
- data/lib/tag_options/property_handler/singular.rb +0 -15
- data/lib/tag_options/property_handler/style.rb +0 -42
- data/lib/tag_options/property_handler/tailwind_css.rb +0 -598
- data/lib/tag_options/railtie.rb +0 -8
@@ -0,0 +1,17 @@
|
|
1
|
+
module TagOptions
|
2
|
+
class Resolver
|
3
|
+
def initialize(*values, **conditional_values)
|
4
|
+
@values = [*values, *resolve_conditional_values(conditional_values)]
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.call(...)
|
8
|
+
new(...).call
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def resolve_conditional_values(conditional_values)
|
14
|
+
conditional_values.select { |_key, value| value }.keys
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "tag_options/resolver"
|
2
|
+
|
3
|
+
module TagOptions
|
4
|
+
module Resolvers
|
5
|
+
class Style < Resolver
|
6
|
+
def call
|
7
|
+
styles.map { |p, v| "#{p}: #{v};" }.join(" ")
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def styles
|
13
|
+
{}.tap do |result|
|
14
|
+
@values.each do |string|
|
15
|
+
string.to_s.split(";").compact.each do |property_value_pair|
|
16
|
+
property, value = property_value_pair.split(":")
|
17
|
+
next unless property && value
|
18
|
+
|
19
|
+
result[property.strip.downcase.to_sym] = value.strip
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/tag_options/version.rb
CHANGED
data/lib/tag_options.rb
CHANGED
@@ -1,17 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'tag_options/property_handler/base'
|
4
|
-
require 'tag_options/property_handler/generic'
|
5
|
-
require 'tag_options/property_handler/resolve_value'
|
6
|
-
require 'tag_options/property_handler/singular'
|
7
|
-
require 'tag_options/property_handler/style'
|
8
|
-
require 'tag_options/configuration'
|
9
|
-
require 'tag_options/hash'
|
10
|
-
require 'tag_options/railtie'
|
11
|
-
require 'tag_options/version'
|
1
|
+
require "tag_options/hash"
|
2
|
+
require "tag_options/version"
|
12
3
|
|
13
4
|
module TagOptions
|
14
|
-
def self.Hash(hash={})
|
5
|
+
def self.Hash(hash = {})
|
15
6
|
TagOptions::Hash.new(hash)
|
16
7
|
end
|
17
8
|
end
|
metadata
CHANGED
@@ -1,121 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tag_options
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Monroe
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: minitest
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: mocha
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop-minitest
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-performance
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rubocop-rake
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: shoulda
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
20
|
+
type: :runtime
|
119
21
|
prerelease: false
|
120
22
|
version_requirements: !ruby/object:Gem::Requirement
|
121
23
|
requirements:
|
@@ -123,7 +25,7 @@ dependencies:
|
|
123
25
|
- !ruby/object:Gem::Version
|
124
26
|
version: '0'
|
125
27
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
28
|
+
name: rspec
|
127
29
|
requirement: !ruby/object:Gem::Requirement
|
128
30
|
requirements:
|
129
31
|
- - ">="
|
@@ -136,20 +38,6 @@ dependencies:
|
|
136
38
|
- - ">="
|
137
39
|
- !ruby/object:Gem::Version
|
138
40
|
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: rails
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: 5.2.0
|
146
|
-
type: :runtime
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: 5.2.0
|
153
41
|
description: Simple library for manipulating options passed to various Rails tag helpers.
|
154
42
|
email:
|
155
43
|
- alex@monroepost.com
|
@@ -161,19 +49,16 @@ files:
|
|
161
49
|
- MIT-LICENSE
|
162
50
|
- README.md
|
163
51
|
- Rakefile
|
164
|
-
- lib/generators/tag_options/install/USAGE
|
165
|
-
- lib/generators/tag_options/install/install_generator.rb
|
166
|
-
- lib/generators/tag_options/install/templates/tag_options.rb
|
167
52
|
- lib/tag_options.rb
|
168
53
|
- lib/tag_options/configuration.rb
|
54
|
+
- lib/tag_options/error.rb
|
55
|
+
- lib/tag_options/errors/not_hash_error.rb
|
56
|
+
- lib/tag_options/errors/resolver_error.rb
|
169
57
|
- lib/tag_options/hash.rb
|
170
|
-
- lib/tag_options/
|
171
|
-
- lib/tag_options/
|
172
|
-
- lib/tag_options/
|
173
|
-
- lib/tag_options/
|
174
|
-
- lib/tag_options/property_handler/style.rb
|
175
|
-
- lib/tag_options/property_handler/tailwind_css.rb
|
176
|
-
- lib/tag_options/railtie.rb
|
58
|
+
- lib/tag_options/hash_at.rb
|
59
|
+
- lib/tag_options/resolver.rb
|
60
|
+
- lib/tag_options/resolvers/default.rb
|
61
|
+
- lib/tag_options/resolvers/style.rb
|
177
62
|
- lib/tag_options/version.rb
|
178
63
|
homepage: https://github.com/wamonroe/tag_options
|
179
64
|
licenses:
|
@@ -182,7 +67,7 @@ metadata:
|
|
182
67
|
homepage_uri: https://github.com/wamonroe/tag_options
|
183
68
|
source_code_uri: https://github.com/wamonroe/tag_options
|
184
69
|
changelog_uri: https://github.com/wamonroe/tag_options/blob/main/CHANGELOG.md
|
185
|
-
post_install_message:
|
70
|
+
post_install_message:
|
186
71
|
rdoc_options: []
|
187
72
|
require_paths:
|
188
73
|
- lib
|
@@ -197,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
82
|
- !ruby/object:Gem::Version
|
198
83
|
version: '0'
|
199
84
|
requirements: []
|
200
|
-
rubygems_version: 3.
|
201
|
-
signing_key:
|
85
|
+
rubygems_version: 3.4.6
|
86
|
+
signing_key:
|
202
87
|
specification_version: 4
|
203
88
|
summary: Simple library for manipulating options passed to various Rails tag helpers.
|
204
89
|
test_files: []
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators'
|
4
|
-
|
5
|
-
module TagOptions
|
6
|
-
class InstallGenerator < Rails::Generators::Base
|
7
|
-
source_root File.expand_path('templates', __dir__)
|
8
|
-
|
9
|
-
def copy_initializer
|
10
|
-
copy_file 'tag_options.rb', 'config/initializers/tag_options.rb'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
TagOptions.configure do |config|
|
4
|
-
# fallback_property_handler
|
5
|
-
#
|
6
|
-
# Defines the default behavior of how values are treated on HTML properties. `TagOptions::PropertyHandler::Generic`
|
7
|
-
# allows for multiple, unique, values seperated by spaces.
|
8
|
-
config.fallback_property_handler = 'TagOptions::PropertyHandler::Generic'
|
9
|
-
|
10
|
-
# property_handlers
|
11
|
-
#
|
12
|
-
# Allows of the custom handling of HTML properties that match the defined property handler. Properties are handled by
|
13
|
-
# the first matching property handler.
|
14
|
-
config.property_handlers = [
|
15
|
-
'TagOptions::PropertyHandler::Singular',
|
16
|
-
'TagOptions::PropertyHandler::Style'
|
17
|
-
]
|
18
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TagOptions
|
4
|
-
module PropertyHandler
|
5
|
-
class Base
|
6
|
-
attr_reader :values, :conditions
|
7
|
-
|
8
|
-
def initialize(*values, **conditions)
|
9
|
-
@values = values
|
10
|
-
@conditions = conditions
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.call(...)
|
14
|
-
new(...).call
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.handler_for?(property_name)
|
18
|
-
self::MATCHER.match?(property_name.to_s)
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def combine_values(*values, **conditions)
|
24
|
-
resolve_uniq_values(*values, **conditions).join(' ')
|
25
|
-
end
|
26
|
-
|
27
|
-
def resolve_uniq_values(*values, **conditions)
|
28
|
-
[*values, *resolve_conditions(conditions)].map { |v| v.to_s.split }.flatten.compact.uniq
|
29
|
-
end
|
30
|
-
|
31
|
-
def resolve_conditions(conditions)
|
32
|
-
conditions.select { |_key, value| value }.keys
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'tag_options/property_handler/base'
|
4
|
-
|
5
|
-
module TagOptions
|
6
|
-
module PropertyHandler
|
7
|
-
class Generic < Base
|
8
|
-
MATCHER = /\A.*\z/.freeze
|
9
|
-
|
10
|
-
def call
|
11
|
-
combine_values(*values, **conditions)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'tag_options/configuration'
|
4
|
-
|
5
|
-
module TagOptions
|
6
|
-
module PropertyHandler
|
7
|
-
class ResolveValue
|
8
|
-
attr_reader :property
|
9
|
-
|
10
|
-
def initialize(property)
|
11
|
-
@property = property
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(...)
|
15
|
-
handler.call(...)
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.call(property, *values, **conditions)
|
19
|
-
new(property).call(*values, **conditions)
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def handler
|
25
|
-
TagOptions.configuration.property_handlers.each do |handler_string|
|
26
|
-
handler = handler_string.constantize
|
27
|
-
return handler if handler.handler_for?(property)
|
28
|
-
end
|
29
|
-
TagOptions.configuration.fallback_property_handler.constantize
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'tag_options/property_handler/base'
|
4
|
-
|
5
|
-
module TagOptions
|
6
|
-
module PropertyHandler
|
7
|
-
class Singular < Base
|
8
|
-
MATCHER = /\Aid|role|aria-.+\z/.freeze
|
9
|
-
|
10
|
-
def call
|
11
|
-
resolve_uniq_values(*values, **conditions).last.to_s
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'tag_options/property_handler/base'
|
4
|
-
|
5
|
-
module TagOptions
|
6
|
-
module PropertyHandler
|
7
|
-
class Style < Base
|
8
|
-
MATCHER = /\Astyle\z/.freeze
|
9
|
-
|
10
|
-
def call
|
11
|
-
styles.map { |p, v| "#{p}: #{v};" }.join(' ')
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def styles
|
17
|
-
styles_from_values.merge(styles_from_conditions)
|
18
|
-
end
|
19
|
-
|
20
|
-
def styles_from_values
|
21
|
-
style_hash_from(values)
|
22
|
-
end
|
23
|
-
|
24
|
-
def styles_from_conditions
|
25
|
-
style_hash_from(resolve_conditions(conditions))
|
26
|
-
end
|
27
|
-
|
28
|
-
def style_hash_from(strings)
|
29
|
-
{}.tap do |result|
|
30
|
-
Array(strings).each do |string|
|
31
|
-
string.to_s.split(';').compact.each do |property_value_pair|
|
32
|
-
property, value = property_value_pair.split(':')
|
33
|
-
next unless property && value
|
34
|
-
|
35
|
-
result[property.strip.downcase.to_sym] = value.strip
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|