philiprehberger-slug 0.3.0 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +9 -0
- data/lib/philiprehberger/slug/version.rb +1 -1
- data/lib/philiprehberger/slug.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ca5f046f1ee001cf812dec361b6ba178a83c0028337fd8782638acb73ac7b66d
|
|
4
|
+
data.tar.gz: 89f3d660821048c7f5beda317de4df2921b34d05ede640f1720deb666eb1470a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 641d425370b27bba56a73b3a9170afdefa36f8b673a1e0f6b4b8e5e66372ee716745f4f7adf33fb31e0af3a528744124474d1a983a591b6a0a2ce3777b4332e0
|
|
7
|
+
data.tar.gz: 26b5610ba47ceb1fd4cbc9135d1bdbe69f1ea7a7198bf38e6691e557bc454e9f73844b3214ae0498f8439c572e25cb99bc07e8a35be8f7780383fce5c25d9474
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -104,11 +104,20 @@ Philiprehberger::Slug.humanize("hello_world", separator: "_") # => "Hello
|
|
|
104
104
|
Philiprehberger::Slug.transliterate("café résumé") # => "cafe resume"
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
+
### Rails-compatible Alias
|
|
108
|
+
|
|
109
|
+
For callers familiar with `ActiveSupport::Inflector#parameterize`:
|
|
110
|
+
|
|
111
|
+
```ruby
|
|
112
|
+
Philiprehberger::Slug.parameterize("Hello World!") # => "hello-world"
|
|
113
|
+
```
|
|
114
|
+
|
|
107
115
|
## API
|
|
108
116
|
|
|
109
117
|
| Method | Description |
|
|
110
118
|
|--------|-------------|
|
|
111
119
|
| `Slug.generate(string, separator:, max:, unique:, custom_mapping:)` | Generate a URL-safe slug from any string |
|
|
120
|
+
| `Slug.parameterize(string, separator:, max:, custom_mapping:)` | Rails-compatible alias for `generate` |
|
|
112
121
|
| `Slug.generate_batch(strings, separator:, max:, custom_mapping:)` | Generate unique slugs for an array of strings with deduplication |
|
|
113
122
|
| `Slug.valid_slug?(string, separator:)` | Check whether a string is a well-formed slug |
|
|
114
123
|
| `Slug.humanize(slug, separator:, capitalize:)` | Convert a slug back to a human-readable title |
|
data/lib/philiprehberger/slug.rb
CHANGED
|
@@ -21,6 +21,18 @@ module Philiprehberger
|
|
|
21
21
|
Generator.call(string, separator: separator, max: max, unique: unique, custom_mapping: custom_mapping)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
# Rails-compatible alias for `generate` for callers familiar with
|
|
25
|
+
# `ActiveSupport::Inflector#parameterize`.
|
|
26
|
+
#
|
|
27
|
+
# @param string [String] the input string
|
|
28
|
+
# @param separator [String] the separator character
|
|
29
|
+
# @param max [Integer, nil] maximum length, truncated at word boundary
|
|
30
|
+
# @param custom_mapping [Hash, nil] custom character replacements
|
|
31
|
+
# @return [String] the generated slug
|
|
32
|
+
def self.parameterize(string, separator: '-', max: nil, custom_mapping: nil)
|
|
33
|
+
generate(string, separator: separator, max: max, custom_mapping: custom_mapping)
|
|
34
|
+
end
|
|
35
|
+
|
|
24
36
|
# Generate unique slugs for an array of strings with automatic deduplication
|
|
25
37
|
#
|
|
26
38
|
# @param strings [Array<String>] the input strings
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-slug
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Generate URL-safe slugs from any string with built-in Unicode transliteration,
|
|
14
14
|
configurable separators, word-boundary truncation, and collision-aware uniqueness.
|