to_slug_param 1.7 → 1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/to_slug_param.rb +23 -5
- data/lib/to_slug_param/string.rb +22 -9
- data/spec/dummy_app/Gemfile +3 -2
- data/spec/dummy_app/config/environment.rb +1 -0
- data/spec/dummy_app/db/schema.rb +0 -1
- data/spec/dummy_app/spec/helpers/string.rb +298 -94
- data/to_slug_param.gemspec +2 -2
- metadata +6 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d29d5d09e8cb4e1cdd8aa8e016366cc72cb2e66
|
4
|
+
data.tar.gz: 598c16f0653e7b1ac43618e9971a09a54c4de9d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fb40ca2e727bf12b5ee5262db85fa4d76885beb5d31134983ca7928cdcebfd8027a910048d22936a6f670b69e41b12b3197bf6911dc0f4e1a86ffb2f3acaa4c
|
7
|
+
data.tar.gz: d2fc89966d2e32e9bb5070c1632beb7d12aa326202453cf6b855727e5077c0f399808792434b5c1f23f658dc11c2777698c2b7a373ac5513f654ed8897ec67b9
|
data/README.md
CHANGED
@@ -67,6 +67,15 @@ Params
|
|
67
67
|
"Документ.doc".to_slug_param(sep: '_', locale: :en) # => "doc"
|
68
68
|
```
|
69
69
|
|
70
|
+
#### HOW TO TEST
|
71
|
+
|
72
|
+
For testing there is a [Dummy App](./spec/dummy_app).
|
73
|
+
|
74
|
+
You can run specs for this Dymmy App and check if they pass.
|
75
|
+
|
76
|
+
- cd **spec/dummy_app**
|
77
|
+
- Follow **spec/dummy_app/README.md**
|
78
|
+
|
70
79
|
### MIT-LICENSE
|
71
80
|
|
72
81
|
##### Copyright (c) 2013-2014 [Ilya N.Zykin]
|
data/lib/to_slug_param.rb
CHANGED
@@ -6,15 +6,33 @@ require 'to_slug_param/symbol'
|
|
6
6
|
module ToSlugParam
|
7
7
|
class Engine < Rails::Engine; end
|
8
8
|
|
9
|
+
SPECIAL_SYMBOLS = %[`'"<>[]{}()-+?!/\\.:;|#\$@&*^%=~_]
|
10
|
+
|
11
|
+
REPLACE_SPEC_SYMB_REGEXP = Regexp.new(
|
12
|
+
SPECIAL_SYMBOLS.split('').map do |s|
|
13
|
+
Regexp.escape(s)
|
14
|
+
end.join('|')
|
15
|
+
)
|
16
|
+
|
9
17
|
class << self
|
10
|
-
def
|
11
|
-
str
|
18
|
+
def parameterize(str, sep)
|
19
|
+
str = str.to_s.strip.gsub(/[[:space:]]/, sep)
|
20
|
+
str = str.gsub(REPLACE_SPEC_SYMB_REGEXP, sep)
|
21
|
+
remove_sep_duplications(str, sep)
|
12
22
|
end
|
13
23
|
|
14
|
-
def
|
24
|
+
def remove_sep_duplications str, sep
|
25
|
+
escaped_sep = Regexp.escape sep
|
26
|
+
|
27
|
+
str.gsub(/\A#{escaped_sep}{1,}/, '')
|
28
|
+
.gsub(/#{escaped_sep}{2,}/, sep)
|
29
|
+
.gsub(/#{escaped_sep}{1,}\z/, '').to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def rails_to_param(str, sep)
|
15
33
|
Rails::VERSION::MAJOR > 4 ? \
|
16
|
-
|
17
|
-
|
34
|
+
ActiveSupport::Inflector.parameterize(str, separator: sep) : \
|
35
|
+
ActiveSupport::Inflector.parameterize(str, sep)
|
18
36
|
end
|
19
37
|
end
|
20
38
|
end
|
data/lib/to_slug_param/string.rb
CHANGED
@@ -23,23 +23,36 @@ class String
|
|
23
23
|
# Self methods
|
24
24
|
# -----------------------------------
|
25
25
|
class << self
|
26
|
+
def prepare_the_string(str, opts = {})
|
27
|
+
opts = opts.symbolize_keys
|
28
|
+
sep = opts[:sep] || '-'
|
29
|
+
str = str.to_s
|
30
|
+
|
31
|
+
ToSlugParam::parameterize(str, sep)
|
32
|
+
end
|
33
|
+
|
26
34
|
def to_slug_param str, opts = {}
|
27
35
|
to_smart_slug_param(str, opts)
|
28
36
|
end
|
29
37
|
|
30
38
|
def to_slug_param_base str, opts = {}
|
31
|
-
|
32
|
-
|
39
|
+
opts = opts.symbolize_keys
|
40
|
+
sep = opts[:sep] || '-'
|
41
|
+
|
42
|
+
str = prepare_the_string(str, opts).mb_chars
|
33
43
|
str = I18n::transliterate(str, opts)
|
34
|
-
str = ToSlugParam::
|
35
|
-
|
44
|
+
str = ToSlugParam::remove_sep_duplications(str, sep)
|
45
|
+
|
46
|
+
ToSlugParam::rails_to_param(str, sep)
|
36
47
|
end
|
37
48
|
|
38
49
|
def to_smart_slug_param str, opts = {}
|
39
|
-
|
50
|
+
opts = opts.symbolize_keys
|
51
|
+
tolerance = opts[:tolerance] || 75
|
52
|
+
str = prepare_the_string(str, opts)
|
40
53
|
|
41
|
-
x = str.to_slug_param_base
|
42
|
-
y = str.to_url
|
54
|
+
x = str.to_slug_param_base(opts)
|
55
|
+
y = prepare_the_string(str.to_url, opts)
|
43
56
|
|
44
57
|
ratio = (x.size.to_f/y.size.to_f)
|
45
58
|
|
@@ -55,13 +68,13 @@ class String
|
|
55
68
|
end
|
56
69
|
|
57
70
|
def file_ext file_name, opts = {}
|
58
|
-
File.extname(file_name)[1..-1].to_s.
|
71
|
+
File.extname(file_name)[1..-1].to_s.to_smart_slug_param opts
|
59
72
|
end
|
60
73
|
|
61
74
|
def file_name name, opts = {}
|
62
75
|
name = File.basename name
|
63
76
|
ext = File.extname name
|
64
|
-
File.basename(name, ext).to_s.
|
77
|
+
File.basename(name, ext).to_s.to_smart_slug_param opts
|
65
78
|
end
|
66
79
|
|
67
80
|
def slugged_filename name, opts = {}
|
data/spec/dummy_app/Gemfile
CHANGED
data/spec/dummy_app/db/schema.rb
CHANGED
@@ -2,131 +2,335 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe 'StringToSlug' do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
before(:each) { I18n.locale = :en }
|
6
|
+
after(:each) { I18n.locale = :en }
|
7
|
+
|
8
|
+
context "New checked API" do
|
9
|
+
context 'Check `parameterize` method' do
|
10
|
+
it "is true" do
|
11
|
+
expect(
|
12
|
+
ToSlugParam.parameterize('Hello \\\ /// `\'"<>[]{}()-+?!\/.:;$*^~ World!', '-')
|
13
|
+
).to eq("Hello-World")
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
context 'Check `to_slug_param_base` method' do
|
18
|
+
it "is true" do
|
19
|
+
I18n.locale = :ru
|
20
|
+
str = "Hello world its me Привет Мир 際 "
|
21
|
+
expect(str.to_slug_param_base).to eq("hello-world-its-me-privet-mir")
|
22
|
+
end
|
20
23
|
|
21
|
-
|
22
|
-
|
24
|
+
it "is true" do
|
25
|
+
I18n.locale = :ru
|
26
|
+
str = "際 際 際 Hello world its me 際 Привет Мир 際 "
|
27
|
+
expect(str.to_slug_param_base).to eq("hello-world-its-me-privet-mir")
|
28
|
+
end
|
23
29
|
|
24
|
-
"
|
25
|
-
|
30
|
+
it "is true" do
|
31
|
+
str = "際 際 際 Hello world its me 際 Привет Мир 際 "
|
32
|
+
expect(str.to_slug_param_base).to eq("hello-world-its-me")
|
33
|
+
end
|
26
34
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
35
|
+
it "is true" do
|
36
|
+
I18n.locale = :ru
|
37
|
+
expect("hey_-.+_)(/\\Мир".to_slug_param_base).to eq("hey-mir")
|
38
|
+
end
|
31
39
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
"Документ.doc".to_slug_param.should eq "dokument-doc"
|
36
|
-
end
|
40
|
+
it "is true" do
|
41
|
+
expect("hey_-.+_)(/\\Мир".to_slug_param_base).to eq("hey")
|
42
|
+
end
|
37
43
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
44
|
+
it "is true" do
|
45
|
+
I18n.locale = :en
|
46
|
+
expect("Документ.doc".to_slug_param_base).to eq("doc")
|
47
|
+
end
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
it "is true" do
|
50
|
+
expect(:"Документ.doc".to_slug_param_base(locale: :en)).to eq("doc")
|
51
|
+
end
|
47
52
|
|
48
|
-
"
|
49
|
-
|
50
|
-
|
51
|
-
"/доки/dir/тест/доку мент".slugged_filename.should eq "doku-ment"
|
53
|
+
it "is true" do
|
54
|
+
expect("Документ.doc".to_slug_param_base(locale: :en)).to eq("doc")
|
55
|
+
end
|
52
56
|
|
53
|
-
|
54
|
-
|
57
|
+
it "is true" do
|
58
|
+
expect("Документ.doc".to_slug_param_base(sep: '_', locale: :en)).to eq("doc")
|
59
|
+
end
|
55
60
|
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
it "is true" do
|
62
|
+
expect(:"Документ.doc".to_slug_param_base(sep: '_', locale: :en)).to eq("doc")
|
63
|
+
end
|
59
64
|
|
60
|
-
"
|
61
|
-
|
62
|
-
|
65
|
+
it "is true" do
|
66
|
+
I18n.locale = :ru
|
67
|
+
expect("Документ.doc".to_slug_param_base).to eq("dokument-doc")
|
68
|
+
end
|
63
69
|
|
64
|
-
|
65
|
-
|
66
|
-
|
70
|
+
it "is true" do
|
71
|
+
expect("Документ.doc".to_slug_param_base(locale: :ru)).to eq("dokument-doc")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "is true" do
|
75
|
+
expect(:"Документ.doc".to_slug_param_base(locale: :ru)).to eq("dokument-doc")
|
76
|
+
end
|
67
77
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
"/доки/dir/тест/документ.doc".slugged_filepath.should eq "/доки/dir/тест/dokument.doc"
|
72
|
-
"/доки/dir/тест/документ".slugged_filepath.should eq "/доки/dir/тест/dokument"
|
73
|
-
"/доки/dir/тест/доку мент".slugged_filepath.should eq "/доки/dir/тест/doku-ment"
|
78
|
+
it "is true" do
|
79
|
+
expect("Документ.doc".to_slug_param_base(sep: '_', locale: :ru)).to eq("dokument_doc")
|
80
|
+
end
|
74
81
|
|
75
|
-
|
82
|
+
it "is true" do
|
83
|
+
expect(:"Документ.doc".to_slug_param_base(sep: '_', locale: :ru)).to eq("dokument_doc")
|
84
|
+
end
|
76
85
|
end
|
77
86
|
|
78
|
-
|
79
|
-
|
80
|
-
|
87
|
+
context 'Check `to_url` method' do
|
88
|
+
it 'should be true' do
|
89
|
+
I18n.locale = :ru
|
90
|
+
str = "Hello world its me Привет Мир 際 "
|
91
|
+
expect(str.to_url).to eq("hello-world-its-me-priviet-mir-ji")
|
92
|
+
end
|
81
93
|
|
82
|
-
|
83
|
-
|
94
|
+
it 'should be true' do
|
95
|
+
I18n.locale = :ru
|
96
|
+
expect("Документ.doc".to_url).to eq("dokumient-tochka-doc")
|
97
|
+
end
|
84
98
|
|
85
|
-
|
86
|
-
|
87
|
-
|
99
|
+
it 'should be true' do
|
100
|
+
I18n.locale = :ru
|
101
|
+
str = "際 際 際 Hello world its me 際 Привет Мир 際 "
|
102
|
+
expect(str.to_url).to eq("ji-ji-ji-hello-world-its-me-ji-priviet-mir-ji")
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should be true' do
|
106
|
+
expect("Документ.doc".to_url).to eq("dokumient-dot-doc")
|
107
|
+
end
|
88
108
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
109
|
+
it 'should be true' do
|
110
|
+
I18n.locale = :ru
|
111
|
+
expect("hey_-.+_)(/\\Мир".to_url).to eq("hey-tochka-plius-sliesh-sliesh-mir")
|
112
|
+
end
|
93
113
|
|
94
|
-
|
95
|
-
|
96
|
-
|
114
|
+
it 'should be true' do
|
115
|
+
expect("hey_-.+_)(/\\Мир".to_url).to eq("hey-dot-plus-slash-slash-mir")
|
116
|
+
end
|
97
117
|
end
|
98
|
-
end
|
99
118
|
|
100
|
-
|
101
|
-
|
102
|
-
|
119
|
+
context 'String tests with fallback' do
|
120
|
+
it 'is true' do
|
121
|
+
str = "Hello world its me Привет Мир 際"
|
122
|
+
expect(str.to_smart_slug_param(tolerance: 90)).to eq("hello-world-its-me-priviet-mir-ji")
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'is true' do
|
126
|
+
str = "Hello world its me Привет Мир 際"
|
127
|
+
expect(str.to_smart_slug_param(tolerance: 50)).to eq("hello-world-its-me")
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'is true' do
|
131
|
+
I18n.locale = :ru
|
132
|
+
str = "Hello world its me Привет Мир 際"
|
133
|
+
expect(str.to_smart_slug_param(tolerance: 90)).to eq("hello-world-its-me-priviet-mir-ji")
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'is true' do
|
137
|
+
I18n.locale = :ru
|
138
|
+
str = "Hello world its me Привет Мир 際"
|
139
|
+
expect(str.to_smart_slug_param(tolerance: 50)).to eq("hello-world-its-me-privet-mir")
|
140
|
+
end
|
103
141
|
end
|
104
142
|
|
105
|
-
|
106
|
-
|
107
|
-
|
143
|
+
context 'String tests' do
|
144
|
+
it 'is true' do
|
145
|
+
expect("Привет Мир! Hello world!".to_slug_param(locale: :ru)).to eq("privet-mir-hello-world")
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'is true' do
|
149
|
+
expect("Привет Мир! Hello world!".to_slug_param(locale: :en)).to eq("priviet-mir-hello-world")
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'is true' do
|
153
|
+
expect("Документ.doc".to_slug_param(locale: :ru)).to eq("dokument-doc")
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'is true' do
|
157
|
+
expect("Документ.doc".to_slug_param(locale: :en)).to eq("dokumient-doc")
|
158
|
+
end
|
108
159
|
end
|
109
160
|
|
110
|
-
|
111
|
-
|
161
|
+
context 'Filename test' do
|
162
|
+
it 'is true' do
|
163
|
+
expect("/doc/dir/test/document.doc".to_slug_param).to eq("doc-dir-test-document-doc")
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'is true' do
|
167
|
+
expect("/doc/dir/test/document.doc".slugged_filename).to eq("document.doc")
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'is true' do
|
171
|
+
I18n.locale = :ru
|
172
|
+
expect("/доки/dir/тест/документ.doc".slugged_filename).to eq("dokument.doc")
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'is true' do
|
176
|
+
I18n.locale = :ru
|
177
|
+
expect("/доки/dir/тест/документ".slugged_filename).to eq("dokument")
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'is true' do
|
181
|
+
expect("/доки/dir/тест/доку мент".slugged_filename).to eq("doku-mient")
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'is true' do
|
185
|
+
expect(String.slugged_filename("/доки/dir/тест/доку мент")).to eq("doku-mient")
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'is true' do
|
189
|
+
expect("/doc/dir/test/document.doc".to_slug_param(locale: :ru)).to eq("doc-dir-test-document-doc")
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'is true' do
|
193
|
+
expect("/doc/dir/test/document.doc".slugged_filename(locale: :ru)).to eq("document.doc")
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'is true' do
|
197
|
+
expect("/доки/dir/тест/документ.doc".slugged_filename(locale: :en)).to eq("dokumient.doc")
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'is true' do
|
201
|
+
expect("/доки/dir/тест/документ".slugged_filename(locale: :en)).to eq("dokumient")
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'is true' do
|
205
|
+
expect("/доки/dir/тест/доку мент".slugged_filename(locale: :en)).to eq("doku-mient")
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'is true' do
|
209
|
+
expect(String.slugged_filename("/доки/dir/тест/доку мент", locale: :en)).to eq("doku-mient")
|
210
|
+
end
|
112
211
|
end
|
113
212
|
|
114
|
-
|
115
|
-
|
213
|
+
context 'Full path to file' do
|
214
|
+
it 'should be true' do
|
215
|
+
expect("/doc/dir/test/document.doc".slugged_filepath).to eq("/doc/dir/test/document.doc")
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'is true' do
|
219
|
+
I18n.locale = :ru
|
220
|
+
expect("/доки/dir/тест/документ.doc".slugged_filepath).to eq("/доки/dir/тест/dokument.doc")
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'is true' do
|
224
|
+
I18n.locale = :ru
|
225
|
+
expect("/доки/dir/тест/документ".slugged_filepath).to eq("/доки/dir/тест/dokument")
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'is true' do
|
229
|
+
I18n.locale = :ru
|
230
|
+
expect("/доки/dir/тест/доку мент".slugged_filepath).to eq("/доки/dir/тест/doku-ment")
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'is true' do
|
234
|
+
expect(String.slugged_filepath("/доки/dir/тест/доку мент")).to eq("/доки/dir/тест/doku-mient")
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'is true' do
|
238
|
+
expect("/doc/dir/test/document.doc".slugged_filepath(locale: :en)).to eq("/doc/dir/test/document.doc")
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'is true' do
|
242
|
+
expect("/доки/dir/тест/документ.doc".slugged_filepath(locale: :ru)).to eq("/доки/dir/тест/dokument.doc")
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'is true' do
|
246
|
+
expect("/доки/dir/тест/документ".slugged_filepath(locale: :en)).to eq("/доки/dir/тест/dokumient")
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'is true' do
|
250
|
+
expect("/доки/dir/тест/доку мент".slugged_filepath(locale: :en)).to eq("/доки/dir/тест/doku-mient")
|
251
|
+
end
|
116
252
|
|
117
|
-
|
118
|
-
|
119
|
-
|
253
|
+
it 'is true' do
|
254
|
+
expect(String.slugged_filepath("/доки/dir/тест/доку мент", locale: :en)).to eq("/доки/dir/тест/doku-mient")
|
255
|
+
end
|
120
256
|
end
|
121
257
|
|
122
|
-
|
123
|
-
|
124
|
-
|
258
|
+
context 'sep' do
|
259
|
+
it 'is true' do
|
260
|
+
I18n.locale = :ru
|
261
|
+
expect("Привет Мир! Hello world!".to_slug_param(sep: '_')).to eq("privet_mir_hello_world")
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'is true' do
|
265
|
+
expect("Привет Мир! Hello world!".to_slug_param(sep: '_')).to eq("priviet_mir_hello_world")
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'is true' do
|
269
|
+
expect("Документ.doc".to_slug_param(sep: '_')).to eq("dokumient_doc")
|
270
|
+
end
|
271
|
+
|
272
|
+
it 'is true' do
|
273
|
+
I18n.locale = :ru
|
274
|
+
expect("/доки/dir/тест/документ".slugged_filepath(sep: '_')).to eq("/доки/dir/тест/dokument")
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'is true' do
|
278
|
+
expect("/доки/dir/тест/доку мент".slugged_filepath(sep: '_')).to eq("/доки/dir/тест/doku_mient")
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'is true' do
|
282
|
+
expect("/доки/dir/тест/доку мент".slugged_filename(sep: '_')).to eq("doku_mient")
|
283
|
+
end
|
125
284
|
end
|
126
285
|
|
127
|
-
|
128
|
-
|
129
|
-
|
286
|
+
context "spec chars" do
|
287
|
+
it 'is true' do
|
288
|
+
expect(
|
289
|
+
"[$&+,:;=?@Hello <>[]{}()-+?!/\\.:;|#\$@&*^%=~_ world!#|'<>.^*()%!-]".to_slug_param
|
290
|
+
).to eq('hello-world')
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'is true' do
|
294
|
+
expect("教師 — the-teacher".to_slug_param(tolerance: 20)).to eq('the-teacher')
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'is true' do
|
298
|
+
expect("Hello ^, I'm here!".to_slug_param).to eq('hello-i-m-here')
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'is true' do
|
302
|
+
expect("HELLO---WorlD".to_slug_param(sep: '_')).to eq('hello_world')
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'is true' do
|
306
|
+
expect(
|
307
|
+
"__...HELLO-___--+++--WorlD----__&&***...__.---".to_slug_param
|
308
|
+
).to eq('hello-world')
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'is true' do
|
312
|
+
expect(
|
313
|
+
"__...HELLO-___--+++--WorlD----__&&***...__.---".to_slug_param(sep: '_')
|
314
|
+
).to eq('hello_world')
|
315
|
+
end
|
316
|
+
|
317
|
+
it 'is true' do
|
318
|
+
expect(
|
319
|
+
"__...HELLO-___--+++--WorlD----__&&***...__.---".to_slug_param(sep: '+')
|
320
|
+
).to eq('hello+plus+world')
|
321
|
+
end
|
322
|
+
|
323
|
+
it 'is true' do
|
324
|
+
expect(
|
325
|
+
"Ilya zykin aka Killich, $$$ aka the-teacher".to_slug_param(sep: '+')
|
326
|
+
).to eq("ilya+plus+zykin+plus+aka+plus+killich+plus+aka+plus+the+plus+teacher")
|
327
|
+
end
|
328
|
+
|
329
|
+
it 'is true' do
|
330
|
+
expect(
|
331
|
+
"Илья Николаевич, прекратите кодить по выходным!".to_sym.to_slug_param
|
332
|
+
).to eq("ilia-nikolaievich-priekratitie-kodit-po-vykhodnym")
|
333
|
+
end
|
130
334
|
end
|
131
335
|
end
|
132
336
|
|
@@ -134,14 +338,14 @@ describe 'StringToSlug' do
|
|
134
338
|
it "should work with Nested Controller Name" do
|
135
339
|
class PagesController < ApplicationController; end
|
136
340
|
ctrl = PagesController.new
|
137
|
-
ctrl.controller_path.to_slug_param.
|
341
|
+
expect(ctrl.controller_path.to_slug_param).to eq('pages')
|
138
342
|
end
|
139
343
|
|
140
344
|
it "should work with Nested Controller Name" do
|
141
345
|
module Admin; end
|
142
346
|
class Admin::PagesController < ApplicationController; end
|
143
347
|
ctrl = Admin::PagesController.new
|
144
|
-
ctrl.controller_path.to_slug_param.
|
348
|
+
expect(ctrl.controller_path.to_slug_param).to eq('admin-pages')
|
145
349
|
end
|
146
350
|
|
147
351
|
it "should work with Nested Controller Name" do
|
@@ -149,7 +353,7 @@ describe 'StringToSlug' do
|
|
149
353
|
class Admin::PagesController < ApplicationController; end
|
150
354
|
ctrl = Admin::PagesController.new
|
151
355
|
params = { sep: '_' }
|
152
|
-
ctrl.controller_path.to_slug_param(params).
|
356
|
+
expect(ctrl.controller_path.to_slug_param(params)).to eq('admin_pages')
|
153
357
|
end
|
154
358
|
end
|
155
359
|
end
|
data/to_slug_param.gemspec
CHANGED
@@ -3,7 +3,7 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
|
5
5
|
module ToSlugParam
|
6
|
-
VERSION = "1.
|
6
|
+
VERSION = "1.8"
|
7
7
|
end
|
8
8
|
|
9
9
|
Gem::Specification.new do |spec|
|
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'rake', '>= 0', '< 14.0'
|
25
25
|
spec.add_runtime_dependency 'rails-i18n', '>= 0', '< 7.0'
|
26
26
|
spec.add_runtime_dependency 'rails', '>= 4.0.3', '< 7.0'
|
27
|
-
spec.add_runtime_dependency 'stringex', '
|
27
|
+
spec.add_runtime_dependency 'stringex', '2.8.5'
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_slug_param
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.8'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya N. Zykin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -74,22 +74,16 @@ dependencies:
|
|
74
74
|
name: stringex
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version: 2.7.1
|
80
|
-
- - "<"
|
77
|
+
- - '='
|
81
78
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
79
|
+
version: 2.8.5
|
83
80
|
type: :runtime
|
84
81
|
prerelease: false
|
85
82
|
version_requirements: !ruby/object:Gem::Requirement
|
86
83
|
requirements:
|
87
|
-
- -
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 2.7.1
|
90
|
-
- - "<"
|
84
|
+
- - '='
|
91
85
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
86
|
+
version: 2.8.5
|
93
87
|
description: " Convert strings and symbols to slug param "
|
94
88
|
email:
|
95
89
|
- zykin-ilya@ya.ru
|