padrino-admin 0.18.0 → 0.18.2
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/lib/padrino-admin/generators/actions.rb +1 -0
- data/lib/padrino-admin/generators/admin_app.rb +36 -17
- data/lib/padrino-admin/generators/admin_page.rb +2 -1
- data/lib/padrino-admin/generators/keep_files.rb +56 -0
- data/lib/padrino-admin/generators/orm.rb +16 -2
- data/lib/padrino-admin/generators/templates/account/mongoid.rb.tt +1 -1
- data/lib/padrino-admin/generators/templates/app/controllers/sessions.rb.tt +0 -4
- data/lib/padrino-admin/generators/templates/assets/stylesheets/application.css +0 -3
- data/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt +0 -5
- data/lib/padrino-admin/generators/templates/erb/app/layouts/error.erb.tt +0 -5
- data/lib/padrino-admin/generators/templates/erb/app/sessions/new.erb.tt +0 -10
- data/lib/padrino-admin/generators/templates/erb/page/index.erb.tt +2 -2
- data/lib/padrino-admin/generators/templates/haml/app/layouts/application.haml.tt +0 -5
- data/lib/padrino-admin/generators/templates/haml/app/layouts/error.haml.tt +0 -5
- data/lib/padrino-admin/generators/templates/haml/app/sessions/new.haml.tt +0 -10
- data/lib/padrino-admin/generators/templates/haml/page/index.haml.tt +2 -2
- data/lib/padrino-admin/generators/templates/page/controller.rb.tt +0 -3
- data/lib/padrino-admin/generators/templates/slim/app/layouts/application.slim.tt +0 -5
- data/lib/padrino-admin/generators/templates/slim/app/layouts/error.slim.tt +0 -5
- data/lib/padrino-admin/generators/templates/slim/app/sessions/new.slim.tt +0 -10
- data/lib/padrino-admin/generators/templates/slim/page/index.slim.tt +2 -2
- data/lib/padrino-admin/helpers/authentication_helpers.rb +3 -1
- data/lib/padrino-admin.rb +21 -1
- data/padrino-admin.gemspec +8 -3
- data/test/generators/test_admin_app_generator.rb +54 -0
- data/test/generators/test_admin_page_generator.rb +130 -4
- data/test/generators/test_admin_rerun_generator.rb +244 -0
- data/test/test_admin_application.rb +73 -0
- metadata +15 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d4201a847361929f410a70a3254c1a71b1af1f16e599e8c289fd19352424ef6b
|
|
4
|
+
data.tar.gz: dd2c63edb9c513fc90122af641619ce19502de997c2a1d870f08e7ae7256d516
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10f18575e2a4d40c57c4ce49923be8b84964fa83fbf55e9ba5884d88d7641e0aa72d5a82ef5dcc884b3ead6e069551afaebb120e72f09b50a605426fe1c9cafb
|
|
7
|
+
data.tar.gz: 1ce89c2fd6e3721ece45a02b950063928df23f97655458d37dccb5d1c9bd89d2cbac4257930fcfd02ddea73c65db69de06a6757af4001b19d88aad75d3c7d060
|
|
@@ -16,6 +16,7 @@ module Padrino
|
|
|
16
16
|
include Thor::Actions
|
|
17
17
|
include Padrino::Generators::Actions
|
|
18
18
|
include Padrino::Generators::Admin::Actions
|
|
19
|
+
include Padrino::Generators::Admin::KeepFiles
|
|
19
20
|
|
|
20
21
|
# Look for custom template files in a generators folder under the project root.
|
|
21
22
|
def source_paths
|
|
@@ -57,26 +58,35 @@ module Padrino
|
|
|
57
58
|
@admin_name = options[:admin_name].classify
|
|
58
59
|
@admin_path = options[:admin_name].underscore
|
|
59
60
|
|
|
61
|
+
# Setup Admin Model
|
|
62
|
+
@model_name = options[:admin_model].classify
|
|
63
|
+
@model_singular = @model_name.underscore
|
|
64
|
+
@model_plural = @model_singular.pluralize
|
|
65
|
+
model_path = destination_root('models', "#{@model_singular}.rb")
|
|
66
|
+
|
|
67
|
+
# A plain app (g app admin) or a missing one: an admin app has access control once generated.
|
|
68
|
+
first_install = !line_in_file?(destination_root(@admin_path, 'app.rb'), /Padrino::Admin::AccessControl/)
|
|
69
|
+
|
|
70
|
+
stop_for_model_without_login(model_path) if first_install && !options[:destroy]
|
|
71
|
+
|
|
60
72
|
store_component_choice(:admin_renderer, tmp_ext)
|
|
61
73
|
|
|
62
74
|
self.behavior = :revoke if options[:destroy]
|
|
63
75
|
|
|
64
76
|
empty_directory destination_root(@admin_path)
|
|
65
77
|
|
|
66
|
-
# Setup Admin Model
|
|
67
|
-
@model_name = options[:admin_model].classify
|
|
68
|
-
@model_singular = @model_name.underscore
|
|
69
|
-
@model_plural = @model_singular.pluralize
|
|
70
|
-
|
|
71
78
|
directory 'templates/app', destination_root(@admin_path)
|
|
72
79
|
directory 'templates/assets', destination_root('public', @admin_path)
|
|
73
80
|
template 'templates/app.rb.tt', destination_root("#{@admin_path}/app.rb")
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
mounted = /^\s*Padrino\.mount\W+#{@app_name}::#{@admin_name}\b/
|
|
82
|
+
if options[:destroy] || !line_in_file?(destination_root('config/apps.rb'), mounted)
|
|
83
|
+
inject_into_file destination_root('config/apps.rb'), <<~RUBY.prepend("\n"), before: %r{^Padrino.mount.*\.to\('/'\)$}
|
|
84
|
+
Padrino.mount('#{@app_name}::#{@admin_name}', app_file: Padrino.root('#{@admin_path}/app.rb')).to('/#{@admin_path}')
|
|
85
|
+
RUBY
|
|
86
|
+
end
|
|
77
87
|
|
|
78
|
-
unless options[:destroy]
|
|
79
|
-
insert_middleware 'ConnectionPoolManagement', @admin_path
|
|
88
|
+
unless options[:destroy] || orm != :activerecord || line_in_file?(destination_root(@admin_path, 'app.rb'), /^\s*use[\s(]+ConnectionPoolManagement\b/)
|
|
89
|
+
insert_middleware 'ConnectionPoolManagement', @admin_path
|
|
80
90
|
end
|
|
81
91
|
|
|
82
92
|
params = [
|
|
@@ -87,7 +97,7 @@ module Padrino
|
|
|
87
97
|
params << '-d' if options[:destroy]
|
|
88
98
|
|
|
89
99
|
# An existing model is reused: the model generator would refuse it and exit 1.
|
|
90
|
-
model_exists = already_exists?(@model_name, fetch_component_choice(:namespace))
|
|
100
|
+
model_exists = already_exists?(@model_name, fetch_component_choice(:namespace)) || File.exist?(model_path)
|
|
91
101
|
Padrino::Generators::Model.start(params) if options[:destroy] || !model_exists
|
|
92
102
|
column = Struct.new(:name, :type)
|
|
93
103
|
columns = %i[id name surname email].map { |col| column.new(col) }
|
|
@@ -100,6 +110,9 @@ module Padrino
|
|
|
100
110
|
{ name: :role, field_type: :text_field }
|
|
101
111
|
]
|
|
102
112
|
|
|
113
|
+
controller = destination_root("#{@admin_path}/controllers/#{@model_plural}.rb")
|
|
114
|
+
controller_before = File.binread(controller) if File.exist?(controller)
|
|
115
|
+
|
|
103
116
|
unless options[:destroy]
|
|
104
117
|
admin_app = Padrino::Generators::AdminPage.new([@model_singular], root: options[:root], destroy: options[:destroy], admin_model: @model_singular, admin_name: options[:admin_name])
|
|
105
118
|
admin_app.default_orm = Padrino::Admin::Generators::Orm.new(@model_singular, orm, columns, column_fields)
|
|
@@ -107,10 +120,14 @@ module Padrino
|
|
|
107
120
|
end
|
|
108
121
|
|
|
109
122
|
# 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",
|
|
123
|
+
template "templates/account/#{orm}.rb.tt", model_path, force: !model_exists
|
|
111
124
|
|
|
125
|
+
# Seeds of the admin model stay in place; moving others aside never replaces an earlier move.
|
|
112
126
|
seed_destination = destination_root('db', 'seeds.rb')
|
|
113
|
-
|
|
127
|
+
seed_backup = destination_root('db/seeds.old')
|
|
128
|
+
if first_install && File.exist?(seed_destination) && !File.exist?(seed_backup) && !line_in_file?(seed_destination, /\b#{@model_name}\b/)
|
|
129
|
+
run "mv #{seed_destination} #{seed_backup}"
|
|
130
|
+
end
|
|
114
131
|
template 'templates/account/seeds.rb.tt', seed_destination
|
|
115
132
|
|
|
116
133
|
empty_directory destination_root("#{@admin_path}/controllers")
|
|
@@ -129,19 +146,21 @@ module Padrino
|
|
|
129
146
|
template "templates/#{ext}/app/errors/404.#{ext}.tt", destination_root("#{@admin_path}/views/errors/404.#{ext}")
|
|
130
147
|
template "templates/#{ext}/app/errors/500.#{ext}.tt", destination_root("#{@admin_path}/views/errors/500.#{ext}")
|
|
131
148
|
|
|
149
|
+
gemfile = destination_root('Gemfile')
|
|
132
150
|
unless options[:destroy]
|
|
133
|
-
|
|
134
|
-
require_dependencies('bcrypt')
|
|
151
|
+
add_missing_project_module @model_plural
|
|
152
|
+
require_dependencies('bcrypt') unless line_in_file?(gemfile, /^\s*gem[\s(]+['"]bcrypt['"]/)
|
|
135
153
|
end
|
|
136
154
|
|
|
137
|
-
require_dependencies 'activesupport', version: '>= 3.1'
|
|
155
|
+
require_dependencies 'activesupport', version: '>= 3.1' if options[:destroy] || !line_in_file?(gemfile, /^\s*gem[\s(]+['"]activesupport['"]/)
|
|
138
156
|
|
|
139
157
|
# A nicer select box.
|
|
140
158
|
# TODO FIXME This doesn't make much sense in here. Review.
|
|
141
159
|
# 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
160
|
|
|
143
161
|
# Destroy account only if not logged in.
|
|
144
|
-
|
|
162
|
+
controller_after = File.binread(controller) if File.exist?(controller)
|
|
163
|
+
gsub_file controller, "if #{@model_singular}.destroy", "if #{@model_singular} != current_account && #{@model_singular}.destroy" if controller_after != controller_before
|
|
145
164
|
return if self.behavior == :revoke
|
|
146
165
|
|
|
147
166
|
instructions = []
|
|
@@ -18,6 +18,7 @@ module Padrino
|
|
|
18
18
|
include Thor::Actions
|
|
19
19
|
include Padrino::Generators::Actions
|
|
20
20
|
include Padrino::Generators::Admin::Actions
|
|
21
|
+
include Padrino::Generators::Admin::KeepFiles
|
|
21
22
|
|
|
22
23
|
# Look for custom template files in a generators folder under the project root.
|
|
23
24
|
def source_paths
|
|
@@ -66,7 +67,7 @@ module Padrino
|
|
|
66
67
|
template "templates/#{ext}/page/index.#{ext}.tt", destination_root("#{@admin_path}/views/#{@orm.name_plural}/index.#{ext}")
|
|
67
68
|
template "templates/#{ext}/page/new.#{ext}.tt", destination_root("#{@admin_path}/views/#{@orm.name_plural}/new.#{ext}")
|
|
68
69
|
|
|
69
|
-
options[:destroy] ? remove_project_module(@orm.name_plural) :
|
|
70
|
+
options[:destroy] ? remove_project_module(@orm.name_plural) : add_missing_project_module(@orm.name_plural)
|
|
70
71
|
end
|
|
71
72
|
else
|
|
72
73
|
exit_outside_app_root!
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module Padrino
|
|
2
|
+
module Generators
|
|
3
|
+
module Admin
|
|
4
|
+
##
|
|
5
|
+
# Keeps an existing file when its overwrite prompt is left unanswered.
|
|
6
|
+
#
|
|
7
|
+
module KeepFiles
|
|
8
|
+
##
|
|
9
|
+
# Answers no at the end of input (no terminal, empty pipe), which Thor takes as a yes.
|
|
10
|
+
# Other answers, including piped ones, work as usual.
|
|
11
|
+
#
|
|
12
|
+
module Shell
|
|
13
|
+
def file_collision(destination)
|
|
14
|
+
@resolving_file_collision = true
|
|
15
|
+
super
|
|
16
|
+
ensure
|
|
17
|
+
@resolving_file_collision = false
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def ask(statement, *args)
|
|
21
|
+
answer = super
|
|
22
|
+
answer.nil? && @resolving_file_collision ? 'n' : answer
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def shell
|
|
27
|
+
super.extend(Shell)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
##
|
|
31
|
+
# Tells whether the file exists and has a line matching the pattern.
|
|
32
|
+
#
|
|
33
|
+
def line_in_file?(path, pattern)
|
|
34
|
+
File.exist?(path) && File.binread(path).match?(pattern)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
##
|
|
38
|
+
# Adds the access_control permission unless the app has one for the controller, edited or not.
|
|
39
|
+
#
|
|
40
|
+
def add_missing_project_module(controller)
|
|
41
|
+
add_project_module(controller) unless line_in_file?(destination_root("#{@admin_path}/app.rb"), /^\s*role\.project_module[\s(]+:#{controller}\b/)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
##
|
|
45
|
+
# Stops when the admin can't log in with an existing model and nobody is left to answer whether to replace it.
|
|
46
|
+
#
|
|
47
|
+
def stop_for_model_without_login(path)
|
|
48
|
+
return if !File.exist?(path) || line_in_file?(path, /\bauthenticate\b/) || $stdin.tty? || !$stdin.eof?
|
|
49
|
+
|
|
50
|
+
raise Thor::Error, "#{path} has no authenticate method and no input is left to confirm replacing it. " \
|
|
51
|
+
'Add the method to the model, or run the generator in a terminal to choose whether to replace the file.'
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -22,7 +22,7 @@ module Padrino
|
|
|
22
22
|
def initialize(name, orm, columns = nil, column_fields = nil)
|
|
23
23
|
name = name.to_s
|
|
24
24
|
@klass_name = name.underscore.camelize
|
|
25
|
-
@klass =
|
|
25
|
+
@klass = load_klass
|
|
26
26
|
@name_param = name.underscore.gsub('/', '_')
|
|
27
27
|
@name_singular = name.underscore.gsub(%r{^.*/}, '') # convert submodules i.e. FooBar::Jank.all # => jank
|
|
28
28
|
@name_plural = @name_singular.pluralize
|
|
@@ -35,6 +35,7 @@ module Padrino
|
|
|
35
35
|
# needed when reading the model's columns to generate a page, so destroying a page skips it.
|
|
36
36
|
def check_model_orm
|
|
37
37
|
return unless @columns.nil?
|
|
38
|
+
raise OrmError, "Model '#{klass_name}' could not be loaded#{' because the project failed to load' if @boot_failed}!\n#{@load_error.class}: #{@load_error.message}" if @load_error
|
|
38
39
|
raise OrmError, "Model '#{klass_name}' could not be found!\nPerhaps you would like to run 'bundle exec padrino g model #{klass_name}' to create it first?" if @klass.nil?
|
|
39
40
|
|
|
40
41
|
base = MODEL_BASES[orm]
|
|
@@ -49,7 +50,7 @@ module Padrino
|
|
|
49
50
|
|
|
50
51
|
def field_type(type)
|
|
51
52
|
type = :string if type.nil?
|
|
52
|
-
type =
|
|
53
|
+
type = Padrino::Inflections.demodulize(type).downcase.to_sym unless type.is_a?(Symbol)
|
|
53
54
|
|
|
54
55
|
case type
|
|
55
56
|
when :integer, :float, :decimal then :text_field
|
|
@@ -140,6 +141,19 @@ module Padrino
|
|
|
140
141
|
else "@#{name_singular}.errors.include?(:#{field})"
|
|
141
142
|
end
|
|
142
143
|
end
|
|
144
|
+
|
|
145
|
+
private
|
|
146
|
+
|
|
147
|
+
# Returns nil when the model is not defined. A model that failed to load keeps its error in
|
|
148
|
+
# @load_error, whether looking it up raised it or loading the project (config/boot.rb) did.
|
|
149
|
+
def load_klass
|
|
150
|
+
@klass_name.constantize
|
|
151
|
+
rescue StandardError => e
|
|
152
|
+
missing = Padrino::Admin.missing_constant?(e, @klass_name)
|
|
153
|
+
@load_error = missing ? Padrino::Generators.boot_error : e
|
|
154
|
+
@boot_failed = missing && !@load_error.nil?
|
|
155
|
+
nil
|
|
156
|
+
end
|
|
143
157
|
end
|
|
144
158
|
end
|
|
145
159
|
end
|
|
@@ -27,7 +27,7 @@ class <%= @model_name %>
|
|
|
27
27
|
# This method is for authentication purpose.
|
|
28
28
|
#
|
|
29
29
|
def self.authenticate(email, password)
|
|
30
|
-
account = where(email:
|
|
30
|
+
account = where(email: /\A#{Object::Regexp.escape(email)}\z/i).first if email.present?
|
|
31
31
|
account if account&.has_password?(password)
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -7,10 +7,6 @@
|
|
|
7
7
|
if account = <%= @model_name %>.authenticate(params[:email], params[:password])
|
|
8
8
|
set_current_account(account)
|
|
9
9
|
redirect url(:base, :index)
|
|
10
|
-
elsif Padrino.env == :development && params[:bypass]
|
|
11
|
-
account = <%= @model_name %>.first
|
|
12
|
-
set_current_account(account)
|
|
13
|
-
redirect url(:base, :index)
|
|
14
10
|
else
|
|
15
11
|
params[:email] = h(params[:email])
|
|
16
12
|
flash.now[:error] = pat('login.error')
|
|
@@ -139,7 +139,6 @@ footer p {
|
|
|
139
139
|
|
|
140
140
|
/* -- Begin Errors -- */
|
|
141
141
|
.custom-error {
|
|
142
|
-
font-family: 'Varela', sans-serif;
|
|
143
142
|
font-size: 1.5em;
|
|
144
143
|
width: 500px;
|
|
145
144
|
margin: 100px auto 0;
|
|
@@ -218,7 +217,6 @@ footer p {
|
|
|
218
217
|
margin-top: 10px;
|
|
219
218
|
height: 20px; /* Bootstrap 3.4 makes it 50px, which pushes the navbar down */
|
|
220
219
|
padding: 0px 15px;
|
|
221
|
-
font-family: 'Varela', sans-serif;
|
|
222
220
|
text-transform: uppercase;
|
|
223
221
|
font-size: 2.5em;
|
|
224
222
|
line-height: 1em;
|
|
@@ -318,7 +316,6 @@ footer p {
|
|
|
318
316
|
/* --- End Application::List --- */
|
|
319
317
|
/* --- Begin Application::Base --- */
|
|
320
318
|
.base-text {
|
|
321
|
-
font-family: 'Varela', sans-serif;
|
|
322
319
|
width: 730px;
|
|
323
320
|
margin: 40px auto 0;
|
|
324
321
|
font-size: 1.45em;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
|
|
3
3
|
<head>
|
|
4
|
-
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
|
|
5
|
-
<!--[if lt IE 9]>
|
|
6
|
-
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
|
7
|
-
<![endif]-->
|
|
8
4
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
|
9
5
|
<meta name=viewport content='width=device-width,initial-scale=1' />
|
|
10
6
|
<title><%%= @title.present? ? "#{@title} | Padrino Admin" : "Padrino Admin" %></title>
|
|
11
7
|
<%%= favicon_tag "favicon.ico" %>
|
|
12
|
-
<link href='http://fonts.googleapis.com/css?family=Varela' rel=stylesheet />
|
|
13
8
|
<%%= stylesheet_link_tag 'bootstrap', 'application' %>
|
|
14
9
|
</head>
|
|
15
10
|
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
-
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
|
|
5
|
-
<!--[if lt IE 9]>
|
|
6
|
-
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
|
7
|
-
<![endif]-->
|
|
8
4
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
|
9
5
|
<meta name=viewport content='width=device-width,initial-scale=1' />
|
|
10
6
|
<title><%%= @title.present? ? "#{@title} | Padrino Admin" : "#{pat(:custom_errors.title)} | Padrino Admin" %></title>
|
|
11
7
|
<%%= favicon_tag "favicon.ico" %>
|
|
12
|
-
<link href='http://fonts.googleapis.com/css?family=Varela' rel=stylesheet />
|
|
13
8
|
<%%= stylesheet_link_tag 'bootstrap', 'application' %>
|
|
14
9
|
</head>
|
|
15
10
|
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
-
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
|
|
5
|
-
<!--[if lt IE 9]>
|
|
6
|
-
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
|
7
|
-
<![endif]-->
|
|
8
4
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
|
9
5
|
<meta name=viewport content='width=device-width,initial-scale=1' />
|
|
10
6
|
<title><%%= @title.present? ? "#{@title} | Padrino Admin" : "#{pat('login.title')} | Padrino Admin" %></title>
|
|
@@ -31,12 +27,6 @@
|
|
|
31
27
|
<div class="col-lg-10"><%%= password_field_tag :password, id: :password, class: 'form-control' %></div>
|
|
32
28
|
</div>
|
|
33
29
|
|
|
34
|
-
<fieldset class="login-control-group-last control-group">
|
|
35
|
-
<div class="login-controls controls">
|
|
36
|
-
<label class="login-bypass-label checkbox"><%%= check_box_tag :bypass %> <%%= pat('login.bypass') %></label>
|
|
37
|
-
</div>
|
|
38
|
-
</fieldset>
|
|
39
|
-
|
|
40
30
|
</div>
|
|
41
31
|
<div class="login-footer modal-footer"><%%= submit_tag(pat('login.sign_in'), class: 'btn btn-primary pull-right') %></div>
|
|
42
32
|
<%% end %>
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
<%- @orm.columns.each_with_index do |column, i| -%>
|
|
53
53
|
<%- if column.name == "created_at" || column.name == "updated_at" -%>
|
|
54
54
|
<td class=list-column> <%%= time_ago_in_words <%= @orm.name_singular %>.<%= column.name %> %></td>
|
|
55
|
-
<%- elsif column.type == :
|
|
56
|
-
<td class=list-column> <%%= <%= @orm.name_singular %>.<%= column.name %> ?
|
|
55
|
+
<%- elsif @orm.field_type(column.type) == :check_box -%>
|
|
56
|
+
<td class=list-column> <%%= tag_icon(<%= @orm.name_singular %>.<%= column.name %> ? :check : :times) + content_tag(:span, <%= @orm.name_singular %>.<%= column.name %>.to_s, class: 'sr-only') unless <%= @orm.name_singular %>.<%= column.name %>.nil? %> </td>
|
|
57
57
|
<%- else -%>
|
|
58
58
|
<td class=list-column> <%%= <%= @orm.name_singular %>.<%= column.name %> %> </td>
|
|
59
59
|
<%- end -%>
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
!!! 5
|
|
2
2
|
%html{lang: 'en'}
|
|
3
3
|
%head
|
|
4
|
-
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
|
|
5
|
-
<!--[if lt IE 9]>
|
|
6
|
-
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
|
7
|
-
<![endif]-->
|
|
8
4
|
%meta{content: 'text/html; charset=utf-8', 'http-equiv' => 'Content-Type'}
|
|
9
5
|
%meta{name: :viewport, content: 'width=device-width,initial-scale=1'}
|
|
10
6
|
%title= @title.present? ? "#{@title} | Padrino Admin" : 'Padrino Admin'
|
|
11
7
|
=favicon_tag 'favicon.ico'
|
|
12
|
-
%link{href: 'http://fonts.googleapis.com/css?family=Varela', rel: :stylesheet}
|
|
13
8
|
=stylesheet_link_tag 'bootstrap', 'application'
|
|
14
9
|
|
|
15
10
|
%body
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
!!! 5
|
|
2
2
|
%html{lang: 'en'}
|
|
3
3
|
%head
|
|
4
|
-
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
|
|
5
|
-
<!--[if lt IE 9]>
|
|
6
|
-
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
|
7
|
-
<![endif]-->
|
|
8
4
|
%meta{content: 'text/html; charset=utf-8', 'http-equiv' => 'Content-Type'}
|
|
9
5
|
%meta{name: :viewport, content: 'width=device-width,initial-scale=1'}
|
|
10
6
|
%title= @title.present? ? "#{@title} | Padrino Admin" : "#{pat(:custom_errors.title)} | Padrino Admin"
|
|
11
7
|
=favicon_tag 'favicon.ico'
|
|
12
|
-
%link{href: 'http://fonts.googleapis.com/css?family=Varela', rel: :stylesheet}
|
|
13
8
|
=stylesheet_link_tag 'bootstrap', 'application'
|
|
14
9
|
|
|
15
10
|
%body
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
!!! 5
|
|
2
2
|
%html{lang: 'en'}
|
|
3
3
|
%head
|
|
4
|
-
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
|
|
5
|
-
<!--[if lt IE 9]>
|
|
6
|
-
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
|
7
|
-
<![endif]-->
|
|
8
4
|
%meta{content: 'text/html; charset=utf-8', 'http-equiv' => 'Content-Type'}
|
|
9
5
|
%meta{name: :viewport, content: 'width=device-width,initial-scale=1'}
|
|
10
6
|
%title= @title.present? ? "#{@title} | Padrino Admin" : "#{pat('login.title')} | Padrino Admin"
|
|
@@ -26,12 +22,6 @@
|
|
|
26
22
|
%label.col-lg-2.control-label{for: :password}= pat('login.password')
|
|
27
23
|
.col-lg-10= password_field_tag :password, id: :password, class:'form-control'
|
|
28
24
|
|
|
29
|
-
%fieldset.login-control-group-last.control-group
|
|
30
|
-
.login-controls.controls
|
|
31
|
-
%label.login-bypass-label.checkbox
|
|
32
|
-
= check_box_tag :bypass
|
|
33
|
-
= pat('login.bypass')
|
|
34
|
-
|
|
35
25
|
.login-footer.modal-footer
|
|
36
26
|
= submit_tag(pat('login.sign_in'), class: 'btn btn-primary pull-right')
|
|
37
27
|
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
<%- @orm.columns.each_with_index do |column, i| -%>
|
|
40
40
|
<%- if column.name == "created_at" || column.name == "updated_at" -%>
|
|
41
41
|
%td.list-column=time_ago_in_words <%= @orm.name_singular %>.<%= column.name %>
|
|
42
|
-
<%- elsif column.type == :
|
|
43
|
-
%td.list-column= <%= @orm.name_singular %>.<%= column.name %> ?
|
|
42
|
+
<%- elsif @orm.field_type(column.type) == :check_box -%>
|
|
43
|
+
%td.list-column= tag_icon(<%= @orm.name_singular %>.<%= column.name %> ? :check : :times) + content_tag(:span, <%= @orm.name_singular %>.<%= column.name %>.to_s, class: 'sr-only') unless <%= @orm.name_singular %>.<%= column.name %>.nil?
|
|
44
44
|
<%- else -%>
|
|
45
45
|
%td.list-column=<%= @orm.name_singular %>.<%= column.name %>
|
|
46
46
|
<%- end -%>
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
if @<%= @orm.name_singular %>
|
|
31
31
|
render '<%= @orm.name_plural %>/edit'
|
|
32
32
|
else
|
|
33
|
-
flash[:warning] = pat(:create_error, model: '<%= @orm.name_singular %>', id: params[:id])
|
|
34
33
|
halt 404
|
|
35
34
|
end
|
|
36
35
|
end
|
|
@@ -49,7 +48,6 @@
|
|
|
49
48
|
render '<%= @orm.name_plural %>/edit'
|
|
50
49
|
end
|
|
51
50
|
else
|
|
52
|
-
flash[:warning] = pat(:update_warning, model: '<%= @orm.name_singular %>', id: params[:id])
|
|
53
51
|
halt 404
|
|
54
52
|
end
|
|
55
53
|
end
|
|
@@ -65,7 +63,6 @@
|
|
|
65
63
|
end
|
|
66
64
|
redirect url(:<%= @orm.name_plural %>, :index)
|
|
67
65
|
else
|
|
68
|
-
flash[:warning] = pat(:delete_warning, model: '<%= @orm.name_singular %>', id: params[:id])
|
|
69
66
|
halt 404
|
|
70
67
|
end
|
|
71
68
|
end
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
doctype 5
|
|
2
2
|
html lang='en'
|
|
3
3
|
head
|
|
4
|
-
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
|
|
5
|
-
<!--[if lt IE 9]>
|
|
6
|
-
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
|
7
|
-
<![endif]-->
|
|
8
4
|
meta content='text/html; charset=utf-8' http-equiv='Content-Type'
|
|
9
5
|
meta name='viewport' content='width=device-width,initial-scale=1'
|
|
10
6
|
title = @title.present? ? "#{@title} | Padrino Admin" : "Padrino Admin"
|
|
11
7
|
= favicon_tag 'favicon.ico'
|
|
12
|
-
link href='http://fonts.googleapis.com/css?family=Varela' rel='stylesheet'
|
|
13
8
|
= stylesheet_link_tag 'bootstrap', 'application'
|
|
14
9
|
|
|
15
10
|
body
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
doctype 5
|
|
2
2
|
html lang="en" xmlns="http://www.w3.org/1999/xhtml"
|
|
3
3
|
head
|
|
4
|
-
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
|
|
5
|
-
<!--[if lt IE 9]>
|
|
6
|
-
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
|
7
|
-
<![endif]-->
|
|
8
4
|
meta content='text/html; charset=utf-8' http-equiv='Content-Type'
|
|
9
5
|
meta name='viewport' content='width=device-width,initial-scale=1'
|
|
10
6
|
title = @title.present? ? "#{@title} | Padrino Admin" : "#{pat(:custom_errors.title)} | Padrino Admin"
|
|
11
7
|
= favicon_tag 'favicon.ico'
|
|
12
|
-
link href='http://fonts.googleapis.com/css?family=Varela' rel='stylesheet'
|
|
13
8
|
= stylesheet_link_tag 'bootstrap', 'application'
|
|
14
9
|
|
|
15
10
|
body
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
doctype 5
|
|
2
2
|
html lang="en" xmlns="http://www.w3.org/1999/xhtml"
|
|
3
3
|
head
|
|
4
|
-
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
|
|
5
|
-
<!--[if lt IE 9]>
|
|
6
|
-
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
|
7
|
-
<![endif]-->
|
|
8
4
|
meta content='text/html; charset=utf-8' http-equiv='Content-Type'
|
|
9
5
|
meta name='viewport' content='width=device-width,initial-scale=1'
|
|
10
6
|
title = @title.present? ? "#{@title} | Padrino Admin" : "#{pat('login.title')} | Padrino Admin"
|
|
@@ -26,12 +22,6 @@ html lang="en" xmlns="http://www.w3.org/1999/xhtml"
|
|
|
26
22
|
label for="password" class='col-lg-2 control-label' = pat('login.password')
|
|
27
23
|
div class='col-lg-10' = password_field_tag :password, id: :password, class: 'form-control'
|
|
28
24
|
|
|
29
|
-
fieldset class='login-control-group-last control-group'
|
|
30
|
-
div class='login-controls controls'
|
|
31
|
-
label class="login-bypass-label checkbox"
|
|
32
|
-
= check_box_tag :bypass
|
|
33
|
-
| #{pat('login.bypass')}
|
|
34
|
-
|
|
35
25
|
div class="login-footer modal-footer"
|
|
36
26
|
= submit_tag(pat('login.sign_in'), class: 'btn btn-primary pull-right')
|
|
37
27
|
= javascript_include_tag 'jquery-3.7.1.min', (Padrino.env == :production ? 'bootstrap/bootstrap.min' : %w[bootstrap/affix bootstrap/alert bootstrap/button bootstrap/carousel bootstrap/collapse bootstrap/dropdown bootstrap/tooltip bootstrap/transition bootstrap/modal bootstrap/popover bootstrap/scrollspy bootstrap/tab]), :application
|
|
@@ -37,8 +37,8 @@ div class="tabs-content"
|
|
|
37
37
|
<%- @orm.columns.each_with_index do |column, i| -%>
|
|
38
38
|
<%- if column.name == 'created_at' || column.name == 'updated_at' -%>
|
|
39
39
|
td class='list-column' = time_ago_in_words <%= @orm.name_singular %>.<%= column.name %>
|
|
40
|
-
<%- elsif column.type == :
|
|
41
|
-
td class='list-column' = <%= @orm.name_singular %>.<%= column.name %> ?
|
|
40
|
+
<%- elsif @orm.field_type(column.type) == :check_box -%>
|
|
41
|
+
td class='list-column' = tag_icon(<%= @orm.name_singular %>.<%= column.name %> ? :check : :times) + content_tag(:span, <%= @orm.name_singular %>.<%= column.name %>.to_s, class: 'sr-only') unless <%= @orm.name_singular %>.<%= column.name %>.nil?
|
|
42
42
|
<%- else -%>
|
|
43
43
|
td class='list-column' = <%= @orm.name_singular %>.<%= column.name %>
|
|
44
44
|
<%- end -%>
|
|
@@ -99,7 +99,9 @@ module Padrino
|
|
|
99
99
|
|
|
100
100
|
def admin_model_obj
|
|
101
101
|
@_admin_model_obj ||= Padrino::Inflections.constantize(settings.admin_model)
|
|
102
|
-
rescue NameError
|
|
102
|
+
rescue NameError => e
|
|
103
|
+
raise unless Padrino::Admin.missing_constant?(e, settings.admin_model)
|
|
104
|
+
|
|
103
105
|
raise Padrino::Admin::AccessControlError, "You must define an #{settings.admin_model} Model"
|
|
104
106
|
end
|
|
105
107
|
end
|
data/lib/padrino-admin.rb
CHANGED
|
@@ -20,6 +20,26 @@ module Padrino
|
|
|
20
20
|
I18n.load_path += Dir["#{__dir__}/padrino-admin/locale/**/*.yml"]
|
|
21
21
|
end
|
|
22
22
|
alias included registered
|
|
23
|
+
|
|
24
|
+
##
|
|
25
|
+
# Whether +error+, raised looking up the constant +name+, says that constant (or one of its
|
|
26
|
+
# namespaces) is not defined, rather than coming from the code that defining it ran. The
|
|
27
|
+
# error must name a segment of +name+ and have been raised on that segment's parent, so a
|
|
28
|
+
# model whose body references another constant with the same short name isn't "missing".
|
|
29
|
+
#
|
|
30
|
+
def missing_constant?(error, name)
|
|
31
|
+
return false unless error.instance_of?(NameError)
|
|
32
|
+
|
|
33
|
+
segments = name.to_s.sub(/\A::/, '').split('::')
|
|
34
|
+
return false unless error.receiver.is_a?(::Module)
|
|
35
|
+
|
|
36
|
+
segments.each_index.any? do |index|
|
|
37
|
+
parent = index.zero? ? 'Object' : segments.first(index).join('::')
|
|
38
|
+
segments[index] == error.name.to_s && error.receiver.name == parent
|
|
39
|
+
end
|
|
40
|
+
rescue ArgumentError
|
|
41
|
+
false
|
|
42
|
+
end
|
|
23
43
|
end
|
|
24
44
|
end
|
|
25
45
|
end
|
|
@@ -29,7 +49,7 @@ end
|
|
|
29
49
|
#
|
|
30
50
|
begin
|
|
31
51
|
require 'padrino-gen'
|
|
32
|
-
Padrino::Generators.load_paths << Dir["#{__dir__}/padrino-admin/generators/{actions,orm,admin_app,admin_page}.rb"]
|
|
52
|
+
Padrino::Generators.load_paths << Dir["#{__dir__}/padrino-admin/generators/{actions,keep_files,orm,admin_app,admin_page}.rb"]
|
|
33
53
|
rescue LoadError
|
|
34
54
|
# do nothing if padrino-gen is not available
|
|
35
55
|
end
|
data/padrino-admin.gemspec
CHANGED
|
@@ -8,16 +8,21 @@ Gem::Specification.new do |s|
|
|
|
8
8
|
s.authors = ['Padrino Team', 'Nathan Esquenazi', "Davide D'Agostino", 'Arthur Chiu']
|
|
9
9
|
s.email = 'padrinorb@gmail.com'
|
|
10
10
|
s.summary = 'Admin Dashboard for Padrino'
|
|
11
|
-
s.homepage = '
|
|
11
|
+
s.homepage = 'https://padrinorb.com'
|
|
12
12
|
s.description = 'Admin View for Padrino applications'
|
|
13
|
+
s.required_ruby_version = '>= 2.7.8'
|
|
13
14
|
s.required_rubygems_version = '>= 1.3.6'
|
|
14
15
|
s.version = Padrino.version
|
|
15
|
-
s.date = Time.now.strftime('%Y-%m-%d')
|
|
16
16
|
s.license = 'MIT'
|
|
17
|
+
s.metadata = {
|
|
18
|
+
'bug_tracker_uri' => 'https://github.com/padrino/padrino-framework/issues',
|
|
19
|
+
'changelog_uri' => 'https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc',
|
|
20
|
+
'documentation_uri' => 'https://padrinorb.com/guides/',
|
|
21
|
+
'source_code_uri' => 'https://github.com/padrino/padrino-framework'
|
|
22
|
+
}
|
|
17
23
|
|
|
18
24
|
s.extra_rdoc_files = Dir['*.rdoc']
|
|
19
25
|
s.files = `git ls-files`.split("\n")
|
|
20
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
21
26
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
22
27
|
s.require_paths = ['lib']
|
|
23
28
|
s.rdoc_options = ['--charset=UTF-8']
|