scaffold_plus 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/generators/scaffold_plus/ancestry/ancestry_generator.rb +5 -13
- data/lib/generators/scaffold_plus/ancestry/templates/ancestry_migration.rb +2 -2
- data/lib/generators/scaffold_plus/friendly_id/friendly_id_generator.rb +46 -0
- data/lib/generators/scaffold_plus/friendly_id/templates/friendly_id_migration.rb +6 -0
- data/lib/scaffold_plus/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8611eb567ad99bbb859e145a779ce56fa28e17d4
|
4
|
+
data.tar.gz: ea3c09627c8a3343739170d9d2106eeb5dd57506
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71c6ea4131e975934d3f24530ce6033ab5b3ef99fa0893017cbe1a392581903067858a6193d32d2d5ba9e0389958195e604885555d84c658c8f61ea3291df800
|
7
|
+
data.tar.gz: 6412c9b5cdf06fae2ff3fddabc9d1d2e9b6200876e200d8f8b886fcc0cab8acfc4d5ec78400a501333549c74cb44f41dc113c70eed55eae0f92737e7c5b57ca3
|
data/README.md
CHANGED
@@ -55,6 +55,14 @@ and updates to the models.
|
|
55
55
|
|
56
56
|
This helper adds "autofocus: true" to an input field in the form view.
|
57
57
|
|
58
|
+
### Add friendly_id to resource
|
59
|
+
rails generate friendly_id
|
60
|
+
rails generate scaffold_plus:friendly_id [attribute]
|
61
|
+
|
62
|
+
This helper depends on the [friendly_id](https://github.com/norman/friendly_id/)
|
63
|
+
gem. It adds "extend FriendlyId" to the model and marks the attribute which is to
|
64
|
+
be slugged (default: 'name'). Currently it is hardcoded to add a 'slug' attribute.
|
65
|
+
|
58
66
|
### Add geo location to resource
|
59
67
|
rails generate scaffold_plus:geocoder_init
|
60
68
|
rails generate scaffold_plus:geocoder
|
@@ -19,12 +19,12 @@ module ScaffoldPlus
|
|
19
19
|
class_option :after, type: :boolean, default: false,
|
20
20
|
desc: 'Add a line after generated text in model'
|
21
21
|
source_root File.expand_path('../templates', __FILE__)
|
22
|
-
|
22
|
+
|
23
23
|
def add_migration
|
24
24
|
return unless options.migration?
|
25
25
|
migration_template "ancestry_migration.rb", "db/migrate/#{migration_name}.rb"
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def update_model
|
29
29
|
inject_into_class "app/models/#{name}.rb", class_name do
|
30
30
|
text = options.before? ? "\n" : ""
|
@@ -35,7 +35,7 @@ module ScaffoldPlus
|
|
35
35
|
text
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def update_controller
|
40
40
|
return unless options.permit?
|
41
41
|
text = ":ancestry"
|
@@ -44,20 +44,12 @@ module ScaffoldPlus
|
|
44
44
|
# Special case: no previous permit
|
45
45
|
gsub_file file, /^(\s*params)\[:#{name}\]$/, "\\1.require(:#{name}).permit(#{text})"
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
protected
|
49
|
-
|
49
|
+
|
50
50
|
def migration_name
|
51
51
|
"add_ancestry_to_#{table_name}"
|
52
52
|
end
|
53
|
-
|
54
|
-
def create_index?
|
55
|
-
options.index?
|
56
|
-
end
|
57
|
-
|
58
|
-
def create_depth?
|
59
|
-
options.depth?
|
60
|
-
end
|
61
53
|
end
|
62
54
|
end
|
63
55
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
class <%= migration_name.camelize %> < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
add_column :<%= table_name %>, :ancestry, :string
|
4
|
-
<%- if
|
4
|
+
<%- if options.depth? -%>
|
5
5
|
add_column :<%= table_name %>, :ancestry_depth, :integer, default: 0
|
6
6
|
<%- end -%>
|
7
|
-
<%- if
|
7
|
+
<%- if options.index? -%>
|
8
8
|
add_index :<%= table_name %>, :ancestry
|
9
9
|
<%- end -%>
|
10
10
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module ScaffoldPlus
|
4
|
+
module Generators
|
5
|
+
class FriendlyIdGenerator < ActiveRecord::Generators::Base
|
6
|
+
desc "Add friendly_id to resource"
|
7
|
+
argument :name, type: :string,
|
8
|
+
desc: 'The object that uses friendly_id'
|
9
|
+
argument :attribute, type: :string, default: 'name',
|
10
|
+
desc: 'The model attribute to be slugged'
|
11
|
+
class_option :migration, type: :boolean, default: true,
|
12
|
+
desc: 'Create migration for the slug attribute'
|
13
|
+
class_option :before, type: :boolean, default: false,
|
14
|
+
desc: 'Add a line before generated text in model'
|
15
|
+
class_option :after, type: :boolean, default: false,
|
16
|
+
desc: 'Add a line after generated text in model'
|
17
|
+
source_root File.expand_path('../templates', __FILE__)
|
18
|
+
|
19
|
+
def add_migration
|
20
|
+
return unless options.migration?
|
21
|
+
migration_template "friendly_id_migration.rb", "db/migrate/#{migration_name}.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_model
|
25
|
+
inject_into_class "app/models/#{name}.rb", class_name do
|
26
|
+
text = options.before? ? "\n" : ""
|
27
|
+
text << " extend FriendlyId\n"
|
28
|
+
text << " friendly_id :#{attribute}, use: :slugged\n"
|
29
|
+
text << "\n" if options.after?
|
30
|
+
text
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_controller
|
35
|
+
file = "app/controllers/#{table_name}_controller.rb"
|
36
|
+
gsub_file file, /(#{class_name})\.find/, "\\1.friendly.find"
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def migration_name
|
42
|
+
"add_friendly_id_to_#{table_name}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scaffold_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volker Wiegand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -85,6 +85,8 @@ files:
|
|
85
85
|
- lib/generators/scaffold_plus/collection/collection_generator.rb
|
86
86
|
- lib/generators/scaffold_plus/collection/templates/view.html.erb
|
87
87
|
- lib/generators/scaffold_plus/force_ssl/force_ssl_generator.rb
|
88
|
+
- lib/generators/scaffold_plus/friendly_id/friendly_id_generator.rb
|
89
|
+
- lib/generators/scaffold_plus/friendly_id/templates/friendly_id_migration.rb
|
88
90
|
- lib/generators/scaffold_plus/geocoder/geocoder_generator.rb
|
89
91
|
- lib/generators/scaffold_plus/geocoder_init/geocoder_init_generator.rb
|
90
92
|
- lib/generators/scaffold_plus/geocoder_init/templates/geocoder.rb
|