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
|
@@ -16,12 +16,12 @@ html lang='en'
|
|
|
16
16
|
div class='navbar navbar-fixed-top'
|
|
17
17
|
div class='navbar-inner'
|
|
18
18
|
div class='container'
|
|
19
|
-
= link_to 'Padrino', url(:base, :index), :
|
|
19
|
+
= link_to 'Padrino', url(:base, :index), class: 'navbar-brand', title: 'Padrino Admin'
|
|
20
20
|
|
|
21
21
|
ul class='nav navbar-nav pull-right'
|
|
22
|
-
li class='navbar-edit-account' = link_to tag_icon(:user), url(:<%= @model_plural %>, :edit, :
|
|
22
|
+
li class='navbar-edit-account' = link_to tag_icon(:user), url(:<%= @model_plural %>, :edit, id: current_account.id), title: pat(:profile), class: 'navbar-nav-link'
|
|
23
23
|
li class='navbar-logout'
|
|
24
|
-
= button_to pat(:logout), url(:sessions, :destroy), :
|
|
24
|
+
= button_to pat(:logout), url(:sessions, :destroy), method: :delete, class: 'navbar-nav-form', submit_options: { type: :submit, title: pat(:logout), class: 'navbar-nav-form-link' } do
|
|
25
25
|
= tag_icon(:'power-off')
|
|
26
26
|
|
|
27
27
|
ul class='nav navbar-nav pull-left'
|
|
@@ -31,7 +31,7 @@ html lang='en'
|
|
|
31
31
|
|
|
32
32
|
div class='container main'
|
|
33
33
|
div class='main-wrapper'
|
|
34
|
-
=
|
|
34
|
+
= { error: 'danger', warning: 'warning', success: 'success', notice: 'info' }.map { |type, class_name| flash_tag(type, class: "alert alert-#{class_name} fade in", bootstrap: true) }.join.html_safe
|
|
35
35
|
div class='row' = yield
|
|
36
36
|
div class='main-wrapper-push'
|
|
37
37
|
|
|
@@ -41,9 +41,9 @@ html lang='en'
|
|
|
41
41
|
' Copyright © #{Time.now.year} Your Site -
|
|
42
42
|
b Powered by Padrino v.#{Padrino.version}
|
|
43
43
|
ul class='pull-right footer-links'
|
|
44
|
-
li = link_to tag_icon(:home, 'web'), 'http://www.padrinorb.com', :
|
|
45
|
-
li = link_to tag_icon(:heart, 'blog'), 'http://www.padrinorb.com/blog', :
|
|
46
|
-
li = link_to tag_icon(:github, 'code'), 'https://github.com/padrino/padrino-framework', :
|
|
47
|
-
li = link_to tag_icon(:twitter, 'twitter'), 'http://twitter.com/padrinorb', :
|
|
44
|
+
li = link_to tag_icon(:home, 'web'), 'http://www.padrinorb.com', target: :_blank, class: 'footer-links-link'
|
|
45
|
+
li = link_to tag_icon(:heart, 'blog'), 'http://www.padrinorb.com/blog', target: :_blank, class: 'footer-links-link'
|
|
46
|
+
li = link_to tag_icon(:github, 'code'), 'https://github.com/padrino/padrino-framework', target: :_blank, class: 'footer-links-link'
|
|
47
|
+
li = link_to tag_icon(:twitter, 'twitter'), 'http://twitter.com/padrinorb', target: :_blank, class: 'footer-links-link'
|
|
48
48
|
|
|
49
|
-
=javascript_include_tag 'jquery-1.11.0.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
|
|
49
|
+
= javascript_include_tag 'jquery-1.11.0.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
|
|
@@ -16,4 +16,4 @@ html lang="en" xmlns="http://www.w3.org/1999/xhtml"
|
|
|
16
16
|
div class="custom-error text-center"
|
|
17
17
|
div class="custom-error-body muted" = yield
|
|
18
18
|
div class="custom-error-footer"
|
|
19
|
-
= link_to tag_icon('arrow-left'),
|
|
19
|
+
= link_to tag_icon('arrow-left'), '#', onclick: 'history.go(-1); return false;', class: 'custom-error-go-back btn btn-default pull-left', title: 'Go Back'
|
|
@@ -12,19 +12,19 @@ html lang="en" xmlns="http://www.w3.org/1999/xhtml"
|
|
|
12
12
|
= stylesheet_link_tag 'bootstrap', 'application'
|
|
13
13
|
|
|
14
14
|
body
|
|
15
|
-
= form_tag url(:sessions, :create), :
|
|
15
|
+
= form_tag url(:sessions, :create), class: 'login form-horizontal' do
|
|
16
16
|
div class="login-header modal-header"
|
|
17
|
-
div class="login-logo" = image_tag('logo.png', :
|
|
17
|
+
div class="login-logo" = image_tag('logo.png', alt: "Padrino's logo", height: 250, width: 193)
|
|
18
18
|
div class="login-body modal-body"
|
|
19
|
-
= {:
|
|
19
|
+
= { error: 'danger', warning: 'warning', success: 'success', notice: 'info' }.map { |type, class_name| flash_tag(type, class: "alert alert-#{class_name} fade in", bootstrap: true) }.join.html_safe
|
|
20
20
|
|
|
21
21
|
div class='form-group'
|
|
22
22
|
label for="email" class='col-lg-2 control-label' = pat('login.email')
|
|
23
|
-
div class='col-lg-10'
|
|
23
|
+
div class='col-lg-10' = email_field_tag :email, id: :email, value: params[:email], autofocus: true, class: 'form-control'
|
|
24
24
|
|
|
25
25
|
div class='form-group'
|
|
26
26
|
label for="password" class='col-lg-2 control-label' = pat('login.password')
|
|
27
|
-
div class='col-lg-10' = password_field_tag :password, :
|
|
27
|
+
div class='col-lg-10' = password_field_tag :password, id: :password, class: 'form-control'
|
|
28
28
|
|
|
29
29
|
fieldset class='login-control-group-last control-group'
|
|
30
30
|
div class='login-controls controls'
|
|
@@ -33,5 +33,5 @@ html lang="en" xmlns="http://www.w3.org/1999/xhtml"
|
|
|
33
33
|
| #{pat('login.bypass')}
|
|
34
34
|
|
|
35
35
|
div class="login-footer modal-footer"
|
|
36
|
-
= submit_tag(pat('login.sign_in'), :
|
|
36
|
+
= submit_tag(pat('login.sign_in'), class: 'btn btn-primary pull-right')
|
|
37
37
|
= javascript_include_tag 'jquery-1.11.0.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
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
<%- @orm.column_fields.each_with_index do |column, index| -%>
|
|
2
2
|
- error = <%= @orm.has_error(column[:name]) %>
|
|
3
3
|
fieldset class='control-group#{error ? ' has-error' : ''}'
|
|
4
|
-
= f.label :<%= column[:name] %>, :
|
|
4
|
+
= f.label :<%= column[:name] %>, class: 'control-label'
|
|
5
5
|
div class='controls'
|
|
6
|
-
= f.<%= column[:field_type] %> :<%= column[:name] %>, :
|
|
6
|
+
= f.<%= column[:field_type] %> :<%= column[:name] %>, class: 'form-control input-large input-with-feedback'<%- if (index == 0) -%>, autofocus: true<%- end -%>
|
|
7
7
|
|
|
8
|
-
span class='help-inline' = error ? f.error_message_on(:<%= column[:name] %>, :
|
|
8
|
+
span class='help-inline' = error ? f.error_message_on(:<%= column[:name] %>, class: 'text-error') : pat(:example)
|
|
9
9
|
<%- end -%>
|
|
10
10
|
|
|
11
11
|
div class="form-actions"
|
|
12
|
-
= f.submit pat(:save), :
|
|
12
|
+
= f.submit pat(:save), class: 'btn btn-primary'
|
|
13
13
|
|
|
|
14
|
-
= f.submit pat(:save_and_continue), :
|
|
14
|
+
= f.submit pat(:save_and_continue), class: 'btn btn-info', name: 'save_and_continue'
|
|
15
15
|
|
|
|
16
|
-
= link_to pat(:cancel), url(:<%= @orm.name_plural %>, :index), :
|
|
16
|
+
= link_to pat(:cancel), url(:<%= @orm.name_plural %>, :index), class: 'btn btn-default'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
ul class="nav nav-tabs"
|
|
2
2
|
li = link_to tag_icon(:list, pat(:list)), url(:<%= @orm.name_plural %>, :index)
|
|
3
3
|
li = link_to tag_icon(:plus, pat(:new)), url(:<%= @orm.name_plural %>, :new)
|
|
4
|
-
li class="active" = link_to tag_icon(:edit, pat(:edit)), url(:<%= @orm.name_plural %>, :edit, :
|
|
4
|
+
li class="active" = link_to tag_icon(:edit, pat(:edit)), url(:<%= @orm.name_plural %>, :edit, id: @<%= @orm.name_singular %>.id)
|
|
5
5
|
|
|
6
6
|
div class="tabs-content"
|
|
7
|
-
= form_for :<%= @orm.name_singular %>, url(:<%= @orm.name_plural %>, :update, :
|
|
8
|
-
= partial '<%= @orm.name_plural %>/form', :
|
|
7
|
+
= form_for :<%= @orm.name_singular %>, url(:<%= @orm.name_plural %>, :update, id: @<%= @orm.name_singular %>.id), method: :put, class: 'form-horizontal' do |f|
|
|
8
|
+
= partial '<%= @orm.name_plural %>/form', locals: { f: f }
|
|
@@ -12,18 +12,18 @@ div class="tabs-content"
|
|
|
12
12
|
= tag_icon :magic
|
|
13
13
|
span class='caret'
|
|
14
14
|
ul class='list-menu dropdown-menu' role='dropdown'
|
|
15
|
-
li class='list-menu-wrapper' = link_to tag_icon('check-square-o', pat(:select_all)), '#', :
|
|
16
|
-
li class='list-menu-wrapper list-menu-wrapper-disabled' = link_to tag_icon('square-o', pat(:deselect_all)), '#', :
|
|
15
|
+
li class='list-menu-wrapper' = link_to tag_icon('check-square-o', pat(:select_all)), '#', id: 'select-all', class: 'list-menu-link'
|
|
16
|
+
li class='list-menu-wrapper list-menu-wrapper-disabled' = link_to tag_icon('square-o', pat(:deselect_all)), '#', id: 'deselect-all', class: 'list-menu-link list-menu-link-disabled'
|
|
17
17
|
li class='list-menu-divider divider'
|
|
18
18
|
li class='list-menu-wrapper list-menu-wrapper-disabled'
|
|
19
|
-
= link_to tag_icon('trash-o', pat(:delete_selected)), '#', :
|
|
19
|
+
= link_to tag_icon('trash-o', pat(:delete_selected)), '#', id: 'delete-selected', class: 'list-menu-link list-menu-link-disabled'
|
|
20
20
|
div class='list-menu-popover-delete-selected popover right'
|
|
21
21
|
div class='arrow'
|
|
22
22
|
h3 class='popover-title' = pat(:delete_selected_title)
|
|
23
23
|
div class='popover-content'
|
|
24
|
-
= form_tag url(:<%= @orm.name_plural %>, :destroy_many), :
|
|
25
|
-
= hidden_field_tag :<%= @orm.name_singular %>_ids,
|
|
26
|
-
= submit_tag pat(:delete), :
|
|
24
|
+
= form_tag url(:<%= @orm.name_plural %>, :destroy_many), method: :delete do
|
|
25
|
+
= hidden_field_tag :<%= @orm.name_singular %>_ids, 'data-delete-many-ids' => true
|
|
26
|
+
= submit_tag pat(:delete), class: 'list-menu-popover-delete-selected-btn btn btn-danger btn-small'
|
|
27
27
|
div class='btn btn-default btn-small cancel' = pat(:cancel)
|
|
28
28
|
<%- @orm.columns.each_with_index do |column, i| -%>
|
|
29
29
|
th class='header' = mat(:<%= @orm.name_singular %>, :<%= column.name %>)
|
|
@@ -33,7 +33,7 @@ div class="tabs-content"
|
|
|
33
33
|
tbody
|
|
34
34
|
-@<%= @orm.name_plural %>.each do |<%= @orm.name_singular %>|
|
|
35
35
|
tr class='list-row'
|
|
36
|
-
td class='list-column list-selectable' = check_box_tag '<%= @orm.name_singular %>_ids[]', :
|
|
36
|
+
td class='list-column list-selectable' = check_box_tag '<%= @orm.name_singular %>_ids[]', value: <%= @orm.name_singular %>.id, class: 'list-selectable-checkbox'
|
|
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 %>
|
|
@@ -45,12 +45,12 @@ div class="tabs-content"
|
|
|
45
45
|
<%- end -%>
|
|
46
46
|
td class='list-column list-row-action'
|
|
47
47
|
div class='list-row-action-wrapper'
|
|
48
|
-
= link_to tag_icon(:edit),
|
|
49
|
-
= link_to tag_icon('trash-o'), :
|
|
48
|
+
= link_to tag_icon(:edit), url(:<%= @orm.name_plural %>, :edit, id: <%= @orm.name_singular %>.id), rel: :tooltip, title: "#{pat(:edit)} <%= @orm.name_singular %>", class: 'list-row-action-wrapper-link'
|
|
49
|
+
= link_to tag_icon('trash-o'), rel: :tooltip, title: "#{pat(:delete)} <%= @orm.name_singular %>", class: 'list-row-action-delete-one list-row-action-wrapper-link'
|
|
50
50
|
div class='popover list-row-action-popover-delete-one left'
|
|
51
51
|
div class='arrow'
|
|
52
|
-
h3 class='popover-title' = pat(:delete, :
|
|
52
|
+
h3 class='popover-title' = pat(:delete, model: "<%= @orm.name_singular %>")
|
|
53
53
|
div class='popover-content'
|
|
54
|
-
= form_tag url(:<%= @orm.name_plural %>, :destroy, :
|
|
55
|
-
= submit_tag pat(:delete), :
|
|
54
|
+
= form_tag url(:<%= @orm.name_plural %>, :destroy, id: <%= @orm.name_singular %>.id), method: :delete do
|
|
55
|
+
= submit_tag pat(:delete), class: 'list-row-action-popover-delete-one-btn btn btn-danger btn-small'
|
|
56
56
|
div class='btn btn-default btn-small cancel' = pat(:cancel)
|
|
@@ -3,5 +3,5 @@ ul class="nav nav-tabs"
|
|
|
3
3
|
li class="active" = link_to tag_icon(:plus, pat(:new)), url(:<%= @orm.name_plural %>, :new)
|
|
4
4
|
|
|
5
5
|
div class="tabs-content"
|
|
6
|
-
= form_for :<%= @orm.name_singular %>, url(:<%= @orm.name_plural %>, :create), :
|
|
7
|
-
= partial '<%= @orm.name_plural %>/form', :
|
|
6
|
+
= form_for :<%= @orm.name_singular %>, url(:<%= @orm.name_plural %>, :create), class: 'form-horizontal' do |f|
|
|
7
|
+
= partial '<%= @orm.name_plural %>/form', locals: { f: f }
|
|
@@ -25,8 +25,8 @@ module Padrino
|
|
|
25
25
|
# @example
|
|
26
26
|
# set_current_account(Account.authenticate(params[:email], params[:password])
|
|
27
27
|
#
|
|
28
|
-
def set_current_account(account=nil)
|
|
29
|
-
session[settings.session_id] = account
|
|
28
|
+
def set_current_account(account = nil)
|
|
29
|
+
session[settings.session_id] = account&.id
|
|
30
30
|
@current_account = account
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -53,10 +53,10 @@ module Padrino
|
|
|
53
53
|
# By default this method is used in Admin Apps.
|
|
54
54
|
#
|
|
55
55
|
def login_required
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
return if allowed?
|
|
57
|
+
|
|
58
|
+
store_location! if store_location
|
|
59
|
+
access_denied
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
##
|
|
@@ -94,7 +94,7 @@ module Padrino
|
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
def login_from_session
|
|
97
|
-
admin_model_obj
|
|
97
|
+
admin_model_obj&.find_by_id(session[settings.session_id])
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
def admin_model_obj
|
|
@@ -17,7 +17,7 @@ module Padrino
|
|
|
17
17
|
# tag_icon(:edit, :list)
|
|
18
18
|
#
|
|
19
19
|
def tag_icon(icon, tag = nil)
|
|
20
|
-
content = content_tag(:i, '', :
|
|
20
|
+
content = content_tag(:i, '', class: "fa fa-#{icon}")
|
|
21
21
|
content << " #{tag}"
|
|
22
22
|
end
|
|
23
23
|
|
|
@@ -32,10 +32,10 @@ module Padrino
|
|
|
32
32
|
# @return [String] The translated word for the current locale.
|
|
33
33
|
#
|
|
34
34
|
# @example
|
|
35
|
-
# # => t(
|
|
35
|
+
# # => t('padrino.admin.profile', default: 'Profile')
|
|
36
36
|
# pat(:profile)
|
|
37
37
|
#
|
|
38
|
-
# # => t(
|
|
38
|
+
# # => t('padrino.admin.profile', default: 'My Profile')
|
|
39
39
|
# pat(:profile, "My Profile")
|
|
40
40
|
#
|
|
41
41
|
def padrino_admin_translate(word, *args)
|
|
@@ -43,7 +43,7 @@ module Padrino
|
|
|
43
43
|
options[:default] ||= word.to_s.humanize
|
|
44
44
|
t("padrino.admin.#{word}", options)
|
|
45
45
|
end
|
|
46
|
-
alias
|
|
46
|
+
alias pat padrino_admin_translate
|
|
47
47
|
|
|
48
48
|
##
|
|
49
49
|
# Translates attribute name for the given model.
|
|
@@ -56,14 +56,14 @@ module Padrino
|
|
|
56
56
|
# @return [String] The translated attribute name for the current locale.
|
|
57
57
|
#
|
|
58
58
|
# @example
|
|
59
|
-
# # => t(
|
|
59
|
+
# # => t('models.account.attributes.email', default: 'Email')
|
|
60
60
|
# mat(:account, :email)
|
|
61
61
|
#
|
|
62
62
|
def model_attribute_translate(model, attribute)
|
|
63
|
-
t("models.#{model}.attributes.#{attribute}", :
|
|
63
|
+
t("models.#{model}.attributes.#{attribute}", default: attribute.to_s.humanize)
|
|
64
64
|
end
|
|
65
|
-
alias
|
|
66
|
-
alias
|
|
65
|
+
alias t_attr model_attribute_translate
|
|
66
|
+
alias mat t_attr
|
|
67
67
|
|
|
68
68
|
##
|
|
69
69
|
# Translates model name.
|
|
@@ -74,13 +74,13 @@ module Padrino
|
|
|
74
74
|
# @return [String] The translated model name for the current locale.
|
|
75
75
|
#
|
|
76
76
|
# @example
|
|
77
|
-
# # => t(
|
|
77
|
+
# # => t('models.account.name', default: 'Account')
|
|
78
78
|
# mt(:account)
|
|
79
79
|
#
|
|
80
80
|
def model_translate(model)
|
|
81
|
-
t("models.#{model}.name", :
|
|
81
|
+
t("models.#{model}.name", default: model.to_s.humanize)
|
|
82
82
|
end
|
|
83
|
-
alias
|
|
83
|
+
alias mt model_translate
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
86
|
end
|
data/lib/padrino-admin.rb
CHANGED
|
@@ -17,9 +17,9 @@ module Padrino
|
|
|
17
17
|
class << self
|
|
18
18
|
def registered(app)
|
|
19
19
|
# Load Padrino::Admin locales
|
|
20
|
-
I18n.load_path += Dir["#{
|
|
20
|
+
I18n.load_path += Dir["#{__dir__}/padrino-admin/locale/**/*.yml"]
|
|
21
21
|
end
|
|
22
|
-
alias
|
|
22
|
+
alias included registered
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
end
|
|
@@ -29,6 +29,7 @@ end
|
|
|
29
29
|
#
|
|
30
30
|
begin
|
|
31
31
|
require 'padrino-gen'
|
|
32
|
-
Padrino::Generators.load_paths << Dir[
|
|
32
|
+
Padrino::Generators.load_paths << Dir["#{__dir__}/padrino-admin/generators/{actions,orm,admin_app,admin_page}.rb"]
|
|
33
33
|
rescue LoadError
|
|
34
|
+
# do nothing if padrino-gen is not available
|
|
34
35
|
end
|
data/padrino-admin.gemspec
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env gem build
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
|
-
require File.expand_path(
|
|
4
|
+
require File.expand_path('../padrino-core/lib/padrino-core/version.rb', __dir__)
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name =
|
|
8
|
-
s.authors = [
|
|
9
|
-
s.email =
|
|
10
|
-
s.summary =
|
|
11
|
-
s.homepage =
|
|
12
|
-
s.description =
|
|
13
|
-
s.required_rubygems_version =
|
|
7
|
+
s.name = 'padrino-admin'
|
|
8
|
+
s.authors = ['Padrino Team', 'Nathan Esquenazi', "Davide D'Agostino", 'Arthur Chiu']
|
|
9
|
+
s.email = 'padrinorb@gmail.com'
|
|
10
|
+
s.summary = 'Admin Dashboard for Padrino'
|
|
11
|
+
s.homepage = 'http://www.padrinorb.com'
|
|
12
|
+
s.description = 'Admin View for Padrino applications'
|
|
13
|
+
s.required_rubygems_version = '>= 1.3.6'
|
|
14
14
|
s.version = Padrino.version
|
|
15
|
-
s.date = Time.now.strftime(
|
|
16
|
-
s.license =
|
|
15
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
|
16
|
+
s.license = 'MIT'
|
|
17
17
|
|
|
18
|
-
s.extra_rdoc_files = Dir[
|
|
18
|
+
s.extra_rdoc_files = Dir['*.rdoc']
|
|
19
19
|
s.files = `git ls-files`.split("\n")
|
|
20
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
21
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
22
|
-
s.require_paths = [
|
|
23
|
-
s.rdoc_options = [
|
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
22
|
+
s.require_paths = ['lib']
|
|
23
|
+
s.rdoc_options = ['--charset=UTF-8']
|
|
24
24
|
|
|
25
|
-
s.add_dependency(
|
|
26
|
-
s.add_dependency(
|
|
27
|
-
s.add_development_dependency(
|
|
28
|
-
s.add_development_dependency(
|
|
25
|
+
s.add_dependency('padrino-core', Padrino.version)
|
|
26
|
+
s.add_dependency('padrino-helpers', Padrino.version)
|
|
27
|
+
s.add_development_dependency('therubyracer', '~> 0.11.1')
|
|
28
|
+
s.add_development_dependency('less', '~> 2.2.2')
|
|
29
29
|
end
|
data/test/fixtures/sequel.rb
CHANGED
|
@@ -2,13 +2,13 @@ require 'digest/sha1'
|
|
|
2
2
|
require 'sequel'
|
|
3
3
|
require 'sequel/extensions/migration'
|
|
4
4
|
|
|
5
|
-
Sequel::Model.db =
|
|
5
|
+
Sequel::Model.db =
|
|
6
6
|
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
|
7
|
-
require 'jdbc/sqlite3'
|
|
8
|
-
Sequel.connect(
|
|
7
|
+
require 'jdbc/sqlite3'
|
|
8
|
+
Sequel.connect('jdbc:sqlite::memory:')
|
|
9
9
|
else
|
|
10
10
|
require 'sqlite3'
|
|
11
|
-
Sequel.sqlite(
|
|
11
|
+
Sequel.sqlite(':memory:')
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
migration = Sequel.migration do
|
|
@@ -66,8 +66,8 @@ class Account < Sequel::Model
|
|
|
66
66
|
|
|
67
67
|
one_to_many :sections
|
|
68
68
|
|
|
69
|
-
def self.admin; first(:
|
|
70
|
-
def self.editor; first(:
|
|
69
|
+
def self.admin; first(role: 'admin'); end
|
|
70
|
+
def self.editor; first(role: 'editor'); end
|
|
71
71
|
|
|
72
72
|
##
|
|
73
73
|
# Replace ActiveRecord method.
|
|
@@ -78,12 +78,12 @@ class Account < Sequel::Model
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
# We build some fake accounts
|
|
81
|
-
admin = Account.create(:
|
|
82
|
-
:
|
|
83
|
-
editor = Account.create(:
|
|
84
|
-
:
|
|
85
|
-
|
|
86
|
-
%w
|
|
87
|
-
admin.add_section(:
|
|
88
|
-
editor.add_section(:
|
|
81
|
+
admin = Account.create(name: 'DAddYE', role: 'admin', email: 'd.dagostino@lipsiasoft.com',
|
|
82
|
+
password: 'some', password_confirmation: 'some')
|
|
83
|
+
editor = Account.create(name: 'Dexter', role: 'editor', email: 'editor@lipsiasoft.com',
|
|
84
|
+
password: 'some', password_confirmation: 'some')
|
|
85
|
+
|
|
86
|
+
%w[News Press HowTo].each do |c|
|
|
87
|
+
admin.add_section(name: c)
|
|
88
|
+
editor.add_section(name: c)
|
|
89
89
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative '../helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe 'AccountModelGenerator' do
|
|
4
4
|
before do
|
|
5
5
|
@apptmp = "#{Dir.tmpdir}/padrino-tests/#{SecureRandom.hex}"
|
|
6
|
-
|
|
6
|
+
`mkdir -p #{@apptmp}`
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
after do
|
|
10
|
-
%
|
|
10
|
+
%(rm -rf #{@apptmp})
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
describe 'activerecord' do
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative '../helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe 'AdminAppGenerator' do
|
|
4
4
|
before do
|
|
5
5
|
@apptmp = "#{Dir.tmpdir}/padrino-tests/#{SecureRandom.hex}"
|
|
6
6
|
`mkdir -p #{@apptmp}`
|
|
@@ -18,7 +18,7 @@ describe "AdminAppGenerator" do
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it 'should fail outside app root' do
|
|
21
|
-
out,
|
|
21
|
+
out, = capture_io { generate(:admin_app, "-r=#{@apptmp}") }
|
|
22
22
|
assert_match(/not at the root/, out)
|
|
23
23
|
assert_no_file_exists("#{@apptmp}/admin")
|
|
24
24
|
end
|
|
@@ -28,12 +28,12 @@ describe "AdminAppGenerator" do
|
|
|
28
28
|
assert_raises(SystemExit) { @out, @err = capture_io { generate(:admin_app, "-r=#{@apptmp}/sample_project") } }
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
it
|
|
32
|
-
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=datamapper','-e=haml') }
|
|
31
|
+
it 'should store and apply session_secret' do
|
|
32
|
+
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=datamapper', '-e=haml') }
|
|
33
33
|
assert_match_in_file(/set :session_secret, '[0-9A-z]*'/, "#{@apptmp}/sample_project/config/apps.rb")
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
it
|
|
36
|
+
it 'should generate the admin app' do
|
|
37
37
|
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=activerecord') }
|
|
38
38
|
capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
|
|
39
39
|
assert_dir_exists("#{@apptmp}/sample_project")
|
|
@@ -53,20 +53,20 @@ describe "AdminAppGenerator" do
|
|
|
53
53
|
assert_file_exists("#{@apptmp}/sample_project/models/account.rb")
|
|
54
54
|
assert_file_exists("#{@apptmp}/sample_project/db/seeds.rb")
|
|
55
55
|
assert_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_accounts.rb")
|
|
56
|
-
assert_match_in_file
|
|
56
|
+
assert_match_in_file %(Padrino.mount('SampleProject::Admin', app_file: Padrino.root('admin/app.rb')).to('/admin')), "#{@apptmp}/sample_project/config/apps.rb"
|
|
57
57
|
assert_match_in_file 'module SampleProject', "#{@apptmp}/sample_project/admin/app.rb"
|
|
58
58
|
assert_match_in_file 'class Admin < Padrino::Application', "#{@apptmp}/sample_project/admin/app.rb"
|
|
59
|
-
assert_match_in_file
|
|
59
|
+
assert_match_in_file "role.project_module :accounts, '/accounts'", "#{@apptmp}/sample_project/admin/app.rb"
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
it
|
|
62
|
+
it 'should generate the master app' do
|
|
63
63
|
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=activerecord') }
|
|
64
64
|
capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project", '--admin-name=master') }
|
|
65
65
|
assert_file_exists("#{@apptmp}/sample_project/master/app.rb")
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
# users can override certain templates from a generators/templates folder in the destination_root
|
|
69
|
-
it
|
|
69
|
+
it 'should use custom generator templates from the project root, if they exist' do
|
|
70
70
|
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=activerecord') }
|
|
71
71
|
custom_template_path = "#{@apptmp}/sample_project/generators/templates/slim/app/layouts/"
|
|
72
72
|
`mkdir -p #{custom_template_path} && echo "h1 = 'Hello, custom generator' " > #{custom_template_path}application.slim.tt`
|
|
@@ -74,12 +74,12 @@ describe "AdminAppGenerator" do
|
|
|
74
74
|
assert_match_in_file(/Hello, custom generator/, "#{@apptmp}/sample_project/admin/views/layouts/application.slim")
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
it
|
|
78
|
-
# TODO FIXME Implement option --admin_root or something. See https://github.com/padrino/padrino-framework/issues/854#issuecomment-14749356
|
|
77
|
+
it 'should generate the admin app under a different folder' do
|
|
78
|
+
# TODO: FIXME Implement option --admin_root or something. See https://github.com/padrino/padrino-framework/issues/854#issuecomment-14749356
|
|
79
79
|
skip
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
-
describe
|
|
82
|
+
describe 'renderers' do
|
|
83
83
|
it 'should correctly generate a new padrino admin application with haml renderer (default)' do
|
|
84
84
|
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=activerecord', '-e=haml') }
|
|
85
85
|
capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
|
|
@@ -143,11 +143,11 @@ describe "AdminAppGenerator" do
|
|
|
143
143
|
assert_match_in_file(/User/, "#{@apptmp}/sample_project/models/user.rb")
|
|
144
144
|
assert_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_users.rb")
|
|
145
145
|
assert_no_match_in_file(/[^_]account/i, "#{@apptmp}/sample_project/db/migrate/001_create_users.rb")
|
|
146
|
-
assert_match_in_file
|
|
146
|
+
assert_match_in_file "role.project_module :users, '/users'", "#{@apptmp}/sample_project/admin/app.rb"
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
it 'should correctly generate a new padrino admin application with model in non-default application path' do
|
|
150
|
-
# TODO FIXME What's the use case here? Clarify.
|
|
150
|
+
# TODO: FIXME What's the use case here? Clarify.
|
|
151
151
|
# Remember that --root/-r in the admin_app generator refers to the project's location, not the admin's location
|
|
152
152
|
# inside it. See https://github.com/padrino/padrino-framework/issues/854#issuecomment-14749356
|
|
153
153
|
skip
|
|
@@ -179,7 +179,7 @@ describe "AdminAppGenerator" do
|
|
|
179
179
|
# assert_match_in_file 'role.project_module :accounts, \'/accounts\'', "#{@apptmp}/sample_project/admin/app.rb"
|
|
180
180
|
end
|
|
181
181
|
|
|
182
|
-
describe
|
|
182
|
+
describe 'activerecord middleware' do
|
|
183
183
|
it 'should add it for #activerecord' do
|
|
184
184
|
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=activerecord', '-e=haml') }
|
|
185
185
|
capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
|
|
@@ -199,7 +199,7 @@ describe "AdminAppGenerator" do
|
|
|
199
199
|
end
|
|
200
200
|
end
|
|
201
201
|
|
|
202
|
-
describe
|
|
202
|
+
describe 'datamapper middleware' do
|
|
203
203
|
it 'should add it for #datamapper' do
|
|
204
204
|
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=datamapper', '-e=haml') }
|
|
205
205
|
capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
|
|
@@ -217,13 +217,13 @@ describe "AdminAppGenerator" do
|
|
|
217
217
|
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=activerecord', '-e=erb') }
|
|
218
218
|
|
|
219
219
|
# Add seeds file
|
|
220
|
-
FileUtils.mkdir_p @apptmp
|
|
221
|
-
File.open(@apptmp
|
|
222
|
-
seeds_rb.puts
|
|
220
|
+
FileUtils.mkdir_p "#{@apptmp}/sample_project/db" unless File.exist?("#{@apptmp}/sample_project/db")
|
|
221
|
+
File.open("#{@apptmp}/sample_project/db/seeds.rb", 'w+') do |seeds_rb|
|
|
222
|
+
seeds_rb.puts '# Old Seeds Content'
|
|
223
223
|
end
|
|
224
224
|
|
|
225
|
-
out,
|
|
226
|
-
refute_match
|
|
225
|
+
out, = capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
|
|
226
|
+
refute_match(%r{Overwrite\s.*?/db/seeds.rb}, out)
|
|
227
227
|
|
|
228
228
|
assert_file_exists "#{@apptmp}/sample_project/db/seeds.old"
|
|
229
229
|
assert_match_in_file 'Account.new(', "#{@apptmp}/sample_project/db/seeds.rb"
|