rails_admin_slug 0.1.0 → 0.1.1
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.
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/README.md +52 -0
- data/lib/rails_admin_slug.rb +2 -2
- data/lib/rails_admin_slug/engine.rb +6 -0
- data/lib/rails_admin_slug/slug.rb +28 -0
- data/rails_admin_slug.gemspec +12 -0
- metadata +8 -2
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# RailsAdminSlug
|
2
|
+
|
3
|
+
A RailsAdmin field type to create a URL slug as you type a page title
|
4
|
+
|
5
|
+
## What is it
|
6
|
+
|
7
|
+
Normally when using a gem like FriendlyId, the slug is created server side where the end user has no way of editing what the slug may be. Sure you can have a form field where they can fill in the slug if they so desire, or edit the slug after the model is created. This can lead to confusion and disuse with less technical users.
|
8
|
+
|
9
|
+
This gem brings the slug creation to the client side in RailsAdmin. The slug is automatically created when a user types the model title. From there the slug can be reviewed and edited before initial model creation.
|
10
|
+
|
11
|
+
## Installing
|
12
|
+
|
13
|
+
Simply add the gem to your projects Gemfile after the rails_admin line.
|
14
|
+
|
15
|
+
gem "rails_admin_slug"
|
16
|
+
|
17
|
+
Create a rails_admin/custom/ui.js file and add the following line to the top (or just add if the file already exists):
|
18
|
+
|
19
|
+
//=require 'ra.slug'
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In your RailsAdmin configuration file (usually config/initializers/rails_admin.rb) override the field type for the slug field.
|
24
|
+
The "source" configuration option defines which field the slug will be tied to and is required to be set.
|
25
|
+
|
26
|
+
RailsAdmin.config do |config|
|
27
|
+
config.model 'Page' do
|
28
|
+
edit do
|
29
|
+
field :slug, :slug do
|
30
|
+
source 'title'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
The slug field type extends the string field type. This means it is still possible to set other configuration items.
|
37
|
+
|
38
|
+
RailsAdmin.config do |config|
|
39
|
+
config.model 'Page' do
|
40
|
+
edit do
|
41
|
+
field :slug, :slug do
|
42
|
+
source 'title'
|
43
|
+
help 'You may edit the slug if you wish'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
## Credits
|
50
|
+
|
51
|
+
The jquery plugin that creates and edit the client side slug is from Patrick McElhaney and can be found at: https://github.com/pmcelhaney/jQuery-Slugify-Plugin/blob/master/readme.md
|
52
|
+
|
data/lib/rails_admin_slug.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require 'rails_admin_slug/engine
|
2
|
-
require 'rails_admin_slug/slug
|
1
|
+
require 'rails_admin_slug/engine'
|
2
|
+
require 'rails_admin_slug/slug'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails_admin/config/fields/base'
|
2
|
+
require 'rails_admin/config/fields/types/string'
|
3
|
+
|
4
|
+
|
5
|
+
module RailsAdmin
|
6
|
+
module Config
|
7
|
+
module Fields
|
8
|
+
module Types
|
9
|
+
class Slug < RailsAdmin::Config::Fields::Types::String
|
10
|
+
|
11
|
+
RailsAdmin::Config::Fields::Types::register(self)
|
12
|
+
|
13
|
+
register_instance_option :source do
|
14
|
+
@source ||= properties && properties[:source]
|
15
|
+
end
|
16
|
+
|
17
|
+
register_instance_option :html_attributes do
|
18
|
+
{
|
19
|
+
:maxlength => length,
|
20
|
+
:size => [50, length.to_i].min,
|
21
|
+
:'data-slug' => "#{self.abstract_model.model.name.underscore}_#{source}"
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'rails_admin_slug'
|
3
|
+
s.version = '0.1.1'
|
4
|
+
s.date = '2013-04-23'
|
5
|
+
s.summary = "RailsAdmin Slug"
|
6
|
+
s.description = "A RailsAdmin field type to create a URL slug as you type a page title "
|
7
|
+
s.authors = ["Tim Watson"]
|
8
|
+
s.email = ['tiwatson@gmail.com']
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
s.homepage = 'http://tiwatson.com'
|
11
|
+
s.require_path = 'lib'
|
12
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_admin_slug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,8 +18,14 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
-
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- README.md
|
22
24
|
- app/assets/javascripts/ra.slug.js
|
25
|
+
- lib/rails_admin_slug.rb
|
26
|
+
- lib/rails_admin_slug/engine.rb
|
27
|
+
- lib/rails_admin_slug/slug.rb
|
28
|
+
- rails_admin_slug.gemspec
|
23
29
|
- vendor/assets/javascripts/jquery.slugify.js
|
24
30
|
homepage: http://tiwatson.com
|
25
31
|
licenses: []
|