stealth_dom_id 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b2873eeed2f0437b75fe061a5261673f08992c186a60349c2460f63bdfbc007
4
- data.tar.gz: 8ba04b34323b83b852f172a97a3ff4af9bc7756da6a1185e47ea34501465bd52
3
+ metadata.gz: bf34f14ddf5664d87736392bf155b9e62537479b04f54cc71fa079907ab5a152
4
+ data.tar.gz: 1b0a148be68c737e327a8c39f5bb611c7ac4cc1785b706750b9234dbcabc8278
5
5
  SHA512:
6
- metadata.gz: 6bf8818c874009b129f470fb5d9742ecb58e8f8bdf3abe81b20f725a80b62ccb7c20bf0f8b2e7535c1d5f7a8ca8aa8e336884d849b781e3a4ea1858d7a5ac441
7
- data.tar.gz: 7deef458663e54886b5ed878bab0b2365fe4c61509cb0446899d228ada8d404ab45046c2e542043cbdfc6a475b56f41a446d0c2080b2ecc1963051553c7c1c97
6
+ metadata.gz: d84dad44771f169545508d05df8d205e36f831ff7eaba8ec18014d41482acbc8980216b0f4ee82cb512d2cef537f883a3230c71536d4b9ec1d19e58f231f318b
7
+ data.tar.gz: 97d53062743fe65d01ca52b140c56183d00107881c954c8893b0eead75b370394fdd499351438718e7c2b5468aec6a0d56dfbac9fbd64191c3e50f0409e660b5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stealth_dom_id (0.2.0)
4
+ stealth_dom_id (0.3.0)
5
5
  actionview (>= 3.0, < 8.1)
6
6
  activesupport (>= 3.0, < 8.1)
7
7
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # StealthDomId
1
+ # stealth_dom_id
2
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
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 an alternative attribute instead of database primary keys. This helps prevent exposing internal database IDs
4
4
 
5
5
 
6
6
  ## Installation
@@ -20,21 +20,21 @@ gem install stealth_dom_id
20
20
 
21
21
  ## Usage
22
22
 
23
- This gem extends Rails' `dom_id` helper to use alternative columns instead of exposing database IDs in your HTML elements.
23
+ This gem extends Rails' `dom_id` helper to use an alternative attribute instead of exposing database IDs in your HTML elements.
24
24
 
25
25
  Instead of:
26
26
  ```erb
27
27
  <%= dom_id(@user) %>
28
28
  # => "user_1"
29
29
 
30
- <%= dom_id(@user, column: :public_id) %>
30
+ <%= dom_id(@user, attribute: :public_id) %>
31
31
  # => Outputs: "user_a1b2c3"
32
32
  ```
33
33
 
34
- The `column` attribute is optional. `prefix` attribute is also supported.
34
+ `attribute` is optional. `prefix` attribute is, just with `dom_id`, also supported.
35
35
 
36
36
  ```erb
37
- <%= dom_id(@user, :admin, column: :public_id) %>
37
+ <%= dom_id(@user, :admin, attribute: :public_id) %>
38
38
  # => Outputs: "admin_user_a1b2c3"
39
39
  ```
40
40
 
@@ -1,11 +1,11 @@
1
1
  module StealthDomId
2
- class ColumnError < ArgumentError; end
2
+ class AttributeError < ArgumentError; end
3
3
 
4
4
  module Core
5
- def dom_id(record_or_class, prefix = nil, column: nil)
5
+ def dom_id(record_or_class, prefix = nil, attribute: nil)
6
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)
7
+ record_id = if attribute
8
+ record_key_for_dom_id_by_attribute(record_or_class, attribute: attribute)
9
9
  else
10
10
  record_key_for_dom_id(record_or_class)
11
11
  end
@@ -23,12 +23,12 @@ module StealthDomId
23
23
  JOIN = "_".freeze
24
24
  NEW = "new".freeze
25
25
 
26
- def record_key_for_dom_id_by_column(record, column:)
27
- key = [convert_to_model(record).send(column)]
26
+ def record_key_for_dom_id_by_attribute(record, attribute:)
27
+ key = [convert_to_model(record).send(attribute)]
28
28
 
29
29
  key ? key.join(JOIN) : key
30
30
  rescue NoMethodError => e
31
- raise ColumnError, "[StealthDomId] Column '#{column}' not found on #{record.class}"
31
+ raise AttributeError, "[StealthDomId] Attribute '#{attribute}' not found on #{record.class}"
32
32
  end
33
33
  end
34
34
  end
@@ -4,6 +4,10 @@ module StealthDomId
4
4
  ActiveSupport.on_load(:action_view) do
5
5
  include StealthDomId::Core
6
6
  end
7
+
8
+ ActiveSupport.on_load(:view_component) do
9
+ ViewComponent::Base.include StealthDomId::Core
10
+ end
7
11
  end
8
12
  end
9
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StealthDomId
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -1,13 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "stealth_dom_id/version"
3
+ # require "active_support"
4
+ require "stealth_dom_id/version"
4
5
  require "stealth_dom_id/core"
5
- require "active_support"
6
+ require "stealth_dom_id/railtie" if defined?(Rails)
6
7
 
7
8
  module StealthDomId
8
9
  class Error < StandardError; end
9
10
  end
10
-
11
- ActiveSupport.on_load(:action_view) do
12
- include StealthDomId::Core
13
- end
@@ -8,13 +8,12 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Rails Designer Developers"]
9
9
  spec.email = ["devs@railsdesigner.com"]
10
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."
11
+ spec.summary = "Extends Rails `dom_id` helper to support custom attribute-based identifiers (example “slug”)"
12
+ spec.description = "stealth_dom_id extends Rails' `dom_id` helper to generate DOM IDs using an alternative attribute instead of database primary keys. This helps prevent exposing internal database IDs."
13
13
  spec.homepage = "https://github.com/Rails-Designer/stealth_dom_id/"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 3.0.0"
16
16
 
17
- spec.metadata["homepage_uri"] = spec.homepage
18
17
  spec.metadata["source_code_uri"] = "https://github.com/Rails-Designer/stealth_dom_id/"
19
18
 
20
19
  spec.files = Dir["{bin,app,config,db,lib,public}/**/*", "Rakefile", "README.md", "stealth_dom_id.gemspec", "Gemfile", "Gemfile.lock"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stealth_dom_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rails Designer Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-06 00:00:00.000000000 Z
11
+ date: 2024-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -50,8 +50,8 @@ dependencies:
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
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
53
+ description: stealth_dom_id extends Rails' `dom_id` helper to generate DOM IDs using
54
+ an alternative attribute instead of database primary keys. This helps prevent exposing
55
55
  internal database IDs.
56
56
  email:
57
57
  - devs@railsdesigner.com
@@ -75,7 +75,6 @@ homepage: https://github.com/Rails-Designer/stealth_dom_id/
75
75
  licenses:
76
76
  - MIT
77
77
  metadata:
78
- homepage_uri: https://github.com/Rails-Designer/stealth_dom_id/
79
78
  source_code_uri: https://github.com/Rails-Designer/stealth_dom_id/
80
79
  post_install_message:
81
80
  rdoc_options: []
@@ -95,5 +94,6 @@ requirements: []
95
94
  rubygems_version: 3.5.23
96
95
  signing_key:
97
96
  specification_version: 4
98
- summary: Extends Rails `dom_id` helper to support custom column-based identifiers
97
+ summary: Extends Rails `dom_id` helper to support custom attribute-based identifiers
98
+ (example “slug”)
99
99
  test_files: []