attrify 0.4.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.
data/lib/attrify.rb ADDED
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "attrify/version"
4
+ require_relative "attrify/variant_registry"
5
+ require_relative "attrify/parser"
6
+
7
+ require_relative "attrify/dsl/engine"
8
+
9
+ module Attrify
10
+ def self.included(base)
11
+ base.extend ClassMethods
12
+ end
13
+
14
+ module ClassMethods
15
+ def attributes(&)
16
+ result = DSL::Engine.new.build(&)
17
+ config = variant_registry
18
+ config.base = result.base_attr
19
+ config.variants = result.variants
20
+ config.compounds = result.compounds
21
+ config.defaults = result.defaults
22
+ end
23
+
24
+ def variant_registry
25
+ @variant_registry ||=
26
+ if superclass.respond_to?(:variant_registry)
27
+ superclass.variant_registry.dup
28
+ else
29
+ VariantRegistry.new
30
+ end
31
+ end
32
+ end
33
+ include Helpers
34
+ def attribs(slot: :main, **args)
35
+ @attr_options ||= {}
36
+
37
+ new_arguments = if slot == :main
38
+ args
39
+ else
40
+ {slot => args}
41
+ end
42
+
43
+ merged_arguments = deep_merge_hashes(@attr_options, new_arguments)
44
+
45
+ variant = self.class.variant_registry&.fetch(**merged_arguments)
46
+ variant.values_for(instance: self, keys: Array(slot))
47
+ end
48
+
49
+ def with_attributes(**args)
50
+ @attr_options = args
51
+ self
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ module Attrify
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: attrify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Hector Medina Fetterman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-10-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionview
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '7.0'
41
+ description: Whether you're using ViewComponent, Tailwind CSS, or any other framework,
42
+ Attrify allows you to seamlessly Handle complex UI components with ease.
43
+ email:
44
+ - javi@digitalhospital.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".rspec"
50
+ - ".standard.yml"
51
+ - CHANGELOG.md
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/attrify.rb
59
+ - lib/attrify/dsl/base.rb
60
+ - lib/attrify/dsl/compound.rb
61
+ - lib/attrify/dsl/engine.rb
62
+ - lib/attrify/dsl/nested_variant.rb
63
+ - lib/attrify/dsl/variant.rb
64
+ - lib/attrify/helpers.rb
65
+ - lib/attrify/operation_set.rb
66
+ - lib/attrify/parser.rb
67
+ - lib/attrify/variant.rb
68
+ - lib/attrify/variant_registry.rb
69
+ - lib/attrify/version.rb
70
+ - sig/attribute_variants.rbs
71
+ homepage: https://rubygems.org/gems/attrify
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ homepage_uri: https://rubygems.org/gems/attrify
76
+ source_code_uri: https://rubygems.org/gems/attrify
77
+ changelog_uri: https://rubygems.org/gems/attrifyblob/master/CHANGELOG.md
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 2.7.0
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.4.20
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: A powerful and flexible variant API to manage HTML attributes inside your
97
+ components.
98
+ test_files: []