classlist 1.0.0 → 1.1.1

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: 3b46ec60d2055c6c957a429f49af57adf78b063f933334cdac92d9b62a669f6f
4
- data.tar.gz: b1ead5e0df053f41a9faf85d4b02345910e9efe5479ec5cb483eba116aae0975
3
+ metadata.gz: 6dc0fe88b3aa27f1379a8bec855ba61dc1127f182024e380d2f55261519836c8
4
+ data.tar.gz: e039d28895c840821f6894771f5219746fd2ac82c4220154946d22d432a30fc8
5
5
  SHA512:
6
- metadata.gz: 2012cbfeea055153c58050c0e6061157bca4228c97372cddb5b7c0072abac3969c9fb20be3ef8e30c56d58845aa9c521e2b4f2b787d3c0a9c8d3bfc7afa28a41
7
- data.tar.gz: 84a6d60146e626e2e0cef6cc6b4b31a72e459d1dcbe01848ebeb5bf4907d0eb04c78c50564c10dfdab53099aecd18a9055b447f13c88be9aaa890c1c36cfdc21
6
+ metadata.gz: f789382914671c7f40face90cf54129706e0fb4b420524e8068ead6cababc36c5b5c8894fe5639339c64e34a24c39b222c1c7df6a8b02b665d3306484f949090
7
+ data.tar.gz: 74ec1b884e31914dccaf7f7b4a3251bbcdcdb78df12a9605467c399b255ddbac1114349b643b6baacd3bf48779cad04e93565fd0c681589d2c6a18cd86805587
data/CHANGELOG.md CHANGED
@@ -9,7 +9,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Added
11
11
 
12
- -
12
+ ### Fixed
13
+
14
+
15
+ ## [1.1.1] - 2025-12-08
16
+
17
+ ### Added
18
+
19
+ - LICENSE file.
20
+ - Code of Conduct.
21
+ - Add support for Ruby 3.2, 3.3, 3.4 (no changes).
22
+
23
+ ### Fixed
24
+
25
+ - Adding a raw `Classlist` to a set of `Classlist::Operation`s would merge the `Classlist` into the last operation, instead of treating the `Classlist` as an implicit `Classlist::Add` operation (which it should be).
26
+
27
+ ## [1.1.0] - 2022-11-07
28
+
29
+ ### Added
30
+
31
+ - Support for chains of operations longer than the most simple cases.
32
+ - Introduce Classlist::Operation as a common super class for Classlist::Add, Classlist::Remove, Classlist::Reset.
33
+ - Classlist::Add that adds all entries when merged
13
34
 
14
35
  ## [1.0.0]
15
36
 
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ jakob@substancelab.com.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Substance Lab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -8,6 +8,8 @@ Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
10
  gem 'classlist'
11
+ # or if you don't want to manually require stuff:
12
+ gem 'classlist', require: 'classlist/all'
11
13
  ```
12
14
 
13
15
  And then execute:
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "classlist/operation"
4
+
5
+ # Classlist::Add is an operation that adds tokens to the original
6
+ # classlist when added to it.
7
+ class Classlist::Add < Classlist::Operation
8
+ def merge(original)
9
+ original.entries + entries
10
+ end
11
+
12
+ # resolve changes the original classlist
13
+ def resolve(original)
14
+ entries.each do |entry|
15
+ original.add(entry)
16
+ end
17
+
18
+ super
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Require this file to load all of Classlist into your application.
4
+ #
5
+ # For example in a Gemfile:
6
+ #
7
+ # gem "classlist", require: "classlist/all"
8
+ #
9
+ # Or you can just require what you need manually.
10
+
11
+ require "classlist/add"
12
+ require "classlist/remove"
13
+ require "classlist/reset"
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "classlist"
4
+
5
+ # Classlist::Operations modify the original classlist
6
+ class Classlist::Operation < Classlist
7
+ # resolve changes the original classlist
8
+ def resolve(original_classlist)
9
+ resolve_operations(original_classlist)
10
+ end
11
+ end
@@ -1,11 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "classlist"
3
+ require "classlist/operation"
4
4
 
5
- # Classlist::Remove is a classlist that removes tokens from the original
5
+ # Classlist::Remove is an operation that removes tokens from the original
6
6
  # classlist when added to it.
7
- class Classlist::Remove < Classlist
7
+ class Classlist::Remove < Classlist::Operation
8
8
  def merge(original)
9
9
  original.entries - entries
10
10
  end
11
+
12
+ # #resolve changes the original classlist
13
+ def resolve(original)
14
+ entries.each do |entry|
15
+ original.remove(entry)
16
+ end
17
+
18
+ super
19
+ end
11
20
  end
@@ -1,11 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "classlist"
3
+ require "classlist/operation"
4
4
 
5
- # Classlist::Reset is a classlist that removes all tokens from the original
5
+ # Classlist::Reset is an operation that removes all tokens from the original
6
6
  # classlist when merged.
7
- class Classlist::Reset < Classlist
7
+ class Classlist::Reset < Classlist::Operation
8
8
  def merge(original)
9
9
  original.entries.replace(entries)
10
10
  end
11
+
12
+ # #resolve changes the original classlist
13
+ def resolve(original)
14
+ original.entries.replace(entries)
15
+
16
+ super
17
+ end
11
18
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Classlist
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.1"
5
5
  end
data/lib/classlist.rb CHANGED
@@ -10,25 +10,38 @@ class Classlist
10
10
  class Error < StandardError; end
11
11
 
12
12
  extend Forwardable
13
+
13
14
  def_delegators :@entries, :each
14
15
 
15
- attr_reader :entries
16
+ attr_reader :entries, :operations
16
17
 
17
18
  # Returns the Classlist resulting from adding other to this classlist.
18
19
  def +(other)
19
- result = if other.is_a?(Classlist)
20
- other.merge(self)
21
- else
22
- entries + build_entries(other)
20
+ # When adding a basic Classlist to an existing list, assume an Add operation
21
+ if other.is_a?(Classlist) && !other.is_a?(Classlist::Operation)
22
+ other = Classlist::Add.new(other.entries.dup)
23
23
  end
24
24
 
25
- Classlist.new(result)
25
+ case other
26
+ when Classlist::Operation
27
+ add_operation(other)
28
+ self
29
+ when Classlist
30
+ result = other.merge(self)
31
+ Classlist.new(result)
32
+ else
33
+ result = entries + build_entries(other)
34
+ Classlist.new(result)
35
+ end
26
36
  end
27
37
 
28
38
  def ==(other)
29
39
  return false unless other.is_a?(self.class)
30
40
 
31
- entries == other.entries
41
+ resolve_operations(self)
42
+ other.resolve_operations
43
+
44
+ @entries == other.entries
32
45
  end
33
46
 
34
47
  # Adds the given tokens to the list, omitting any that are already present.
@@ -39,6 +52,10 @@ class Classlist
39
52
  end
40
53
  end
41
54
 
55
+ def add_operation(other)
56
+ @operations << other
57
+ end
58
+
42
59
  def include?(token)
43
60
  entries.include?(token)
44
61
  end
@@ -46,6 +63,7 @@ class Classlist
46
63
 
47
64
  def initialize(entries = [])
48
65
  @entries = build_entries(entries)
66
+ @operations = []
49
67
  end
50
68
 
51
69
  # Returns the item in the list by its index, or null if the index is greater
@@ -91,12 +109,19 @@ class Classlist
91
109
  true
92
110
  end
93
111
 
112
+ def resolve_operations(original_classlist = self)
113
+ operations.each do |operation|
114
+ operation.resolve(original_classlist)
115
+ end
116
+ end
117
+
94
118
  def to_a
95
- entries
119
+ resolve_operations(self)
120
+ @entries
96
121
  end
97
122
 
98
123
  def to_s
99
- entries.join(" ")
124
+ to_a.join(" ")
100
125
  end
101
126
  alias_method :value, :to_s
102
127
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classlist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Skjerning
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2022-11-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Serverside manipulation of lists of CSS classnames that play nicely with
14
13
  View Components.
@@ -21,13 +20,18 @@ files:
21
20
  - ".rubocop.yml"
22
21
  - ".standard.yml"
23
22
  - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
24
  - Gemfile
25
+ - LICENSE
25
26
  - README.md
26
27
  - Rakefile
27
28
  - bin/console
28
29
  - bin/setup
29
30
  - classlist.gemspec
30
31
  - lib/classlist.rb
32
+ - lib/classlist/add.rb
33
+ - lib/classlist/all.rb
34
+ - lib/classlist/operation.rb
31
35
  - lib/classlist/remove.rb
32
36
  - lib/classlist/reset.rb
33
37
  - lib/classlist/version.rb
@@ -37,7 +41,6 @@ licenses:
37
41
  - MIT
38
42
  metadata:
39
43
  homepage_uri: https://github.com/substancelab/classlist
40
- post_install_message:
41
44
  rdoc_options: []
42
45
  require_paths:
43
46
  - lib
@@ -52,8 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
55
  - !ruby/object:Gem::Version
53
56
  version: '0'
54
57
  requirements: []
55
- rubygems_version: 3.2.22
56
- signing_key:
58
+ rubygems_version: 3.6.9
57
59
  specification_version: 4
58
60
  summary: Ruby implementation of the Element.classList DOM API
59
61
  test_files: []