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.
- checksums.yaml +4 -4
- data/Rakefile +5 -5
- data/lib/padrino-admin/access_control.rb +10 -9
- data/lib/padrino-admin/generators/actions.rb +8 -8
- data/lib/padrino-admin/generators/admin_app.rb +62 -62
- data/lib/padrino-admin/generators/admin_page.rb +16 -17
- data/lib/padrino-admin/generators/orm.rb +56 -65
- data/lib/padrino-admin/generators/templates/account/activerecord.rb.tt +11 -11
- data/lib/padrino-admin/generators/templates/account/couchrest.rb.tt +10 -10
- data/lib/padrino-admin/generators/templates/account/datamapper.rb.tt +11 -11
- data/lib/padrino-admin/generators/templates/account/dynamoid.rb.tt +9 -9
- data/lib/padrino-admin/generators/templates/account/minirecord.rb.tt +11 -11
- data/lib/padrino-admin/generators/templates/account/mongoid.rb.tt +16 -16
- data/lib/padrino-admin/generators/templates/account/mongomapper.rb.tt +11 -11
- data/lib/padrino-admin/generators/templates/account/ohm.rb.tt +2 -2
- data/lib/padrino-admin/generators/templates/account/seeds.rb.tt +2 -2
- data/lib/padrino-admin/generators/templates/app/controllers/base.rb.tt +2 -2
- data/lib/padrino-admin/generators/templates/app/controllers/sessions.rb.tt +2 -2
- data/lib/padrino-admin/generators/templates/app.rb.tt +7 -7
- data/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt +10 -9
- data/lib/padrino-admin/generators/templates/erb/app/layouts/error.erb.tt +3 -2
- data/lib/padrino-admin/generators/templates/erb/app/sessions/new.erb.tt +8 -7
- data/lib/padrino-admin/generators/templates/erb/page/_form.erb.tt +7 -7
- data/lib/padrino-admin/generators/templates/erb/page/edit.erb.tt +3 -3
- data/lib/padrino-admin/generators/templates/erb/page/index.erb.tt +12 -12
- data/lib/padrino-admin/generators/templates/erb/page/new.erb.tt +2 -2
- data/lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt +10 -5
- data/lib/padrino-admin/generators/templates/haml/app/layouts/application.haml.tt +14 -14
- data/lib/padrino-admin/generators/templates/haml/app/layouts/error.haml.tt +6 -5
- data/lib/padrino-admin/generators/templates/haml/app/sessions/new.haml.tt +12 -11
- data/lib/padrino-admin/generators/templates/haml/page/_form.haml.tt +7 -7
- data/lib/padrino-admin/generators/templates/haml/page/edit.haml.tt +3 -3
- data/lib/padrino-admin/generators/templates/haml/page/index.haml.tt +14 -14
- data/lib/padrino-admin/generators/templates/haml/page/new.haml.tt +2 -2
- data/lib/padrino-admin/generators/templates/page/controller.rb.tt +25 -25
- data/lib/padrino-admin/generators/templates/slim/app/layouts/application.slim.tt +9 -9
- data/lib/padrino-admin/generators/templates/slim/app/layouts/error.slim.tt +1 -1
- data/lib/padrino-admin/generators/templates/slim/app/sessions/new.slim.tt +6 -6
- data/lib/padrino-admin/generators/templates/slim/page/_form.slim.tt +6 -6
- data/lib/padrino-admin/generators/templates/slim/page/edit.slim.tt +3 -3
- data/lib/padrino-admin/generators/templates/slim/page/index.slim.tt +12 -12
- data/lib/padrino-admin/generators/templates/slim/page/new.slim.tt +2 -2
- data/lib/padrino-admin/helpers/authentication_helpers.rb +7 -7
- data/lib/padrino-admin/helpers/view_helpers.rb +11 -11
- data/lib/padrino-admin.rb +4 -3
- data/padrino-admin.gemspec +18 -18
- data/test/fixtures/sequel.rb +14 -14
- data/test/generators/test_account_model_generator.rb +4 -4
- data/test/generators/test_admin_app_generator.rb +22 -22
- data/test/generators/test_admin_page_generator.rb +30 -30
- data/test/helper.rb +6 -6
- data/test/test_admin_application.rb +114 -116
- data/test/test_locale.rb +3 -3
- metadata +8 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5488a7db533da911edc1e5a6d9a93ada47389ae6cce07d91b0f40443700a81b1
|
|
4
|
+
data.tar.gz: a3d6dd922905dc573665ac9f505d12af787af4682dfe884bde3572d37a079d79
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bff20f86a10e7e5ecd9d4024655e06f552a54ba1532d6e58aaa67f917f25a708480fdce21edbe0aa2cd915bea9d0238b5be4e492bb1609ac06e04a0beed1c185
|
|
7
|
+
data.tar.gz: 94bc71711fd785063a27f065e0d51a58515442a19e6d8387e8da7a3c41957dec7f02a408c2cb75f4f5a6fb221a7b9167e84309c7b128180a94ba0a822700c549
|
data/Rakefile
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
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
|
|
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(
|
|
13
|
-
out = File.join(
|
|
14
|
-
css = Less::Parser.new(:
|
|
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
|
|
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.
|
|
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, :
|
|
103
|
+
# = link_to 'Profile', url(:accounts, :edit, id: current_account.id)
|
|
103
104
|
#
|
|
104
|
-
def allowed?(account=nil, path=nil)
|
|
105
|
-
path =
|
|
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
|
-
|
|
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
|
|
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
|
-
[
|
|
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
|
-
[
|
|
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
|
|
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
|
|
53
|
-
say_status :replace, @admin_path
|
|
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!(
|
|
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;
|
|
11
|
+
def self.source_root; __dir__; end
|
|
14
12
|
# Defines the "banner" text for the CLI.
|
|
15
|
-
def self.banner;
|
|
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
|
-
[
|
|
23
|
+
[destination_root('generators').to_s, __dir__]
|
|
26
24
|
else
|
|
27
|
-
[
|
|
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
|
|
34
|
-
|
|
35
|
-
class_option :
|
|
36
|
-
class_option :
|
|
37
|
-
class_option :
|
|
38
|
-
class_option :
|
|
39
|
-
class_option :
|
|
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(
|
|
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|
|
|
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
|
|
75
|
-
directory
|
|
76
|
-
template
|
|
77
|
-
inject_into_file destination_root('config/apps.rb'),
|
|
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 [
|
|
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,
|
|
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 <<
|
|
89
|
-
params <<
|
|
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 = [
|
|
94
|
+
columns = %i[id name surname email].map { |col| column.new(col) }
|
|
94
95
|
column_fields = [
|
|
95
|
-
{ :
|
|
96
|
-
{ :
|
|
97
|
-
{ :
|
|
98
|
-
{ :
|
|
99
|
-
{ :
|
|
100
|
-
{ :
|
|
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], :
|
|
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(
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
empty_directory destination_root(@admin_path
|
|
118
|
-
empty_directory destination_root(@admin_path
|
|
119
|
-
empty_directory destination_root(@admin_path
|
|
120
|
-
empty_directory destination_root(@admin_path
|
|
121
|
-
empty_directory destination_root(@admin_path
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
template "templates/#{ext}/app/
|
|
125
|
-
template "templates/#{ext}/app/layouts/
|
|
126
|
-
template "templates/#{ext}/app/
|
|
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
|
|
130
|
-
template "templates/#{ext}/app/errors/404.#{ext}.tt", destination_root(@admin_path
|
|
131
|
-
template "templates/#{ext}/app/errors/500.#{ext}.tt", destination_root(@admin_path
|
|
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', :
|
|
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, :
|
|
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
|
|
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 [
|
|
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
|
|
161
|
-
say
|
|
162
|
-
say
|
|
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
|
|
164
|
+
say '=' * 65, :green
|
|
165
165
|
say
|
|
166
166
|
else
|
|
167
|
-
say
|
|
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;
|
|
13
|
+
def self.source_root; __dir__; end
|
|
15
14
|
# Defines the "banner" text for the CLI.
|
|
16
|
-
def self.banner;
|
|
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
|
-
[
|
|
25
|
+
[destination_root('generators').to_s, __dir__]
|
|
27
26
|
else
|
|
28
|
-
[
|
|
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, :
|
|
34
|
-
class_option :skip_migration, :
|
|
35
|
-
class_option :root, :
|
|
36
|
-
class_option :destroy, :
|
|
37
|
-
class_option :admin_name,
|
|
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
|
|
51
|
+
empty_directory destination_root("#{@admin_path}/views/#{@orm.name_plural}")
|
|
53
52
|
|
|
54
|
-
template
|
|
55
|
-
template "templates/#{ext}/page/_form.#{ext}.tt", destination_root(@admin_path
|
|
56
|
-
template "templates/#{ext}/page/edit.#{ext}.tt", destination_root(@admin_path
|
|
57
|
-
template "templates/#{ext}/page/index.#{ext}.tt", destination_root(@admin_path
|
|
58
|
-
template "templates/#{ext}/page/new.#{ext}.tt", destination_root(@admin_path
|
|
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
|
|
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
|