the_string_to_slug 1.1 → 1.2

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
  SHA1:
3
- metadata.gz: 4a4835e1fce9b86bfd6d2972a1962e2e49cd3fb2
4
- data.tar.gz: bb2cc21692b00c62be219635b3481c5e23a878d2
3
+ metadata.gz: 05c1fda589a9fd82d7b6ca75d4d3143c31bbd986
4
+ data.tar.gz: 4a64890bbc945bd88981a75ef57541cfe9b0f885
5
5
  SHA512:
6
- metadata.gz: 0b2c161d669135b2a8859f5a434f2605d440d34f14b55ad22825034d5642389efe1088ff486b85afee2867922c71f5f03714a4d201c1fb9cea3f2fcb7ce63607
7
- data.tar.gz: 85f45fe0904df42af44f4e277763c9a3b3b666a472735e1c2c9ad82118c6cf18a524ecb344c60786dc3bcc3f6879f0c9f7709c962839c1ab0ac3217d4d0d5af4
6
+ metadata.gz: 2e88afcd87802f6556925d7f0564a9ac883d4201feb1182798e75255df314ff2aad34e9aa117a340e0710ff8975ba2e133b7e079374c3ae85339aa35a5c0f1e7
7
+ data.tar.gz: 423d241fb30aee3902460fd36efbd460453af2538b71541f1a3dff751a537d81805a375ef58866d0921d0ea20d77afd9d4c7547bdd2b5eceb50f809071d0c40c
data/README.md CHANGED
@@ -1,19 +1,31 @@
1
1
  ### TheStringToSlug
2
2
 
3
- Convert text string to slug param
3
+ Convert strings and symbols to slug param
4
4
 
5
- Translite, downcase, parameterize
5
+ Transliteration + Parameterization for slugs building
6
6
 
7
7
  #### Install
8
8
 
9
9
  ```ruby
10
- gem "the_string_to_slug", "~> 0.0.5"
10
+ gem "the_string_to_slug", "~> 1.2"
11
11
  ```
12
12
 
13
13
  <a href="http://rubygems.org/gems/the_string_to_slug">RubyGems/the_string_to_slug</a>
14
14
 
15
15
  #### Using
16
16
 
17
+ For russian transliteration by default
18
+
19
+ ```ruby
20
+ I18n.enforce_available_locales = true
21
+
22
+ module DummyApp
23
+ class Application < Rails::Application
24
+ config.i18n.default_locale = :ru
25
+ end
26
+ end
27
+ ```
28
+
17
29
  ```ruby
18
30
  "Привет Мир! Hello world!".to_slug_param
19
31
  # => "privet-mir-hello-world"
@@ -39,21 +51,41 @@ String.slugged_filename("/доки/dir/тест/документ.doc") #=> "doku
39
51
  For full file path:
40
52
 
41
53
  ```ruby
42
- "/доки/dir/тест/документ.doc".slugged_file #=> "/доки/dir/тест/dokument.doc"
43
- String.slugged_filename("/доки/dir/тест/документ.doc") #=> "/доки/dir/тест/dokument.doc"
54
+ "/доки/dir/тест/документ.doc".slugged_filepath #=> "/доки/dir/тест/dokument.doc"
55
+ String.slugged_filepath("/доки/dir/тест/документ.doc") #=> "/доки/dir/тест/dokument.doc"
44
56
  ```
45
57
 
46
58
  Params
47
59
 
48
60
  ```ruby
49
- "Документ.doc".to_slug_param(locale: :en)
50
- # => "doc"
51
-
52
- "Документ.doc".to_slug_param(locale: :en)
53
- # => "dokument-doc"
61
+ "Документ.doc".to_slug_param(locale: :ru) # => "dokument-doc"
62
+ "Документ.doc".to_slug_param(locale: :en) # => "doc"
54
63
  ```
55
64
 
56
65
  ```ruby
57
- "Документ.doc".to_slug_param(delimiter: '_')
58
- # => "dokument_doc"
59
- ```
66
+ "Документ.doc".to_slug_param(sep: '_', locale: :ru) # => "dokument_doc"
67
+ "Документ.doc".to_slug_param(sep: '_', locale: :en) # => "doc"
68
+ ```
69
+
70
+ ### MIT-LICENSE
71
+
72
+ ##### Copyright (c) 2013-2014 [Ilya N.Zykin]
73
+
74
+ Permission is hereby granted, free of charge, to any person obtaining
75
+ a copy of this software and associated documentation files (the
76
+ "Software"), to deal in the Software without restriction, including
77
+ without limitation the rights to use, copy, modify, merge, publish,
78
+ distribute, sublicense, and/or sell copies of the Software, and to
79
+ permit persons to whom the Software is furnished to do so, subject to
80
+ the following conditions:
81
+
82
+ The above copyright notice and this permission notice shall be
83
+ included in all copies or substantial portions of the Software.
84
+
85
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
88
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
89
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
90
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
91
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,3 +1,3 @@
1
1
  module TheStringToSlug
2
- VERSION = "1.1"
2
+ VERSION = "1.2"
3
3
  end
@@ -12,8 +12,8 @@ class String
12
12
  self.class.slugged_filename(self, opts)
13
13
  end
14
14
 
15
- def slugged_file opts = {}
16
- self.class.slugged_file(self, opts)
15
+ def slugged_filepath opts = {}
16
+ self.class.slugged_filepath(self, opts)
17
17
  end
18
18
 
19
19
  # -----------------------------------
@@ -21,13 +21,13 @@ class String
21
21
  # -----------------------------------
22
22
  class << self
23
23
  def to_slug_param str, opts = {}
24
- delimiter = opts.delete(:delimiter) || '-'
24
+ sep = opts.delete(:sep) || '-'
25
25
  str = str.gsub(/\-{2,}/, '-').mb_chars
26
26
  str = I18n::transliterate(str, opts)
27
- .gsub('_', delimiter)
28
- .gsub('-', delimiter)
29
- .parameterize(delimiter)
30
- .downcase.to_s
27
+ .gsub('_', sep)
28
+ .gsub('-', sep)
29
+ .parameterize(sep)
30
+ .to_s
31
31
  end
32
32
 
33
33
  def file_ext file_name, opts = {}
@@ -49,9 +49,23 @@ class String
49
49
  [fname, ext].join('.')
50
50
  end
51
51
 
52
- def slugged_file file_full_path, opts = {}
52
+ def slugged_filepath file_full_path, opts = {}
53
53
  fname = slugged_filename file_full_path, opts
54
54
  file_full_path.split('/')[0...-1].push(fname).join '/'
55
55
  end
56
56
  end
57
+ end
58
+
59
+ class Symbol
60
+ def to_slug_param opts = {}
61
+ String.to_slug_param(self.to_s, opts)
62
+ end
63
+
64
+ def slugged_filename opts = {}
65
+ String.slugged_filename(self.to_s, opts)
66
+ end
67
+
68
+ def slugged_filepath opts = {}
69
+ String.slugged_file(self.to_s, opts)
70
+ end
57
71
  end
@@ -2,6 +2,22 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe 'StringToSlug' do
5
+ context "readme" do
6
+ it "testcase 1" do
7
+ "Документ.doc".to_slug_param(locale: :ru).should eq "dokument-doc"
8
+ "Документ.doc".to_slug_param(locale: :en).should eq "doc"
9
+
10
+ :"Документ.doc".to_slug_param(locale: :ru).should eq "dokument-doc"
11
+ :"Документ.doc".to_slug_param(locale: :en).should eq "doc"
12
+
13
+ "Документ.doc".to_slug_param(sep: '_', locale: :ru).should eq "dokument_doc"
14
+ "Документ.doc".to_slug_param(sep: '_', locale: :en).should eq "doc"
15
+
16
+ :"Документ.doc".to_slug_param(sep: '_', locale: :ru).should eq "dokument_doc"
17
+ :"Документ.doc".to_slug_param(sep: '_', locale: :en).should eq "doc"
18
+ end
19
+ end
20
+
5
21
  context 'String tests' do
6
22
  it 'should be true' do
7
23
  "Привет Мир! Hello world!".to_slug_param.should eq "privet-mir-hello-world"
@@ -17,6 +33,7 @@ describe 'StringToSlug' do
17
33
  context 'Filename test' do
18
34
  it 'should be true' do
19
35
  "/doc/dir/test/document.doc".to_slug_param.should eq "doc-dir-test-document-doc"
36
+
20
37
  "/doc/dir/test/document.doc".slugged_filename.should eq "document.doc"
21
38
  "/доки/dir/тест/документ.doc".slugged_filename.should eq "dokument.doc"
22
39
  "/доки/dir/тест/документ".slugged_filename.should eq "dokument"
@@ -39,33 +56,33 @@ describe 'StringToSlug' do
39
56
 
40
57
  context 'Full path to file' do
41
58
  it 'should be true' do
42
- "/doc/dir/test/document.doc".slugged_file.should eq "/doc/dir/test/document.doc"
43
- "/доки/dir/тест/документ.doc".slugged_file.should eq "/доки/dir/тест/dokument.doc"
44
- "/доки/dir/тест/документ".slugged_file.should eq "/доки/dir/тест/dokument"
45
- "/доки/dir/тест/доку мент".slugged_file.should eq "/доки/dir/тест/doku-ment"
59
+ "/doc/dir/test/document.doc".slugged_filepath.should eq "/doc/dir/test/document.doc"
60
+ "/доки/dir/тест/документ.doc".slugged_filepath.should eq "/доки/dir/тест/dokument.doc"
61
+ "/доки/dir/тест/документ".slugged_filepath.should eq "/доки/dir/тест/dokument"
62
+ "/доки/dir/тест/доку мент".slugged_filepath.should eq "/доки/dir/тест/doku-ment"
46
63
 
47
- String.slugged_file("/доки/dir/тест/доку мент").should eq "/доки/dir/тест/doku-ment"
64
+ String.slugged_filepath("/доки/dir/тест/доку мент").should eq "/доки/dir/тест/doku-ment"
48
65
  end
49
66
 
50
67
  it 'When wrong translation' do
51
- "/doc/dir/test/document.doc".slugged_file(locale: :en).should eq "/doc/dir/test/document.doc"
52
- "/доки/dir/тест/документ.doc".slugged_file(locale: :en).should eq "/доки/dir/тест/.doc"
68
+ "/doc/dir/test/document.doc".slugged_filepath(locale: :en).should eq "/doc/dir/test/document.doc"
69
+ "/доки/dir/тест/документ.doc".slugged_filepath(locale: :en).should eq "/доки/dir/тест/.doc"
53
70
 
54
- "/доки/dir/тест/документ".slugged_file(locale: :en).should eq "/доки/dir/тест/"
55
- "/доки/dir/тест/доку мент".slugged_file(locale: :en).should eq "/доки/dir/тест/"
71
+ "/доки/dir/тест/документ".slugged_filepath(locale: :en).should eq "/доки/dir/тест/"
72
+ "/доки/dir/тест/доку мент".slugged_filepath(locale: :en).should eq "/доки/dir/тест/"
56
73
 
57
- String.slugged_file("/доки/dir/тест/доку мент", locale: :en).should eq "/доки/dir/тест/"
74
+ String.slugged_filepath("/доки/dir/тест/доку мент", locale: :en).should eq "/доки/dir/тест/"
58
75
  end
59
76
  end
60
77
 
61
- context 'Delimiter' do
78
+ context 'sep' do
62
79
  it 'should be true' do
63
- "Привет Мир! Hello world!".to_slug_param(delimiter: '_').should eq "privet_mir_hello_world"
64
- "Документ.doc".to_slug_param(delimiter: '_').should eq "dokument_doc"
80
+ "Привет Мир! Hello world!".to_slug_param(sep: '_').should eq "privet_mir_hello_world"
81
+ "Документ.doc".to_slug_param(sep: '_').should eq "dokument_doc"
65
82
 
66
- "/доки/dir/тест/документ".slugged_file(delimiter: '_').should eq "/доки/dir/тест/dokument"
67
- "/доки/dir/тест/доку мент".slugged_file(delimiter: '_').should eq "/доки/dir/тест/doku_ment"
68
- "/доки/dir/тест/доку мент".slugged_filename(delimiter: '_').should eq "doku_ment"
83
+ "/доки/dir/тест/документ".slugged_filepath(sep: '_').should eq "/доки/dir/тест/dokument"
84
+ "/доки/dir/тест/доку мент".slugged_filepath(sep: '_').should eq "/доки/dir/тест/doku_ment"
85
+ "/доки/dir/тест/доку мент".slugged_filename(sep: '_').should eq "doku_ment"
69
86
  end
70
87
  end
71
88
 
@@ -80,20 +97,25 @@ describe 'StringToSlug' do
80
97
  end
81
98
 
82
99
  it "should works" do
83
- "HELLO---WorlD".to_slug_param(delimiter: '_').should eq 'hello_world'
100
+ "HELLO---WorlD".to_slug_param(sep: '_').should eq 'hello_world'
84
101
  end
85
102
 
86
103
  it "should works" do
87
104
  str = "__...HELLO-___--+++--WorlD----__&&***...__.---"
88
105
 
89
106
  str.to_slug_param.should eq 'hello-world'
90
- str.to_slug_param(delimiter: '_').should eq 'hello_world'
91
- str.to_slug_param(delimiter: '+').should eq 'hello+world'
107
+ str.to_slug_param(sep: '_').should eq 'hello_world'
108
+ str.to_slug_param(sep: '+').should eq 'hello+world'
92
109
  end
93
110
 
94
111
  it "should works" do
95
112
  str = "Ilya zykin aka Killich, $$$ aka the-teacher"
96
- str.to_slug_param(delimiter: '+').should eq "ilya+zykin+aka+killich+aka+the+teacher"
113
+ str.to_slug_param(sep: '+').should eq "ilya+zykin+aka+killich+aka+the+teacher"
114
+ end
115
+
116
+ it "should works" do
117
+ str = "Илья Николаевич, прекратите кодить по выходным!".to_sym
118
+ str.to_slug_param.should eq "ilya-nikolaevich-prekratite-kodit-po-vyhodnym"
97
119
  end
98
120
  end
99
121
 
@@ -115,7 +137,7 @@ describe 'StringToSlug' do
115
137
  module Admin; end
116
138
  class Admin::PagesController < ApplicationController; end
117
139
  ctrl = Admin::PagesController.new
118
- params = { delimiter: '_' }
140
+ params = { sep: '_' }
119
141
  ctrl.controller_path.to_slug_param(params).should eq 'admin_pages'
120
142
  end
121
143
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = TheStringToSlug::VERSION
9
9
  spec.authors = ['Ilya N. Zykin']
10
10
  spec.email = ['zykin-ilya@ya.ru']
11
- spec.description = %q{ Convert text string to slug param }
12
- spec.summary = %q{ Translite, downcase, parameterize }
11
+ spec.description = %q{ Convert strings and symbols to slug param }
12
+ spec.summary = %q{ Transliteration + Parameterization for slugs building }
13
13
  spec.homepage = 'https://github.com/the-teacher/the_string_to_slug'
14
14
  spec.license = 'MIT'
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_string_to_slug
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
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: 2014-03-20 00:00:00.000000000 Z
11
+ date: 2014-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails-i18n
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: " Convert text string to slug param "
55
+ description: " Convert strings and symbols to slug param "
56
56
  email:
57
57
  - zykin-ilya@ya.ru
58
58
  executables: []
@@ -146,7 +146,7 @@ rubyforge_project:
146
146
  rubygems_version: 2.1.11
147
147
  signing_key:
148
148
  specification_version: 4
149
- summary: Translite, downcase, parameterize
149
+ summary: Transliteration + Parameterization for slugs building
150
150
  test_files:
151
151
  - spec/dummy_app/.gitignore
152
152
  - spec/dummy_app/.rspec