padrino-admin 0.16.0.pre3 → 0.16.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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +5 -5
  3. data/lib/padrino-admin/access_control.rb +10 -9
  4. data/lib/padrino-admin/generators/actions.rb +8 -8
  5. data/lib/padrino-admin/generators/admin_app.rb +62 -62
  6. data/lib/padrino-admin/generators/admin_page.rb +16 -17
  7. data/lib/padrino-admin/generators/orm.rb +56 -65
  8. data/lib/padrino-admin/generators/templates/account/activerecord.rb.tt +11 -11
  9. data/lib/padrino-admin/generators/templates/account/couchrest.rb.tt +10 -10
  10. data/lib/padrino-admin/generators/templates/account/datamapper.rb.tt +11 -11
  11. data/lib/padrino-admin/generators/templates/account/dynamoid.rb.tt +9 -9
  12. data/lib/padrino-admin/generators/templates/account/minirecord.rb.tt +11 -11
  13. data/lib/padrino-admin/generators/templates/account/mongoid.rb.tt +16 -16
  14. data/lib/padrino-admin/generators/templates/account/mongomapper.rb.tt +11 -11
  15. data/lib/padrino-admin/generators/templates/account/ohm.rb.tt +2 -2
  16. data/lib/padrino-admin/generators/templates/account/seeds.rb.tt +2 -2
  17. data/lib/padrino-admin/generators/templates/app/controllers/base.rb.tt +2 -2
  18. data/lib/padrino-admin/generators/templates/app/controllers/sessions.rb.tt +2 -2
  19. data/lib/padrino-admin/generators/templates/app.rb.tt +7 -7
  20. data/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt +10 -9
  21. data/lib/padrino-admin/generators/templates/erb/app/layouts/error.erb.tt +3 -2
  22. data/lib/padrino-admin/generators/templates/erb/app/sessions/new.erb.tt +8 -7
  23. data/lib/padrino-admin/generators/templates/erb/page/_form.erb.tt +7 -7
  24. data/lib/padrino-admin/generators/templates/erb/page/edit.erb.tt +3 -3
  25. data/lib/padrino-admin/generators/templates/erb/page/index.erb.tt +12 -12
  26. data/lib/padrino-admin/generators/templates/erb/page/new.erb.tt +2 -2
  27. data/lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt +10 -5
  28. data/lib/padrino-admin/generators/templates/haml/app/layouts/application.haml.tt +14 -14
  29. data/lib/padrino-admin/generators/templates/haml/app/layouts/error.haml.tt +6 -5
  30. data/lib/padrino-admin/generators/templates/haml/app/sessions/new.haml.tt +12 -11
  31. data/lib/padrino-admin/generators/templates/haml/page/_form.haml.tt +7 -7
  32. data/lib/padrino-admin/generators/templates/haml/page/edit.haml.tt +3 -3
  33. data/lib/padrino-admin/generators/templates/haml/page/index.haml.tt +14 -14
  34. data/lib/padrino-admin/generators/templates/haml/page/new.haml.tt +2 -2
  35. data/lib/padrino-admin/generators/templates/page/controller.rb.tt +25 -25
  36. data/lib/padrino-admin/generators/templates/slim/app/layouts/application.slim.tt +9 -9
  37. data/lib/padrino-admin/generators/templates/slim/app/layouts/error.slim.tt +1 -1
  38. data/lib/padrino-admin/generators/templates/slim/app/sessions/new.slim.tt +6 -6
  39. data/lib/padrino-admin/generators/templates/slim/page/_form.slim.tt +6 -6
  40. data/lib/padrino-admin/generators/templates/slim/page/edit.slim.tt +3 -3
  41. data/lib/padrino-admin/generators/templates/slim/page/index.slim.tt +12 -12
  42. data/lib/padrino-admin/generators/templates/slim/page/new.slim.tt +2 -2
  43. data/lib/padrino-admin/helpers/authentication_helpers.rb +7 -7
  44. data/lib/padrino-admin/helpers/view_helpers.rb +11 -11
  45. data/lib/padrino-admin.rb +4 -3
  46. data/padrino-admin.gemspec +18 -18
  47. data/test/fixtures/sequel.rb +14 -14
  48. data/test/generators/test_account_model_generator.rb +4 -4
  49. data/test/generators/test_admin_app_generator.rb +22 -22
  50. data/test/generators/test_admin_page_generator.rb +30 -30
  51. data/test/helper.rb +6 -6
  52. data/test/test_admin_application.rb +114 -116
  53. data/test/test_locale.rb +3 -3
  54. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ccba55822f2c76f099bbe1274dc226e42d32ebbb8a0ddb222e7c2d5027d2903
4
- data.tar.gz: 402dbb7f20c9aba74388fa055c0ee53ba1967f48e467671deb2e703698ccef85
3
+ metadata.gz: 5488a7db533da911edc1e5a6d9a93ada47389ae6cce07d91b0f40443700a81b1
4
+ data.tar.gz: a3d6dd922905dc573665ac9f505d12af787af4682dfe884bde3572d37a079d79
5
5
  SHA512:
6
- metadata.gz: 73334fd600b3b7cb7ec8795d835c244c268b58d13c2c3975f62e2ea8857e18bfccd9692344bfb537c6a28e546d68735e9f88d41ed91a75949fc565ded13c8aa4
7
- data.tar.gz: ccb0e3bc7d680e1dae904679bd532d78a93dd4aea17148cf2b41061fdf05a76631cff64d0dca177935c98d1104f4967b5a6b69d17af743aa77fa87967ef7c887
6
+ metadata.gz: bff20f86a10e7e5ecd9d4024655e06f552a54ba1532d6e58aaa67f917f25a708480fdce21edbe0aa2cd915bea9d0238b5be4e492bb1609ac06e04a0beed1c185
7
+ data.tar.gz: 94bc71711fd785063a27f065e0d51a58515442a19e6d8387e8da7a3c41957dec7f02a408c2cb75f4f5a6fb221a7b9167e84309c7b128180a94ba0a822700c549
data/Rakefile CHANGED
@@ -1,17 +1,17 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
1
+ require_relative '../gem_rake_helper'
2
2
 
3
3
  namespace :bootstrap do
4
4
  desc 'Compile bootstrap assets'
5
5
  task :compile do
6
- puts "Implement"
6
+ puts 'Implement'
7
7
  end
8
8
 
9
9
  desc 'Compile css'
10
10
  task :css do
11
11
  require 'less'
12
- src = File.join(File.dirname(__FILE__), 'lib', 'padrino-admin', 'bootstrap-less', 'padrino-admin.less')
13
- out = File.join(File.dirname(__FILE__), 'lib', 'padrino-admin', 'generators', 'templates', 'assets', 'stylesheets', 'bootstrap.css')
14
- css = Less::Parser.new(:paths => [File.dirname(src)]).parse(File.read(src)).to_css(:compress => true)
12
+ src = File.join(__dir__, 'lib', 'padrino-admin', 'bootstrap-less', 'padrino-admin.less')
13
+ out = File.join(__dir__, 'lib', 'padrino-admin', 'generators', 'templates', 'assets', 'stylesheets', 'bootstrap.css')
14
+ css = Less::Parser.new(paths: [File.dirname(src)]).parse(File.read(src)).to_css(compress: true)
15
15
  File.open(out, 'w') { |file| file.write css }
16
16
  puts "Generated #{out}"
17
17
  end
@@ -2,6 +2,7 @@ module Padrino
2
2
  module Admin
3
3
  class AccessControlError < StandardError
4
4
  end
5
+
5
6
  ##
6
7
  # This module enables access control functionality within a Padrino application.
7
8
  #
@@ -28,7 +29,7 @@ module Padrino
28
29
 
29
30
  app.send(:access_control=, Padrino::Admin::AccessControl::Base.new)
30
31
  end
31
- alias :included :registered
32
+ alias included registered
32
33
  end
33
34
 
34
35
  ##
@@ -43,7 +44,7 @@ module Padrino
43
44
  # We map project modules for a given role or roles.
44
45
  #
45
46
  def roles_for(*roles, &block)
46
- raise Padrino::Admin::AccessControlError, "Role #{role} must be present and must be a symbol!" if roles.any? { |r| !r.kind_of?(Symbol) } || roles.empty?
47
+ raise Padrino::Admin::AccessControlError, "Role #{role} must be present and must be a symbol!" if roles.any? { |r| !r.is_a?(Symbol) } || roles.empty?
47
48
  raise Padrino::Admin::AccessControlError, "You can't merge :any with other roles" if roles.size > 1 && roles.any? { |r| r == :any }
48
49
 
49
50
  @roles += roles
@@ -99,10 +100,10 @@ module Padrino
99
100
  # # NOTE The un-mounted path is used ('/accounts' instead of '/admin/accounts')
100
101
  # - if access_control.allowed?(current_account, '/accounts')
101
102
  # # Admins see the "Profile" link, but Workers do not
102
- # = link_to 'Profile', url(:accounts, :edit, :id => current_account.id)
103
+ # = link_to 'Profile', url(:accounts, :edit, id: current_account.id)
103
104
  #
104
- def allowed?(account=nil, path=nil)
105
- path = "/" if path.nil? || path.empty?
105
+ def allowed?(account = nil, path = nil)
106
+ path = '/' if path.nil? || path.empty?
106
107
  role = account.role.to_sym rescue nil
107
108
  authorizations = @authorizations.find_all { |auth| auth.roles.include?(:any) }
108
109
  allowed_paths = authorizations.map(&:allowed).flatten.uniq
@@ -154,7 +155,7 @@ module Padrino
154
155
  ##
155
156
  # Create a project module.
156
157
  #
157
- def project_module(name, path, options={})
158
+ def project_module(name, path, options = {})
158
159
  allow(path)
159
160
  @project_modules << ProjectModule.new(name, path, options)
160
161
  end
@@ -166,7 +167,7 @@ module Padrino
166
167
  class ProjectModule
167
168
  attr_reader :name, :options
168
169
 
169
- def initialize(name, path, options={})
170
+ def initialize(name, path, options = {})
170
171
  @name, @path, @options = name, path, options
171
172
  end
172
173
 
@@ -174,7 +175,7 @@ module Padrino
174
175
  # Returns the name of the project module humanize them for you.
175
176
  #
176
177
  def human_name
177
- @name.to_s.humanize
178
+ @name.to_s.humanize
178
179
  end
179
180
 
180
181
  ##
@@ -186,7 +187,7 @@ module Padrino
186
187
  # # => /admin/accounts
187
188
  # project_module.path("/admin")
188
189
  #
189
- def path(prefix=nil)
190
+ def path(prefix = nil)
190
191
  path = prefix ? File.join(prefix, @path) : @path
191
192
  path = File.join(ENV['RACK_BASE_URI'].to_s, path) if ENV['RACK_BASE_URI']
192
193
  path
@@ -14,7 +14,7 @@ module Padrino
14
14
  def orm
15
15
  fetch_component_choice(:orm).to_sym rescue :activerecord
16
16
  end
17
- alias :adapter :orm
17
+ alias adapter orm
18
18
 
19
19
  ##
20
20
  # Tell us which rendering engine you are using.
@@ -27,14 +27,14 @@ module Padrino
27
27
  # Tell us for now which orm we support
28
28
  #
29
29
  def supported_orm
30
- [:minirecord, :datamapper, :activerecord, :mongomapper, :mongoid, :couchrest, :sequel, :ohm, :dynamoid]
30
+ %i[minirecord datamapper activerecord mongomapper mongoid couchrest sequel ohm dynamoid]
31
31
  end
32
32
 
33
33
  ##
34
34
  # Tell us for now which rendering engine we support.
35
35
  #
36
36
  def supported_ext
37
- [:haml, :slim, :erb]
37
+ %i[haml slim erb]
38
38
  end
39
39
 
40
40
  ##
@@ -42,17 +42,17 @@ module Padrino
42
42
  #
43
43
  def add_project_module(controller)
44
44
  permission = " role.project_module :#{controller}, '/#{controller}'\n"
45
- inject_into_file destination_root(@admin_path+'/app.rb'), permission, :after => "access_control.roles_for :admin do |role|\n"
45
+ inject_into_file destination_root("#{@admin_path}/app.rb"), permission, after: "access_control.roles_for :admin do |role|\n"
46
46
  end
47
47
 
48
48
  ##
49
49
  # Remove from access_control permissions.
50
50
  #
51
51
  def remove_project_module(controller)
52
- path = destination_root(@admin_path+'/app.rb')
53
- say_status :replace, @admin_path+'/app.rb', :red
52
+ path = destination_root("#{@admin_path}/app.rb")
53
+ say_status :replace, "#{@admin_path}/app.rb", :red
54
54
  content = File.binread(path)
55
- content.gsub!(/^\s+role\.project_module :#{controller}, '\/#{controller}'\n/, '')
55
+ content.gsub!(%r{^\s+role\.project_module :#{controller}, '/#{controller}'\n}, '')
56
56
  File.open(path, 'wb') { |f| f.write content }
57
57
  end
58
58
 
@@ -68,7 +68,7 @@ module Padrino
68
68
  # fetch_app_name('subapp')
69
69
  #
70
70
  # @api public
71
- def fetch_app_name(app='app')
71
+ def fetch_app_name(app = 'app')
72
72
  app_path = destination_root(app, 'app.rb')
73
73
  @app_name ||= File.read(app_path).scan(/module\s(.*?)\n/).flatten[0]
74
74
  end
@@ -1,18 +1,16 @@
1
- # -*- coding: utf-8 -*-
2
1
  module Padrino
3
2
  module Generators
4
3
  ##
5
4
  # Defines the generator for creating a new admin app.
6
5
  #
7
6
  class AdminApp < Thor::Group
8
-
9
7
  # Add this generator to our padrino-gen
10
8
  Padrino::Generators.add_generator(:admin, self)
11
9
 
12
10
  # Define the source template root
13
- def self.source_root; File.expand_path(File.dirname(__FILE__)); end
11
+ def self.source_root; __dir__; end
14
12
  # Defines the "banner" text for the CLI.
15
- def self.banner; "padrino-gen admin"; end
13
+ def self.banner; 'padrino-gen admin'; end
16
14
 
17
15
  # Include related modules.
18
16
  include Thor::Actions
@@ -22,34 +20,34 @@ module Padrino
22
20
  # Look for custom template files in a generators folder under the project root.
23
21
  def source_paths
24
22
  if File.exist? destination_root('generators', 'templates')
25
- ["#{destination_root('generators')}", File.expand_path(File.dirname(__FILE__))]
23
+ [destination_root('generators').to_s, __dir__]
26
24
  else
27
- [File.expand_path(File.dirname(__FILE__))]
25
+ [__dir__]
28
26
  end
29
27
  end
30
28
 
31
29
  desc "Description:\n\n\tpadrino-gen admin generates a new Padrino Admin application"
32
30
 
33
- class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
34
- # class_option :models_path, :desc => 'The models destination path', :default => '.', :type => :string
35
- class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
36
- class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
37
- class_option :renderer, :aliases => '-e', :desc => "Rendering engine (erb, haml, slim)", :type => :string
38
- class_option :admin_model, :aliases => '-m', :desc => "The name of model for access controlling", :default => 'Account', :type => :string
39
- class_option :admin_name, :aliases => '-a', :desc => 'The admin application name and path', :default => 'admin', :type => :string
31
+ class_option :skip_migration, type: :boolean, aliases: '-s', default: false
32
+ class_option :root, type: :string, aliases: '-r', default: '.', desc: 'The root destination'
33
+ class_option :destroy, type: :boolean, aliases: '-d', default: false
34
+ class_option :renderer, type: :string, aliases: '-e', desc: 'Rendering engine (erb, haml, slim)'
35
+ class_option :admin_model, type: :string, aliases: '-m', default: 'Account', desc: 'The name of model for access controlling'
36
+ class_option :admin_name, type: :string, aliases: '-a', default: 'admin', desc: 'The admin application name and path'
37
+ # class_option :models_path, desc: 'The models destination path', default: '.', type: :string
40
38
 
41
39
  # Copies over the Padrino base admin application.
42
40
  def create_admin
43
41
  self.destination_root = options[:root]
44
42
  if in_app_root?
45
43
  unless supported_orm.include?(orm)
46
- say "<= At the moment, Padrino only supports #{supported_orm.join(" or ")}. Sorry!", :yellow
44
+ say "<= At the moment, Padrino only supports #{supported_orm.join(' or ')}. Sorry!", :yellow
47
45
  raise SystemExit
48
46
  end
49
47
 
50
48
  tmp_ext = options[:renderer] || fetch_component_choice(:renderer)
51
49
  unless supported_ext.include?(tmp_ext.to_sym)
52
- say "<= You are using '#{tmp_ext}' and for admin we only support '#{supported_ext.join(', ')}'. Please use #{supported_ext.map { |ext| '-e ' + ext.to_s }.join(' or ')}", :yellow
50
+ say "<= You are using '#{tmp_ext}' and for admin we only support '#{supported_ext.join(', ')}'. Please use #{supported_ext.map { |ext| "-e #{ext}" }.join(' or ')}", :yellow
53
51
  raise SystemExit
54
52
  end
55
53
 
@@ -71,100 +69,102 @@ module Padrino
71
69
  @model_singular = @model_name.underscore
72
70
  @model_plural = @model_singular.pluralize
73
71
 
74
- directory "templates/app", destination_root(@admin_path)
75
- directory "templates/assets", destination_root("public", @admin_path)
76
- template "templates/app.rb.tt", destination_root(@admin_path + "/app.rb")
77
- inject_into_file destination_root('config/apps.rb'), "\nPadrino.mount(\"#{@app_name}::#{@admin_name}\", :app_file => Padrino.root('#{@admin_path}/app.rb')).to(\"/#{@admin_path}\")\n", :before => /^Padrino.mount.*\.to\('\/'\)$/
72
+ directory 'templates/app', destination_root(@admin_path)
73
+ directory 'templates/assets', destination_root('public', @admin_path)
74
+ template 'templates/app.rb.tt', destination_root("#{@admin_path}/app.rb")
75
+ inject_into_file destination_root('config/apps.rb'), <<~RUBY.prepend("\n"), before: %r{^Padrino.mount.*\.to\('/'\)$}
76
+ Padrino.mount('#{@app_name}::#{@admin_name}', app_file: Padrino.root('#{@admin_path}/app.rb')).to('/#{@admin_path}')
77
+ RUBY
78
+
78
79
  unless options[:destroy]
79
- insert_middleware 'ConnectionPoolManagement', @admin_path if [:minirecord, :activerecord].include?(orm)
80
+ insert_middleware 'ConnectionPoolManagement', @admin_path if %i[minirecord activerecord].include?(orm)
80
81
  insert_middleware 'IdentityMap', @admin_path if orm == :datamapper
81
82
  end
82
83
 
83
84
  params = [
84
- @model_singular, "name:string", "surname:string", "email:string", "crypted_password:string", "role:string",
85
+ @model_singular, 'name:string', 'surname:string', 'email:string', 'crypted_password:string', 'role:string',
85
86
  "-a=#{options[:models_path]}",
86
87
  "-r=#{options[:root]}"
87
88
  ]
88
- params << "-s" if options[:skip_migration]
89
- params << "-d" if options[:destroy]
89
+ params << '-s' if options[:skip_migration]
90
+ params << '-d' if options[:destroy]
90
91
 
91
92
  Padrino::Generators::Model.start(params)
92
93
  column = Struct.new(:name, :type)
93
- columns = [:id, :name, :surname, :email].map { |col| column.new(col) }
94
+ columns = %i[id name surname email].map { |col| column.new(col) }
94
95
  column_fields = [
95
- { :name => :name, :field_type => :text_field },
96
- { :name => :surname, :field_type => :text_field },
97
- { :name => :email, :field_type => :text_field },
98
- { :name => :password, :field_type => :password_field },
99
- { :name => :password_confirmation, :field_type => :password_field },
100
- { :name => :role, :field_type => :text_field }
96
+ { name: :name, field_type: :text_field },
97
+ { name: :surname, field_type: :text_field },
98
+ { name: :email, field_type: :text_field },
99
+ { name: :password, field_type: :password_field },
100
+ { name: :password_confirmation, field_type: :password_field },
101
+ { name: :role, field_type: :text_field }
101
102
  ]
102
103
 
103
104
  unless options[:destroy]
104
- admin_app = Padrino::Generators::AdminPage.new([@model_singular], :root => options[:root], :destroy => options[:destroy], :admin_model => @model_singular, :admin_name => @admin_name)
105
+ admin_app = Padrino::Generators::AdminPage.new([@model_singular], root: options[:root], destroy: options[:destroy], admin_model: @model_singular, admin_name: @admin_name)
105
106
  admin_app.default_orm = Padrino::Admin::Generators::Orm.new(@model_singular, orm, columns, column_fields)
106
107
  admin_app.invoke_all
107
108
  end
108
109
 
109
- # TODO See this, there's something wrong it's not being applied properly or something because test_account_model_generator last test fails.
110
- template "templates/account/#{orm}.rb.tt", destination_root("models", "#{@model_singular}.rb"), :force => true
110
+ # TODO: See this, there's something wrong it's not being applied properly or something because test_account_model_generator last test fails.
111
+ template "templates/account/#{orm}.rb.tt", destination_root('models', "#{@model_singular}.rb"), force: true
111
112
 
112
- if File.exist?(destination_root("db/seeds.rb"))
113
- run "mv #{destination_root('db/seeds.rb')} #{destination_root('db/seeds.old')}"
114
- end
115
- template "templates/account/seeds.rb.tt", destination_root("db/seeds.rb")
116
-
117
- empty_directory destination_root(@admin_path+"/controllers")
118
- empty_directory destination_root(@admin_path+"/views")
119
- empty_directory destination_root(@admin_path+"/views/base")
120
- empty_directory destination_root(@admin_path+"/views/layouts")
121
- empty_directory destination_root(@admin_path+"/views/sessions")
122
- empty_directory destination_root(@admin_path+"/views/errors")
123
-
124
- template "templates/#{ext}/app/base/index.#{ext}.tt", destination_root(@admin_path+"/views/base/index.#{ext}")
125
- template "templates/#{ext}/app/layouts/application.#{ext}.tt", destination_root(@admin_path+"/views/layouts/application.#{ext}")
126
- template "templates/#{ext}/app/layouts/error.#{ext}.tt", destination_root(@admin_path+"/views/layouts/error.#{ext}")
127
- template "templates/#{ext}/app/sessions/new.#{ext}.tt", destination_root(@admin_path+"/views/sessions/new.#{ext}")
113
+ seed_destination = destination_root('db', 'seeds.rb')
114
+ run "mv #{seed_destination} #{destination_root('db/seeds.old')}" if File.exist?(seed_destination)
115
+ template 'templates/account/seeds.rb.tt', seed_destination
116
+
117
+ empty_directory destination_root("#{@admin_path}/controllers")
118
+ empty_directory destination_root("#{@admin_path}/views")
119
+ empty_directory destination_root("#{@admin_path}/views/base")
120
+ empty_directory destination_root("#{@admin_path}/views/layouts")
121
+ empty_directory destination_root("#{@admin_path}/views/sessions")
122
+ empty_directory destination_root("#{@admin_path}/views/errors")
123
+
124
+ template "templates/#{ext}/app/base/index.#{ext}.tt", destination_root("#{@admin_path}/views/base/index.#{ext}")
125
+ template "templates/#{ext}/app/layouts/application.#{ext}.tt", destination_root("#{@admin_path}/views/layouts/application.#{ext}")
126
+ template "templates/#{ext}/app/layouts/error.#{ext}.tt", destination_root("#{@admin_path}/views/layouts/error.#{ext}")
127
+ template "templates/#{ext}/app/sessions/new.#{ext}.tt", destination_root("#{@admin_path}/views/sessions/new.#{ext}")
128
128
  # Custom error.
129
- template "templates/#{ext}/app/errors/403.#{ext}.tt", destination_root(@admin_path+"/views/errors/403.#{ext}")
130
- template "templates/#{ext}/app/errors/404.#{ext}.tt", destination_root(@admin_path+"/views/errors/404.#{ext}")
131
- template "templates/#{ext}/app/errors/500.#{ext}.tt", destination_root(@admin_path+"/views/errors/500.#{ext}")
129
+ template "templates/#{ext}/app/errors/403.#{ext}.tt", destination_root("#{@admin_path}/views/errors/403.#{ext}")
130
+ template "templates/#{ext}/app/errors/404.#{ext}.tt", destination_root("#{@admin_path}/views/errors/404.#{ext}")
131
+ template "templates/#{ext}/app/errors/500.#{ext}.tt", destination_root("#{@admin_path}/views/errors/500.#{ext}")
132
132
 
133
133
  unless options[:destroy]
134
134
  add_project_module @model_plural
135
135
  require_dependencies('bcrypt')
136
136
  end
137
137
 
138
- require_dependencies 'activesupport', :version => ">= 3.1"
138
+ require_dependencies 'activesupport', version: '>= 3.1'
139
139
 
140
140
  # A nicer select box.
141
141
  # TODO FIXME This doesn't make much sense in here. Review.
142
- # gsub_file destination_root("admin/views/#{@model_plural}/_form.#{ext}"), "f.text_field :role, :class => :text_field", "f.select :role, :options => access_control.roles"
142
+ # gsub_file destination_root("admin/views/#{@model_plural}/_form.#{ext}"), "f.text_field :role, class: :text_field", "f.select :role, options: access_control.roles"
143
143
 
144
144
  # Destroy account only if not logged in.
145
- gsub_file destination_root(@admin_path+"/controllers/#{@model_plural}.rb"), "if #{@model_singular}.destroy", "if #{@model_singular} != current_account && #{@model_singular}.destroy"
145
+ gsub_file destination_root("#{@admin_path}/controllers/#{@model_plural}.rb"), "if #{@model_singular}.destroy", "if #{@model_singular} != current_account && #{@model_singular}.destroy"
146
146
  return if self.behavior == :revoke
147
147
 
148
148
  instructions = []
149
149
  instructions << "Run 'bundle'"
150
- if [:activerecord, :datamapper, :sequel].include?(orm)
150
+ if %i[activerecord datamapper sequel].include?(orm)
151
151
  instructions << "Run 'bundle exec rake db:create' if you have not created a database yet"
152
152
  instructions << "Run 'bundle exec rake db:migrate'"
153
153
  end
154
154
  instructions << "Now repeat after me... 'ohm mani padme hum', 'ohm mani padme hum'... :)" if orm == :ohm
155
155
  instructions << "Run 'bundle exec rake db:seed'"
156
156
  instructions << "Visit the admin panel in the browser at '/#{@admin_path}'"
157
- instructions.map! { |i| " #{instructions.index(i)+1}) #{i}" }
157
+ instructions.map! { |i| " #{instructions.index(i) + 1}) #{i}" }
158
158
 
159
159
  say
160
- say "="*65, :green
161
- say "The admin panel has been mounted! Next, follow these steps:", :green
162
- say "="*65, :green
160
+ say '=' * 65, :green
161
+ say 'The admin panel has been mounted! Next, follow these steps:', :green
162
+ say '=' * 65, :green
163
163
  say instructions.join("\n")
164
- say "="*65, :green
164
+ say '=' * 65, :green
165
165
  say
166
166
  else
167
- say "You are not at the root of a Padrino application! (config/boot.rb not found)"
167
+ say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
168
168
  end
169
169
  end
170
170
  end
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  module Padrino
3
2
  module Generators
4
3
  ##
@@ -11,9 +10,9 @@ module Padrino
11
10
  Padrino::Generators.add_generator(:admin_page, self)
12
11
 
13
12
  # Define the source template root.
14
- def self.source_root; File.expand_path(File.dirname(__FILE__)); end
13
+ def self.source_root; __dir__; end
15
14
  # Defines the "banner" text for the CLI.
16
- def self.banner; "padrino-gen admin_page [model]"; end
15
+ def self.banner; 'padrino-gen admin_page [model]'; end
17
16
 
18
17
  # Include related modules.
19
18
  include Thor::Actions
@@ -23,18 +22,18 @@ module Padrino
23
22
  # Look for custom template files in a generators folder under the project root.
24
23
  def source_paths
25
24
  if File.exist? destination_root('generators')
26
- ["#{destination_root('generators')}", File.expand_path(File.dirname(__FILE__))]
25
+ [destination_root('generators').to_s, __dir__]
27
26
  else
28
- [File.expand_path(File.dirname(__FILE__))]
27
+ [__dir__]
29
28
  end
30
29
  end
31
30
 
32
31
  desc "Description:\n\n\tpadrino-gen admin_page model(s)"
33
- argument :models, :desc => "The name(s) of your model(s)", :type => :array
34
- class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
35
- class_option :root, :desc => "The root destination", :aliases => '-r', :type => :string
36
- class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
37
- class_option :admin_name, :aliases => '-a', :desc => 'The admin application name and path', :default => 'admin', :type => :string
32
+ argument :models, desc: 'The name(s) of your model(s)', type: :array
33
+ class_option :skip_migration, aliases: '-s', default: false, type: :boolean
34
+ class_option :root, desc: 'The root destination', aliases: '-r', type: :string
35
+ class_option :destroy, aliases: '-d', default: false, type: :boolean
36
+ class_option :admin_name, aliases: '-a', desc: 'The admin application name and path', default: 'admin', type: :string
38
37
  # Show help if no argv given.
39
38
  require_arguments!
40
39
 
@@ -49,18 +48,18 @@ module Padrino
49
48
  models.each do |model|
50
49
  @orm = default_orm || Padrino::Admin::Generators::Orm.new(model, adapter)
51
50
  self.behavior = :revoke if options[:destroy]
52
- empty_directory destination_root(@admin_path+"/views/#{@orm.name_plural}")
51
+ empty_directory destination_root("#{@admin_path}/views/#{@orm.name_plural}")
53
52
 
54
- template "templates/page/controller.rb.tt", destination_root(@admin_path+"/controllers/#{@orm.name_plural}.rb")
55
- template "templates/#{ext}/page/_form.#{ext}.tt", destination_root(@admin_path+"/views/#{@orm.name_plural}/_form.#{ext}")
56
- template "templates/#{ext}/page/edit.#{ext}.tt", destination_root(@admin_path+"/views/#{@orm.name_plural}/edit.#{ext}")
57
- template "templates/#{ext}/page/index.#{ext}.tt", destination_root(@admin_path+"/views/#{@orm.name_plural}/index.#{ext}")
58
- template "templates/#{ext}/page/new.#{ext}.tt", destination_root(@admin_path+"/views/#{@orm.name_plural}/new.#{ext}")
53
+ template 'templates/page/controller.rb.tt', destination_root("#{@admin_path}/controllers/#{@orm.name_plural}.rb")
54
+ template "templates/#{ext}/page/_form.#{ext}.tt", destination_root("#{@admin_path}/views/#{@orm.name_plural}/_form.#{ext}")
55
+ template "templates/#{ext}/page/edit.#{ext}.tt", destination_root("#{@admin_path}/views/#{@orm.name_plural}/edit.#{ext}")
56
+ template "templates/#{ext}/page/index.#{ext}.tt", destination_root("#{@admin_path}/views/#{@orm.name_plural}/index.#{ext}")
57
+ template "templates/#{ext}/page/new.#{ext}.tt", destination_root("#{@admin_path}/views/#{@orm.name_plural}/new.#{ext}")
59
58
 
60
59
  options[:destroy] ? remove_project_module(@orm.name_plural) : add_project_module(@orm.name_plural)
61
60
  end
62
61
  else
63
- say "You are not at the root of a Padrino application! (config/boot.rb not found)"
62
+ say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
64
63
  end
65
64
  end
66
65
  end