mongoid_permalink_extension 0.1.2 → 0.1.3

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: 871d9e6f3675450b0bea4e3f772d4ca1a37a7d3e
4
- data.tar.gz: cfe647f888ec7ee710a434a0ba057aa3a8da6e1e
3
+ metadata.gz: f268dde2d70066b5c5a5f073c697471f421ccc8f
4
+ data.tar.gz: fd67695b3b8dca96e2b3f7b4e4676d2d7f4523cf
5
5
  SHA512:
6
- metadata.gz: 32a6ff15eb4117584c9c98f323da1b8f3f5152ffe39889cd08856da9102bba9df0de551e645a734653da3478a98d61e54d7b34618ab41513d9ea9b1045f130ad
7
- data.tar.gz: 62526cba6d41c7e3619b01dd22e5dc24bff869a3bc5397889db892d6c4bd9e79669a854c145232cc71f8d408352ca979bbc2d0ba5b3668968aaa56c1091396b3
6
+ metadata.gz: eb0fb5d378c5a92be97ac8ea5176d9434da4c519af0f4e4ef733b0dc5a3db2b52c2f38ee746d53c5ba751c4fe8821c74a667fe17331047166be8fb7eab382997
7
+ data.tar.gz: 3a3e2df2f14e55efa77ad05f2d0d648c9b79e88f387ab6a3f6a7c8b415f5c9fc8381a5c9a388f9a8379c0164805a16e9f6c304819ad98c98f65eb4506404f588
@@ -4,28 +4,25 @@ require 'stringex'
4
4
 
5
5
  module MongoidPermalinkExtension
6
6
  class Permalink
7
-
8
7
  class << self
9
-
10
- def demongoize value
8
+ def demongoize(value)
11
9
  value
12
10
  end
13
11
 
14
- def mongoize value
12
+ def mongoize(value)
15
13
  return if value.nil? # FIXME: this way we can never set the value to nil
16
- value.to_s.
17
- gsub(/([^[:upper:]](?=[[:upper:]]))|([a-z](?=\d+))/, '\1\2-').
18
- gsub(/\//, '-').
19
- gsub(/[-–—]+/, '-').
20
- gsub(/[^\p{Alnum} -]/, '').
21
- gsub(/\s+/, '-').
22
- gsub(/[-]+/, '-').
23
- gsub(/\A\-/, '').
24
- gsub(/\b\w/){ $&.upcase }.
25
- to_ascii
14
+ value.to_s
15
+ .gsub(/\A\s+|\s+\z/, '')
16
+ .gsub(/([^[:upper:]](?=[[:upper:]]))|([a-z](?=\d+))/, '\1\2-')
17
+ .gsub(/\//, '-')
18
+ .gsub(/[-–—]+/, '-')
19
+ .gsub(/[^\p{Alnum} -]/, '')
20
+ .gsub(/\s+/, '-')
21
+ .gsub(/[-]+/, '-')
22
+ .gsub(/\A\-/, '')
23
+ .gsub(/\b\w/) { $&.upcase }
24
+ .to_ascii
26
25
  end
27
-
28
26
  end
29
-
30
27
  end
31
28
  end
@@ -1,3 +1,3 @@
1
1
  module MongoidPermalinkExtension
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
@@ -27,52 +27,69 @@ describe MongoidPermalinkExtension::Permalink do
27
27
  it 'converts anything to string' do
28
28
  MongoidPermalinkExtension::Permalink.mongoize(12).must_equal '12'
29
29
  end
30
+
30
31
  it 'stores transformed string' do
31
- MongoidPermalinkExtension::Permalink.mongoize("some some").must_be :present?
32
+ MongoidPermalinkExtension::Permalink.mongoize('some some').must_be :present?
32
33
  end
34
+
33
35
  it 'stores nil if nil passed' do
34
36
  MongoidPermalinkExtension::Permalink.mongoize(nil).must_be_nil
35
37
  end
38
+
36
39
  it 'converts spaces to hyphens' do
37
- MongoidPermalinkExtension::Permalink.mongoize("A B").must_equal 'A-B'
38
- MongoidPermalinkExtension::Permalink.mongoize("A B").must_equal 'A-B'
40
+ MongoidPermalinkExtension::Permalink.mongoize('A B').must_equal 'A-B'
41
+ MongoidPermalinkExtension::Permalink.mongoize('A B').must_equal 'A-B'
42
+ end
43
+
44
+ it 'strips spaces around the string' do
45
+ MongoidPermalinkExtension::Permalink.mongoize(' A B ').must_equal 'A-B'
39
46
  end
47
+
40
48
  it 'converts slashes to hyphens' do
41
- MongoidPermalinkExtension::Permalink.mongoize("A/B").must_equal 'A-B'
49
+ MongoidPermalinkExtension::Permalink.mongoize('A/B').must_equal 'A-B'
42
50
  end
51
+
43
52
  it 'converts to camel case' do
44
- MongoidPermalinkExtension::Permalink.mongoize("hello hello").wont_include 'h'
45
- MongoidPermalinkExtension::Permalink.mongoize("hello hello").must_equal 'Hello-Hello'
53
+ MongoidPermalinkExtension::Permalink.mongoize('hello hello').wont_include 'h'
54
+ MongoidPermalinkExtension::Permalink.mongoize('hello hello').must_equal 'Hello-Hello'
46
55
  end
56
+
47
57
  it 'adds spaces to camel case' do
48
- MongoidPermalinkExtension::Permalink.mongoize("CamelCase").must_equal 'Camel-Case'
58
+ MongoidPermalinkExtension::Permalink.mongoize('CamelCase').must_equal 'Camel-Case'
49
59
  end
60
+
50
61
  it 'preserves ABC' do
51
- MongoidPermalinkExtension::Permalink.mongoize("ABC Demo").must_equal 'ABC-Demo'
62
+ MongoidPermalinkExtension::Permalink.mongoize('ABC Demo').must_equal 'ABC-Demo'
52
63
  # MongoidPermalinkExtension::Permalink.mongoize("ABCDeMo").must_equal 'ABC-De-Mo'
53
64
  end
65
+
54
66
  it 'preserves dashes as separators' do
55
- MongoidPermalinkExtension::Permalink.mongoize("Camel-Case").must_equal 'Camel-Case'
56
- MongoidPermalinkExtension::Permalink.mongoize("Camel--Case").must_equal 'Camel-Case'
67
+ MongoidPermalinkExtension::Permalink.mongoize('Camel-Case').must_equal 'Camel-Case'
68
+ MongoidPermalinkExtension::Permalink.mongoize('Camel--Case').must_equal 'Camel-Case'
57
69
  end
70
+
58
71
  it 'converts all dashes to hyphens' do
59
- MongoidPermalinkExtension::Permalink.mongoize("A–Z").must_equal 'A-Z'
60
- MongoidPermalinkExtension::Permalink.mongoize("A----–Z").must_equal 'A-Z'
61
- MongoidPermalinkExtension::Permalink.mongoize("A—Z").must_equal 'A-Z'
62
- MongoidPermalinkExtension::Permalink.mongoize("A—––––––Z").must_equal 'A-Z'
72
+ MongoidPermalinkExtension::Permalink.mongoize('A–Z').must_equal 'A-Z'
73
+ MongoidPermalinkExtension::Permalink.mongoize('A----–Z').must_equal 'A-Z'
74
+ MongoidPermalinkExtension::Permalink.mongoize('A—Z').must_equal 'A-Z'
75
+ MongoidPermalinkExtension::Permalink.mongoize('A—––––––Z').must_equal 'A-Z'
63
76
  end
77
+
64
78
  it 'remove non-alphanumeric characters' do
65
79
  %w(?!@#$%^&*()+=.,;<>[]“”).shuffle.each do |i|
66
80
  MongoidPermalinkExtension::Permalink.mongoize(i).wont_include i
67
81
  end
68
82
  end
83
+
69
84
  it 'does not start with a hyphen' do
70
- MongoidPermalinkExtension::Permalink.mongoize("“Yes” to a Historic Moment").must_equal "Yes-To-A-Historic-Moment"
71
- MongoidPermalinkExtension::Permalink.mongoize("¿Yes?").must_equal "Yes"
85
+ MongoidPermalinkExtension::Permalink.mongoize('“Yes” to a Historic Moment').must_equal 'Yes-To-A-Historic-Moment'
86
+ MongoidPermalinkExtension::Permalink.mongoize('¿Yes?').must_equal 'Yes'
72
87
  end
88
+
73
89
  it 'preserves accented characters' do
74
90
  MongoidPermalinkExtension::Permalink.mongoize('Bienále Brno Česká republika').must_equal 'Bienale-Brno-Ceska-Republika'
75
91
  end
92
+
76
93
  it 'produces nice slugs' do
77
94
  MongoidPermalinkExtension::Permalink.mongoize('Future Vocabularies?').must_equal 'Future-Vocabularies'
78
95
  MongoidPermalinkExtension::Permalink.mongoize('2011 space odyssey').must_equal '2011-Space-Odyssey'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_permalink_extension
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-24 00:00:00.000000000 Z
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid