mongoid_permalink_extension 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +17 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +9 -0
- data/lib/mongoid_permalink_extension.rb +3 -0
- data/lib/mongoid_permalink_extension/permalink.rb +27 -0
- data/lib/mongoid_permalink_extension/version.rb +3 -0
- data/mongoid_permalink_extension.gemspec +28 -0
- data/test/mongoid_permalink_extension/permalink_test.rb +62 -0
- data/test/test_helper.rb +9 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 98afc802b3412519f89bbbbd3c1f0ea16fcb470f
|
4
|
+
data.tar.gz: c26b501ab8d2fcf8fb9fbae808f5fda225f0df85
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 058569701ff2b746af74119d686a188b4373d2955a0dfc4acb85fb4b387b561c432d6ef50f650003e8a736541bd59c5e248ab59365cedfd753e3339ef9c766a1
|
7
|
+
data.tar.gz: 140277531935221ef8dbc2b4650626d4026bf4bfaa5b22131ce78662153e915f9242991b6db44b146324ebe05b34f5202abe58a710653da25e5893c0af65d209
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Tomas Celizna
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tomas Celizna
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Mongoid Permalink Extension
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/tomasc/mongoid_permalink_extension.svg)](https://travis-ci.org/tomasc/mongoid_permalink_extension) [![Coverage Status](https://img.shields.io/coveralls/tomasc/mongoid_permalink_extension.svg)](https://coveralls.io/r/tomasc/mongoid_permalink_extension)
|
4
|
+
|
5
|
+
A [Mongoid](https://github.com/mongoid/mongoid) field extension that stores any String as a permalink slug.
|
6
|
+
|
7
|
+
* converts spaces to hyphens
|
8
|
+
* converts to camel case
|
9
|
+
* converts all dashes to hyphens
|
10
|
+
* remove non-alphanumeric characters
|
11
|
+
* removes accents
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'mongoid_permalink_extension'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install mongoid_permalink_extension
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Add to Mongoid models as:
|
30
|
+
|
31
|
+
field :permalink, type: MongoidPermalinkExtension::Permalink
|
32
|
+
|
33
|
+
Produces slugs in the form of:
|
34
|
+
|
35
|
+
A-Hard-Days-Night
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'stringex'
|
4
|
+
|
5
|
+
module MongoidPermalinkExtension
|
6
|
+
class Permalink
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def demongoize value
|
11
|
+
value
|
12
|
+
end
|
13
|
+
|
14
|
+
def mongoize value
|
15
|
+
return if value.nil?
|
16
|
+
value.to_s.
|
17
|
+
gsub(/[–—]/, '-').
|
18
|
+
gsub(/\s+/, '-').
|
19
|
+
gsub(/[^\p{Alnum} -]/, '').
|
20
|
+
gsub(/\b\w/){ $&.upcase }.
|
21
|
+
to_ascii
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mongoid_permalink_extension/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mongoid_permalink_extension"
|
8
|
+
spec.version = MongoidPermalinkExtension::VERSION
|
9
|
+
spec.authors = ["Tomas Celizna"]
|
10
|
+
spec.email = ["tomas.celizna@gmail.com"]
|
11
|
+
spec.description = %q{Custom field type for Mongoid that automatically converts strings to URL slugs.}
|
12
|
+
spec.summary = %q{Custom field type for Mongoid that automatically converts strings to URL slugs.}
|
13
|
+
spec.homepage = "https://github.com/tomasc/mongoid_permalink_extension"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "mongoid", ">= 4.0"
|
22
|
+
spec.add_dependency "stringex"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "coveralls"
|
26
|
+
spec.add_development_dependency "minitest"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
# ---------------------------------------------------------------------
|
6
|
+
|
7
|
+
class MongoidPermalinkExtensionTest
|
8
|
+
include Mongoid::Document
|
9
|
+
field :permalink, type: MongoidPermalinkExtension::Permalink
|
10
|
+
end
|
11
|
+
|
12
|
+
# ---------------------------------------------------------------------
|
13
|
+
|
14
|
+
module MongoidPermalinkExtension
|
15
|
+
describe Permalink do
|
16
|
+
|
17
|
+
subject { MongoidPermalinkExtensionTest.new }
|
18
|
+
|
19
|
+
describe '.demongoize' do
|
20
|
+
let(:permalink_value) { 'something stored in the database' }
|
21
|
+
it 'does not change the value' do
|
22
|
+
MongoidPermalinkExtension::Permalink.demongoize(permalink_value).must_equal permalink_value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.mongoize' do
|
27
|
+
it 'converts anything to string' do
|
28
|
+
MongoidPermalinkExtension::Permalink.mongoize(12).must_equal '12'
|
29
|
+
end
|
30
|
+
it 'stores transformed string' do
|
31
|
+
MongoidPermalinkExtension::Permalink.mongoize("some some").must_be :present?
|
32
|
+
end
|
33
|
+
it 'stores nil if nil passed' do
|
34
|
+
MongoidPermalinkExtension::Permalink.mongoize(nil).must_be_nil
|
35
|
+
end
|
36
|
+
it 'converts spaces to hyphens' do
|
37
|
+
MongoidPermalinkExtension::Permalink.mongoize(" ").must_equal '-'
|
38
|
+
MongoidPermalinkExtension::Permalink.mongoize(" ").must_equal '-'
|
39
|
+
end
|
40
|
+
it 'converts to camel case' do
|
41
|
+
MongoidPermalinkExtension::Permalink.mongoize("hello hello").wont_include 'h'
|
42
|
+
end
|
43
|
+
it 'converts all dashes to hyphens' do
|
44
|
+
MongoidPermalinkExtension::Permalink.mongoize("–").must_equal '-'
|
45
|
+
MongoidPermalinkExtension::Permalink.mongoize("—").must_equal '-'
|
46
|
+
end
|
47
|
+
it 'remove non-alphanumeric characters' do
|
48
|
+
%w(?!@#$%^&*()+=/.,;<>[]).shuffle.each do |i|
|
49
|
+
MongoidPermalinkExtension::Permalink.mongoize(i).wont_include i
|
50
|
+
end
|
51
|
+
end
|
52
|
+
it 'preserves accented characters' do
|
53
|
+
MongoidPermalinkExtension::Permalink.mongoize('Bienále Brno Česká republika').must_equal 'Bienale-Brno-Ceska-Republika'
|
54
|
+
end
|
55
|
+
it 'produces nice slugs' do
|
56
|
+
MongoidPermalinkExtension::Permalink.mongoize('Future Vocabularies?').must_equal 'Future-Vocabularies'
|
57
|
+
MongoidPermalinkExtension::Permalink.mongoize('2011 space odyssey').must_equal '2011-Space-Odyssey'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid_permalink_extension
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomas Celizna
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mongoid
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: stringex
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Custom field type for Mongoid that automatically converts strings to
|
98
|
+
URL slugs.
|
99
|
+
email:
|
100
|
+
- tomas.celizna@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .coveralls.yml
|
106
|
+
- .gitignore
|
107
|
+
- .travis.yml
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- lib/mongoid_permalink_extension.rb
|
114
|
+
- lib/mongoid_permalink_extension/permalink.rb
|
115
|
+
- lib/mongoid_permalink_extension/version.rb
|
116
|
+
- mongoid_permalink_extension.gemspec
|
117
|
+
- test/mongoid_permalink_extension/permalink_test.rb
|
118
|
+
- test/test_helper.rb
|
119
|
+
homepage: https://github.com/tomasc/mongoid_permalink_extension
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.1.10
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Custom field type for Mongoid that automatically converts strings to URL
|
143
|
+
slugs.
|
144
|
+
test_files:
|
145
|
+
- test/mongoid_permalink_extension/permalink_test.rb
|
146
|
+
- test/test_helper.rb
|
147
|
+
has_rdoc:
|