classlist 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +4 -0
- data/.standard.yml +2 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +11 -0
- data/README.md +35 -0
- data/Rakefile +13 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/classlist.gemspec +36 -0
- data/lib/classlist/version.rb +5 -0
- data/lib/classlist.rb +95 -0
- data/sig/classlist.rbs +4 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0623abc0509ba65bd66bc3147ee059f7d6424f082e21867031998fa66469b1f7
|
4
|
+
data.tar.gz: b9c6713cebf59a58ab5a436db88249601e04fe24b8bc553775675ffdebb44361
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4fec82f539a407cf44e97beb4b83d60caf72c48ed3818e56c3900e19d53a31497729887a1f14f62fe4ffd68a7e7bb32665893d15d2fe2d9777b7469f7f9fcbb1
|
7
|
+
data.tar.gz: c8bc4baae23c82f8291fb78ed0da3a251aace747016a510304021413b8e6855bcf192fe38703eb47fd213107ae6dd82b02509b3be2bf6ebf34346c963a773af7
|
data/.rubocop.yml
ADDED
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Everything :)
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Classlist
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/classlist`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'classlist'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install classlist
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/koppen/classlist.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "standard/rake"
|
5
|
+
require "rake/testtask"
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |t|
|
8
|
+
t.libs << "test"
|
9
|
+
t.libs << "lib"
|
10
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
11
|
+
end
|
12
|
+
|
13
|
+
task default: %i[test standard]
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "classlist"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/classlist.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/classlist/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "classlist"
|
7
|
+
spec.version = Classlist::VERSION
|
8
|
+
spec.authors = ["Jakob Skjerning"]
|
9
|
+
spec.email = ["jakob@mentalized.net"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby implementation of the Element.classList DOM API"
|
12
|
+
spec.description = "Serverside manipulation of lists of CSS classnames that play nicely with View Components."
|
13
|
+
spec.homepage = "https://github.com/substancelab/classlist"
|
14
|
+
spec.required_ruby_version = ">= 2.7.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
33
|
+
|
34
|
+
# For more information and examples about making a new gem, check out our
|
35
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
end
|
data/lib/classlist.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "classlist/version"
|
4
|
+
|
5
|
+
class Classlist
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
attr_reader :entries
|
9
|
+
|
10
|
+
# Adds the given tokens to the list, omitting any that are already present.
|
11
|
+
def add(tokens)
|
12
|
+
entries = build_entries(tokens)
|
13
|
+
entries.each do |entry|
|
14
|
+
self.entries.push(entry) unless self.entries.include?(entry)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(entries = [])
|
19
|
+
@entries = build_entries(entries)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Removes the specified tokens from the classlist, ignoring any that are not
|
23
|
+
# present.
|
24
|
+
def remove(tokens)
|
25
|
+
entries = build_entries(tokens)
|
26
|
+
entries.each do |entry|
|
27
|
+
self.entries.delete(entry)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Replaces an existing token with a new token. If the first token doesn't
|
32
|
+
# exist, #replace returns false immediately, without adding the new token to
|
33
|
+
# the token list.
|
34
|
+
def replace(old_token, new_token)
|
35
|
+
return false unless entries.include?(old_token)
|
36
|
+
|
37
|
+
if entries.include?(new_token)
|
38
|
+
entries.delete(old_token)
|
39
|
+
else
|
40
|
+
index = entries.index(old_token)
|
41
|
+
entries[index] = new_token
|
42
|
+
end
|
43
|
+
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_a
|
48
|
+
entries
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_s
|
52
|
+
entries.join(" ")
|
53
|
+
end
|
54
|
+
|
55
|
+
# Removes an existing token from the list and returns false. If the token
|
56
|
+
# doesn't exist it's added and the function returns true.
|
57
|
+
#
|
58
|
+
# If force is included, it turns the toggle into a one way-only operation. If
|
59
|
+
# set to false, then token will only be removed, but not added. If set to
|
60
|
+
# true, then token will only be added, but not removed.
|
61
|
+
def toggle(token, force = nil)
|
62
|
+
if entries.include?(token)
|
63
|
+
entries.delete(token) unless force == true
|
64
|
+
result = false
|
65
|
+
else
|
66
|
+
entries.push(token) unless force == false
|
67
|
+
result = true
|
68
|
+
end
|
69
|
+
|
70
|
+
if force.nil?
|
71
|
+
result
|
72
|
+
else
|
73
|
+
force
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
attr_writer :entries
|
80
|
+
|
81
|
+
def build_entries(entries)
|
82
|
+
case entries
|
83
|
+
when Array
|
84
|
+
entries
|
85
|
+
when Classlist
|
86
|
+
entries.entries
|
87
|
+
when NilClass
|
88
|
+
[]
|
89
|
+
when String
|
90
|
+
entries.split(" ")
|
91
|
+
else
|
92
|
+
raise Error, "Invalid entries: #{entries.inspect}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/sig/classlist.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: classlist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jakob Skjerning
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Serverside manipulation of lists of CSS classnames that play nicely with
|
14
|
+
View Components.
|
15
|
+
email:
|
16
|
+
- jakob@mentalized.net
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- ".standard.yml"
|
23
|
+
- CHANGELOG.md
|
24
|
+
- Gemfile
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- bin/console
|
28
|
+
- bin/setup
|
29
|
+
- classlist.gemspec
|
30
|
+
- lib/classlist.rb
|
31
|
+
- lib/classlist/version.rb
|
32
|
+
- sig/classlist.rbs
|
33
|
+
homepage: https://github.com/substancelab/classlist
|
34
|
+
licenses:
|
35
|
+
- MIT
|
36
|
+
metadata:
|
37
|
+
homepage_uri: https://github.com/substancelab/classlist
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.7.0
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.2.22
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Ruby implementation of the Element.classList DOM API
|
57
|
+
test_files: []
|