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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68734750146a32a30b34dd4ac662f7e4f8338087
4
- data.tar.gz: c0b6a9ec6c80f13618837257cd0b36b6ce88c8f1
3
+ metadata.gz: 8611eb567ad99bbb859e145a779ce56fa28e17d4
4
+ data.tar.gz: ea3c09627c8a3343739170d9d2106eeb5dd57506
5
5
  SHA512:
6
- metadata.gz: 284a0a8fabf17966663bc38281fedd8f04d6bcd8828eb47303db1b128c22ef6a8f62de0d10a1bf6a50cb2ecc878859d62800d860636ae36b3161018093cc668c
7
- data.tar.gz: fbb087f7decee500fa94b2c25012921424cf168eae4a3216c63b01e2c26679884c297b5578760344c15277dcd329dea055a143b8b15f8172ed7e350a2a61bcb9
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 create_depth? -%>
4
+ <%- if options.depth? -%>
5
5
  add_column :<%= table_name %>, :ancestry_depth, :integer, default: 0
6
6
  <%- end -%>
7
- <%- if create_index? -%>
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
@@ -0,0 +1,6 @@
1
+ class <%= migration_name.camelize %> < ActiveRecord::Migration
2
+ def change
3
+ add_column :<%= table_name %>, :slug, :string
4
+ add_index :<%= table_name %>, :slug, unique: true
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module ScaffoldPlus
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.0"
3
3
  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.5.0
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-18 00:00:00.000000000 Z
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