to_slug_param 1.7 → 1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c5c22e7e3337b7ea544788089b3e007b26b8f23
4
- data.tar.gz: e66d52d8b1c9e72d28fde1eb8af6ff3766013680
3
+ metadata.gz: 5d29d5d09e8cb4e1cdd8aa8e016366cc72cb2e66
4
+ data.tar.gz: 598c16f0653e7b1ac43618e9971a09a54c4de9d8
5
5
  SHA512:
6
- metadata.gz: 43c5a349ac77790c3a43bb381dae9be38aec025ea46931737cf023566552e62ba03de114d23425ec55908d54caa1d8dc1eca3a06e0560dd8aa2c32e92d8e0e35
7
- data.tar.gz: 3c78fdbe617d73ae2e103903a58adccb4fb8cebd1664b9f8a635027b27311f099c6147db1eef31782ff115db8ea39fbf47f76a36fd513eb791de47e4382b05f0
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]
@@ -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 basic_parameterize(str, sep)
11
- str.gsub('_', sep).gsub('-', sep)
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 parameterize(str, sep)
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
- str.parameterize(separator: sep) : \
17
- str.parameterize(sep)
34
+ ActiveSupport::Inflector.parameterize(str, separator: sep) : \
35
+ ActiveSupport::Inflector.parameterize(str, sep)
18
36
  end
19
37
  end
20
38
  end
@@ -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
- sep = opts.delete(:sep) || '-'
32
- str = str.gsub(/\-{2,}/, '-').mb_chars
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::basic_parameterize(sep, opts)
35
- ToSlugParam::parameterize(sep, opts)
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
- tolerance = opts.delete(:tolerance) || 75
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.to_slug_param_base opts
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.to_slug_param_base opts
77
+ File.basename(name, ext).to_s.to_smart_slug_param opts
65
78
  end
66
79
 
67
80
  def slugged_filename name, opts = {}
@@ -1,8 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rails', '4.0.0'
3
+ gem 'rails', '5.2.0'
4
4
 
5
- gem 'sqlite3'
5
+ gem 'sqlite3', '~> 1.3', '< 1.4'
6
+ gem 'pry'
6
7
  gem 'rspec'
7
8
  gem 'rspec-rails'
8
9
  gem 'to_slug_param', path: '../../'
@@ -1,5 +1,6 @@
1
1
  # Load the Rails application.
2
2
  require File.expand_path('../application', __FILE__)
3
+ require 'sqlite3'
3
4
 
4
5
  # Initialize the Rails application.
5
6
  DummyApp::Application.initialize!
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
@@ -2,131 +2,335 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe 'StringToSlug' do
5
- context 'String tests with fallback' do
6
- it 'should be true' do
7
- str = "Hello world its me Привет Мир 際"
8
-
9
- I18n.locale = :en
10
- str.to_smart_slug_param(tolerance: 90).should eq "hello-world-its-me-priviet-mir-ji"
11
- str.to_smart_slug_param(tolerance: 50).should eq "hello-world-its-me"
12
- I18n.locale = :ru
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
- context "readme" do
17
- it "testcase 1" do
18
- "Документ.doc".to_slug_param(locale: :ru).should eq "dokument-doc"
19
- "Документ.doc".to_slug_param(locale: :en).should eq "doc"
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
- :"Документ.doc".to_slug_param(locale: :ru).should eq "dokument-doc"
22
- :"Документ.doc".to_slug_param(locale: :en).should eq "doc"
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
- "Документ.doc".to_slug_param(sep: '_', locale: :ru).should eq "dokument_doc"
25
- "Документ.doc".to_slug_param(sep: '_', locale: :en).should eq "doc"
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
- :"Документ.doc".to_slug_param(sep: '_', locale: :ru).should eq "dokument_doc"
28
- :"Документ.doc".to_slug_param(sep: '_', locale: :en).should eq "doc"
29
- end
30
- end
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
- context 'String tests' do
33
- it 'should be true' do
34
- "Привет Мир! Hello world!".to_slug_param.should eq "privet-mir-hello-world"
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
- it 'When wrong translation' do
39
- "Привет Мир! Hello world!".to_slug_param(locale: :en).should eq "hello-world"
40
- "Документ.doc".to_slug_param(locale: :en).should eq "doc"
41
- end
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
- context 'Filename test' do
45
- it 'should be true' do
46
- "/doc/dir/test/document.doc".to_slug_param.should eq "doc-dir-test-document-doc"
49
+ it "is true" do
50
+ expect(:"Документ.doc".to_slug_param_base(locale: :en)).to eq("doc")
51
+ end
47
52
 
48
- "/doc/dir/test/document.doc".slugged_filename.should eq "document.doc"
49
- "/доки/dir/тест/документ.doc".slugged_filename.should eq "dokument.doc"
50
- "/доки/dir/тест/документ".slugged_filename.should eq "dokument"
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
- String.slugged_filename("/доки/dir/тест/доку мент").should eq "doku-ment"
54
- end
57
+ it "is true" do
58
+ expect("Документ.doc".to_slug_param_base(sep: '_', locale: :en)).to eq("doc")
59
+ end
55
60
 
56
- it 'When wrong translation' do
57
- "/doc/dir/test/document.doc".to_slug_param(locale: :ru).should eq "doc-dir-test-document-doc"
58
- "/doc/dir/test/document.doc".slugged_filename(locale: :ru).should eq "document.doc"
61
+ it "is true" do
62
+ expect(:"Документ.doc".to_slug_param_base(sep: '_', locale: :en)).to eq("doc")
63
+ end
59
64
 
60
- "/доки/dir/тест/документ.doc".slugged_filename(locale: :en).should eq ".doc"
61
- "/доки/dir/тест/документ".slugged_filename(locale: :en).should eq ""
62
- "/доки/dir/тест/доку мент".slugged_filename(locale: :en).should eq ""
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
- String.slugged_filename("/доки/dir/тест/доку мент", locale: :en).should eq ""
65
- end
66
- end
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
- context 'Full path to file' do
69
- it 'should be true' do
70
- "/doc/dir/test/document.doc".slugged_filepath.should eq "/doc/dir/test/document.doc"
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
- String.slugged_filepath("/доки/dir/тест/доку мент").should eq "/доки/dir/тест/doku-ment"
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
- it 'When wrong translation' do
79
- "/doc/dir/test/document.doc".slugged_filepath(locale: :en).should eq "/doc/dir/test/document.doc"
80
- "/доки/dir/тест/документ.doc".slugged_filepath(locale: :en).should eq "/доки/dir/тест/.doc"
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
- "/доки/dir/тест/документ".slugged_filepath(locale: :en).should eq "/доки/dir/тест/"
83
- "/доки/dir/тест/доку мент".slugged_filepath(locale: :en).should eq "/доки/dir/тест/"
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
- String.slugged_filepath("/доки/dir/тест/доку мент", locale: :en).should eq "/доки/dir/тест/"
86
- end
87
- end
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
- context 'sep' do
90
- it 'should be true' do
91
- "Привет Мир! Hello world!".to_slug_param(sep: '_').should eq "privet_mir_hello_world"
92
- "Документ.doc".to_slug_param(sep: '_').should eq "dokument_doc"
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
- "/доки/dir/тест/документ".slugged_filepath(sep: '_').should eq "/доки/dir/тест/dokument"
95
- "/доки/dir/тест/доку мент".slugged_filepath(sep: '_').should eq "/доки/dir/тест/doku_ment"
96
- "/доки/dir/тест/доку мент".slugged_filename(sep: '_').should eq "doku_ment"
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
- context "spec chars" do
101
- it "should works" do
102
- "[$&+,:;=?@Hello world!#|'<>.^*()%!-]".to_slug_param.should eq 'hello-world'
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
- it "should works" do
106
- "教師 the-teacher".to_slug_param.should eq 'the-teacher'
107
- "Hello ^, I'm here!".to_slug_param.should eq 'hello-i-m-here'
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
- it "should works" do
111
- "HELLO---WorlD".to_slug_param(sep: '_').should eq 'hello_world'
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
- it "should works" do
115
- str = "__...HELLO-___--+++--WorlD----__&&***...__.---"
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
- str.to_slug_param.should eq 'hello-world'
118
- str.to_slug_param(sep: '_').should eq 'hello_world'
119
- str.to_slug_param(sep: '+').should eq 'hello+world'
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
- it "should works" do
123
- str = "Ilya zykin aka Killich, $$$ aka the-teacher"
124
- str.to_slug_param(sep: '+').should eq "ilya+zykin+aka+killich+aka+the+teacher"
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
- it "should works" do
128
- str = "Илья Николаевич, прекратите кодить по выходным!".to_sym
129
- str.to_slug_param.should eq "ilya-nikolaevich-prekratite-kodit-po-vyhodnym"
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.should eq 'pages'
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.should eq 'admin-pages'
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).should eq 'admin_pages'
356
+ expect(ctrl.controller_path.to_slug_param(params)).to eq('admin_pages')
153
357
  end
154
358
  end
155
359
  end
@@ -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.7"
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', '>= 2.7.1', '< 3.0'
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.7'
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-10-27 00:00:00.000000000 Z
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: '3.0'
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: '3.0'
86
+ version: 2.8.5
93
87
  description: " Convert strings and symbols to slug param "
94
88
  email:
95
89
  - zykin-ilya@ya.ru