manual_slug 0.1.0
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +2 -0
- data/lib/manual_slug.rb +18 -0
- data/lib/manual_slug/active_record.rb +32 -0
- data/lib/manual_slug/mongoid.rb +42 -0
- data/lib/manual_slug/version.rb +3 -0
- data/manual_slug.gemspec +25 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4b99c2e9be9b809346facf138a466fc21aca8ad0afe78eb85185c9b14e1db94f
|
4
|
+
data.tar.gz: ce70515bae72f0968a3e59ecbc4d6524b1489f0949d252e2aecc049a6bfb0885
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d594c54b00b8b7d4d35203d48828a7afbfb9bae6be91414d2b0faf066f2f8e1125449baf3d787db0f85c76eb59acfac382c55ef7f90a8feb04f4aca241e7305
|
7
|
+
data.tar.gz: 86d621a6dfdae2f2bbc9583e5f227a83054a46b21ca3aeb6e0b4c41c5a733eb64a98734cc066bc9f4622094bdfc460622496cdc37aaa984ebc19d5715e10e49a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 glebtv
|
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,49 @@
|
|
1
|
+
[](http://badge.fury.io/rb/manual_slug)
|
2
|
+
|
3
|
+
# ManualSlug
|
4
|
+
|
5
|
+
Allows to set slug field for models manually
|
6
|
+
|
7
|
+
Supports [FriendlyID](https://github.com/norman/friendly_id) and [Mongoid Slug](https://github.com/mongoid/mongoid-slug)
|
8
|
+
|
9
|
+
This is an extraction from [RocketCMS](https://github.com/rs-pro/rocket_cms)
|
10
|
+
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'manual_slug'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install manual_slug
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# in your model, insted of regular slug code
|
32
|
+
include ManualSlug
|
33
|
+
manual_slug :report_slug
|
34
|
+
|
35
|
+
# or
|
36
|
+
manual_slug :report_slug, options_for_your_gem
|
37
|
+
```
|
38
|
+
|
39
|
+
Then use ```text_slug``` instead of ```slug``` when you need to provide your users the ability to edit slugs.
|
40
|
+
|
41
|
+
Also supports Rails Admin and ActiveAdmin.
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it ( https://github.com/rs-pro/manual_slug/fork )
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/manual_slug.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "manual_slug/version"
|
2
|
+
|
3
|
+
module ManualSlug
|
4
|
+
autoload :Mongoid, 'manual_slug/mongoid'
|
5
|
+
autoload :ActiveRecord, 'manual_slug/active_record'
|
6
|
+
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
if (defined?(RocketCMS) && RocketCMS.mongoid?)
|
9
|
+
include ManualSlug::Mongoid
|
10
|
+
elsif defined?(ActiveRecord)
|
11
|
+
include ManualSlug::ActiveRecord
|
12
|
+
elsif defined?(Mongoid)
|
13
|
+
include ManualSlug::Mongoid
|
14
|
+
else
|
15
|
+
puts "manual_slug was unable to find your ORM, please load after ORM"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ManualSlug::ActiveRecord
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
extend FriendlyId
|
6
|
+
end
|
7
|
+
|
8
|
+
def text_slug
|
9
|
+
slug
|
10
|
+
end
|
11
|
+
def text_slug=(s)
|
12
|
+
self.slug = s
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
def manual_slug(field, options = {}, callback = true)
|
17
|
+
friendly_id field, use: [:slugged, :finders]
|
18
|
+
define_method(:should_generate_new_friendly_id?) do
|
19
|
+
slug.blank?
|
20
|
+
end
|
21
|
+
|
22
|
+
skip_callback :validation, :before, :set_slug
|
23
|
+
before_validation do
|
24
|
+
if self.slug.blank?
|
25
|
+
self.send(:set_slug)
|
26
|
+
end
|
27
|
+
true
|
28
|
+
end if callback
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ManualSlug::Mongoid
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
include ::Mongoid::Slug
|
4
|
+
|
5
|
+
def text_slug
|
6
|
+
self._slugs.blank? ? '' : self._slugs.last
|
7
|
+
end
|
8
|
+
def text_slug=(slug)
|
9
|
+
if slug.blank?
|
10
|
+
self._slugs = []
|
11
|
+
else
|
12
|
+
if self._slugs.blank?
|
13
|
+
self._slugs = [slug]
|
14
|
+
else
|
15
|
+
self._slugs.delete(slug)
|
16
|
+
self._slugs << slug
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
def manual_slug(field, options = {}, callback = true)
|
23
|
+
options.merge!(permanent: true, history: true)
|
24
|
+
slug field, options
|
25
|
+
|
26
|
+
# we will create slugs manually when needed
|
27
|
+
skip_callback :create, :before, :build_slug
|
28
|
+
|
29
|
+
before_validation do
|
30
|
+
if self._slugs.blank?
|
31
|
+
self.build_slug
|
32
|
+
else
|
33
|
+
self._slugs = self._slugs.map{ |s| s.strip }.select {|s| !s.blank? }
|
34
|
+
end
|
35
|
+
true
|
36
|
+
end if callback
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
data/manual_slug.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'manual_slug/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "manual_slug"
|
8
|
+
spec.version = ManualSlug::VERSION
|
9
|
+
spec.authors = ["glebtv"]
|
10
|
+
spec.email = ["glebtv@gmail.com"]
|
11
|
+
spec.summary = %q{Allows to set slug manually for friendly_id and mongoid-slug}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "https://github.com/rs-pro/manual_slug"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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 'activesupport'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: manual_slug
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- glebtv
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: ''
|
56
|
+
email:
|
57
|
+
- glebtv@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/manual_slug.rb
|
68
|
+
- lib/manual_slug/active_record.rb
|
69
|
+
- lib/manual_slug/mongoid.rb
|
70
|
+
- lib/manual_slug/version.rb
|
71
|
+
- manual_slug.gemspec
|
72
|
+
homepage: https://github.com/rs-pro/manual_slug
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.7.3
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Allows to set slug manually for friendly_id and mongoid-slug
|
96
|
+
test_files: []
|