stealth_dom_id 0.2.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 +7 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +124 -0
- data/README.md +51 -0
- data/Rakefile +10 -0
- data/bin/console +11 -0
- data/bin/release +19 -0
- data/bin/setup +6 -0
- data/lib/stealth_dom_id/core.rb +34 -0
- data/lib/stealth_dom_id/railtie.rb +9 -0
- data/lib/stealth_dom_id/version.rb +5 -0
- data/lib/stealth_dom_id.rb +13 -0
- data/stealth_dom_id.gemspec +25 -0
- metadata +99 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1b2873eeed2f0437b75fe061a5261673f08992c186a60349c2460f63bdfbc007
|
|
4
|
+
data.tar.gz: 8ba04b34323b83b852f172a97a3ff4af9bc7756da6a1185e47ea34501465bd52
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6bf8818c874009b129f470fb5d9742ecb58e8f8bdf3abe81b20f725a80b62ccb7c20bf0f8b2e7535c1d5f7a8ca8aa8e336884d849b781e3a4ea1858d7a5ac441
|
|
7
|
+
data.tar.gz: 7deef458663e54886b5ed878bab0b2365fe4c61509cb0446899d228ada8d404ab45046c2e542043cbdfc6a475b56f41a446d0c2080b2ecc1963051553c7c1c97
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
stealth_dom_id (0.2.0)
|
|
5
|
+
actionview (>= 3.0, < 8.1)
|
|
6
|
+
activesupport (>= 3.0, < 8.1)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
actionview (7.2.2)
|
|
12
|
+
activesupport (= 7.2.2)
|
|
13
|
+
builder (~> 3.1)
|
|
14
|
+
erubi (~> 1.11)
|
|
15
|
+
rails-dom-testing (~> 2.2)
|
|
16
|
+
rails-html-sanitizer (~> 1.6)
|
|
17
|
+
activesupport (7.2.2)
|
|
18
|
+
base64
|
|
19
|
+
benchmark (>= 0.3)
|
|
20
|
+
bigdecimal
|
|
21
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
22
|
+
connection_pool (>= 2.2.5)
|
|
23
|
+
drb
|
|
24
|
+
i18n (>= 1.6, < 2)
|
|
25
|
+
logger (>= 1.4.2)
|
|
26
|
+
minitest (>= 5.1)
|
|
27
|
+
securerandom (>= 0.3)
|
|
28
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
29
|
+
ast (2.4.2)
|
|
30
|
+
base64 (0.2.0)
|
|
31
|
+
benchmark (0.3.0)
|
|
32
|
+
bigdecimal (3.1.8)
|
|
33
|
+
builder (3.3.0)
|
|
34
|
+
concurrent-ruby (1.3.4)
|
|
35
|
+
connection_pool (2.4.1)
|
|
36
|
+
crass (1.0.6)
|
|
37
|
+
drb (2.2.1)
|
|
38
|
+
erubi (1.13.0)
|
|
39
|
+
i18n (1.14.6)
|
|
40
|
+
concurrent-ruby (~> 1.0)
|
|
41
|
+
json (2.7.5)
|
|
42
|
+
language_server-protocol (3.17.0.3)
|
|
43
|
+
lint_roller (1.1.0)
|
|
44
|
+
logger (1.6.1)
|
|
45
|
+
loofah (2.23.1)
|
|
46
|
+
crass (~> 1.0.2)
|
|
47
|
+
nokogiri (>= 1.12.0)
|
|
48
|
+
minitest (5.25.1)
|
|
49
|
+
nokogiri (1.16.7-aarch64-linux)
|
|
50
|
+
racc (~> 1.4)
|
|
51
|
+
nokogiri (1.16.7-arm-linux)
|
|
52
|
+
racc (~> 1.4)
|
|
53
|
+
nokogiri (1.16.7-arm64-darwin)
|
|
54
|
+
racc (~> 1.4)
|
|
55
|
+
nokogiri (1.16.7-x86-linux)
|
|
56
|
+
racc (~> 1.4)
|
|
57
|
+
nokogiri (1.16.7-x86_64-darwin)
|
|
58
|
+
racc (~> 1.4)
|
|
59
|
+
nokogiri (1.16.7-x86_64-linux)
|
|
60
|
+
racc (~> 1.4)
|
|
61
|
+
parallel (1.26.3)
|
|
62
|
+
parser (3.3.5.1)
|
|
63
|
+
ast (~> 2.4.1)
|
|
64
|
+
racc
|
|
65
|
+
racc (1.8.1)
|
|
66
|
+
rails-dom-testing (2.2.0)
|
|
67
|
+
activesupport (>= 5.0.0)
|
|
68
|
+
minitest
|
|
69
|
+
nokogiri (>= 1.6)
|
|
70
|
+
rails-html-sanitizer (1.6.0)
|
|
71
|
+
loofah (~> 2.21)
|
|
72
|
+
nokogiri (~> 1.14)
|
|
73
|
+
rainbow (3.1.1)
|
|
74
|
+
rake (13.2.1)
|
|
75
|
+
regexp_parser (2.9.2)
|
|
76
|
+
rubocop (1.66.1)
|
|
77
|
+
json (~> 2.3)
|
|
78
|
+
language_server-protocol (>= 3.17.0)
|
|
79
|
+
parallel (~> 1.10)
|
|
80
|
+
parser (>= 3.3.0.2)
|
|
81
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
82
|
+
regexp_parser (>= 2.4, < 3.0)
|
|
83
|
+
rubocop-ast (>= 1.32.2, < 2.0)
|
|
84
|
+
ruby-progressbar (~> 1.7)
|
|
85
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
86
|
+
rubocop-ast (1.33.1)
|
|
87
|
+
parser (>= 3.3.1.0)
|
|
88
|
+
rubocop-performance (1.22.1)
|
|
89
|
+
rubocop (>= 1.48.1, < 2.0)
|
|
90
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
|
91
|
+
ruby-progressbar (1.13.0)
|
|
92
|
+
securerandom (0.3.1)
|
|
93
|
+
standard (1.41.1)
|
|
94
|
+
language_server-protocol (~> 3.17.0.2)
|
|
95
|
+
lint_roller (~> 1.0)
|
|
96
|
+
rubocop (~> 1.66.0)
|
|
97
|
+
standard-custom (~> 1.0.0)
|
|
98
|
+
standard-performance (~> 1.5)
|
|
99
|
+
standard-custom (1.0.2)
|
|
100
|
+
lint_roller (~> 1.0)
|
|
101
|
+
rubocop (~> 1.50)
|
|
102
|
+
standard-performance (1.5.0)
|
|
103
|
+
lint_roller (~> 1.1)
|
|
104
|
+
rubocop-performance (~> 1.22.0)
|
|
105
|
+
tzinfo (2.0.6)
|
|
106
|
+
concurrent-ruby (~> 1.0)
|
|
107
|
+
unicode-display_width (2.6.0)
|
|
108
|
+
|
|
109
|
+
PLATFORMS
|
|
110
|
+
aarch64-linux
|
|
111
|
+
arm-linux
|
|
112
|
+
arm64-darwin
|
|
113
|
+
x86-linux
|
|
114
|
+
x86_64-darwin
|
|
115
|
+
x86_64-linux
|
|
116
|
+
|
|
117
|
+
DEPENDENCIES
|
|
118
|
+
minitest (~> 5.16)
|
|
119
|
+
rake (~> 13.0)
|
|
120
|
+
standard (~> 1.41)
|
|
121
|
+
stealth_dom_id!
|
|
122
|
+
|
|
123
|
+
BUNDLED WITH
|
|
124
|
+
2.5.22
|
data/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# StealthDomId
|
|
2
|
+
|
|
3
|
+
stealth_dom_id extends Rails' [`dom_id`](https://github.com/rails/rails/blob/main/actionview/lib/action_view/record_identifier.rb) helper to generate DOM IDs using alternative columns instead of database primary keys. This helps prevent exposing internal database IDs
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
bundle add stealth_dom_id
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
gem install stealth_dom_id
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
This gem extends Rails' `dom_id` helper to use alternative columns instead of exposing database IDs in your HTML elements.
|
|
24
|
+
|
|
25
|
+
Instead of:
|
|
26
|
+
```erb
|
|
27
|
+
<%= dom_id(@user) %>
|
|
28
|
+
# => "user_1"
|
|
29
|
+
|
|
30
|
+
<%= dom_id(@user, column: :public_id) %>
|
|
31
|
+
# => Outputs: "user_a1b2c3"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The `column` attribute is optional. `prefix` attribute is also supported.
|
|
35
|
+
|
|
36
|
+
```erb
|
|
37
|
+
<%= dom_id(@user, :admin, column: :public_id) %>
|
|
38
|
+
# => Outputs: "admin_user_a1b2c3"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Development
|
|
43
|
+
|
|
44
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
45
|
+
|
|
46
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "stealth_dom_id"
|
|
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
|
+
require "irb"
|
|
11
|
+
IRB.start(__FILE__)
|
data/bin/release
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
VERSION=$1
|
|
4
|
+
|
|
5
|
+
if [ -z "$VERSION" ]; then
|
|
6
|
+
echo "Error: The version number is required."
|
|
7
|
+
echo "Usage: $0 <version-number>"
|
|
8
|
+
exit 1
|
|
9
|
+
fi
|
|
10
|
+
|
|
11
|
+
printf "# frozen_string_literal: true\n\nmodule StealthDomId\n VERSION = \"$VERSION\"\nend\n" > ./lib/stealth_dom_id/version.rb
|
|
12
|
+
bundle
|
|
13
|
+
git add Gemfile.lock lib/stealth_dom_id/version.rb
|
|
14
|
+
git commit -m "Bump version for $VERSION"
|
|
15
|
+
git push
|
|
16
|
+
git tag v$VERSION
|
|
17
|
+
git push --tags
|
|
18
|
+
gem build stealth_dom_id.gemspec
|
|
19
|
+
gem push "stealth_dom_id-$VERSION.gem"
|
data/bin/setup
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module StealthDomId
|
|
2
|
+
class ColumnError < ArgumentError; end
|
|
3
|
+
|
|
4
|
+
module Core
|
|
5
|
+
def dom_id(record_or_class, prefix = nil, column: nil)
|
|
6
|
+
unless record_or_class.is_a?(Class)
|
|
7
|
+
record_id = if column
|
|
8
|
+
record_key_for_dom_id_by_column(record_or_class, column: column)
|
|
9
|
+
else
|
|
10
|
+
record_key_for_dom_id(record_or_class)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
if record_id
|
|
15
|
+
"#{dom_class(record_or_class, prefix)}#{JOIN}#{record_id}"
|
|
16
|
+
else
|
|
17
|
+
dom_class(record_or_class, prefix || NEW)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
JOIN = "_".freeze
|
|
24
|
+
NEW = "new".freeze
|
|
25
|
+
|
|
26
|
+
def record_key_for_dom_id_by_column(record, column:)
|
|
27
|
+
key = [convert_to_model(record).send(column)]
|
|
28
|
+
|
|
29
|
+
key ? key.join(JOIN) : key
|
|
30
|
+
rescue NoMethodError => e
|
|
31
|
+
raise ColumnError, "[StealthDomId] Column '#{column}' not found on #{record.class}"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "stealth_dom_id/version"
|
|
4
|
+
require "stealth_dom_id/core"
|
|
5
|
+
require "active_support"
|
|
6
|
+
|
|
7
|
+
module StealthDomId
|
|
8
|
+
class Error < StandardError; end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
ActiveSupport.on_load(:action_view) do
|
|
12
|
+
include StealthDomId::Core
|
|
13
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/stealth_dom_id/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "stealth_dom_id"
|
|
7
|
+
spec.version = StealthDomId::VERSION
|
|
8
|
+
spec.authors = ["Rails Designer Developers"]
|
|
9
|
+
spec.email = ["devs@railsdesigner.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Extends Rails `dom_id` helper to support custom column-based identifiers"
|
|
12
|
+
spec.description = "StealthDomId extends Rails' `dom_id` helper to generate DOM IDs using alternative columns instead of database primary keys. This helps prevent exposing internal database IDs."
|
|
13
|
+
spec.homepage = "https://github.com/Rails-Designer/stealth_dom_id/"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/Rails-Designer/stealth_dom_id/"
|
|
19
|
+
|
|
20
|
+
spec.files = Dir["{bin,app,config,db,lib,public}/**/*", "Rakefile", "README.md", "stealth_dom_id.gemspec", "Gemfile", "Gemfile.lock"]
|
|
21
|
+
|
|
22
|
+
spec.required_ruby_version = ">= 3.0.0"
|
|
23
|
+
spec.add_dependency "actionview", ">= 3.0", "< 8.1"
|
|
24
|
+
spec.add_dependency "activesupport", ">= 3.0", "< 8.1"
|
|
25
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: stealth_dom_id
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Rails Designer Developers
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-11-06 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: actionview
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.0'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '8.1'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '3.0'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '8.1'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: activesupport
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '3.0'
|
|
40
|
+
- - "<"
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '8.1'
|
|
43
|
+
type: :runtime
|
|
44
|
+
prerelease: false
|
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '3.0'
|
|
50
|
+
- - "<"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '8.1'
|
|
53
|
+
description: StealthDomId extends Rails' `dom_id` helper to generate DOM IDs using
|
|
54
|
+
alternative columns instead of database primary keys. This helps prevent exposing
|
|
55
|
+
internal database IDs.
|
|
56
|
+
email:
|
|
57
|
+
- devs@railsdesigner.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- Gemfile
|
|
63
|
+
- Gemfile.lock
|
|
64
|
+
- README.md
|
|
65
|
+
- Rakefile
|
|
66
|
+
- bin/console
|
|
67
|
+
- bin/release
|
|
68
|
+
- bin/setup
|
|
69
|
+
- lib/stealth_dom_id.rb
|
|
70
|
+
- lib/stealth_dom_id/core.rb
|
|
71
|
+
- lib/stealth_dom_id/railtie.rb
|
|
72
|
+
- lib/stealth_dom_id/version.rb
|
|
73
|
+
- stealth_dom_id.gemspec
|
|
74
|
+
homepage: https://github.com/Rails-Designer/stealth_dom_id/
|
|
75
|
+
licenses:
|
|
76
|
+
- MIT
|
|
77
|
+
metadata:
|
|
78
|
+
homepage_uri: https://github.com/Rails-Designer/stealth_dom_id/
|
|
79
|
+
source_code_uri: https://github.com/Rails-Designer/stealth_dom_id/
|
|
80
|
+
post_install_message:
|
|
81
|
+
rdoc_options: []
|
|
82
|
+
require_paths:
|
|
83
|
+
- lib
|
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: 3.0.0
|
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
|
+
requirements:
|
|
91
|
+
- - ">="
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
requirements: []
|
|
95
|
+
rubygems_version: 3.5.23
|
|
96
|
+
signing_key:
|
|
97
|
+
specification_version: 4
|
|
98
|
+
summary: Extends Rails `dom_id` helper to support custom column-based identifiers
|
|
99
|
+
test_files: []
|