tb_core 1.4.3.1 → 1.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -54
  3. data/app/assets/javascripts/admin/core/application.js +8 -4
  4. data/app/assets/javascripts/admin/core/dashboard.js +2 -3
  5. data/app/assets/javascripts/admin/core/date_picker.js +2 -2
  6. data/app/assets/javascripts/admin/core/editor.js +2 -2
  7. data/app/assets/javascripts/admin/core/modal.js +1 -1
  8. data/app/assets/javascripts/admin/core/users.js +5 -5
  9. data/app/assets/javascripts/tb_core.js +8 -0
  10. data/app/assets/libs/sortable/sortable.js +152 -91
  11. data/app/controllers/admin/application_controller.rb +1 -2
  12. data/app/controllers/admin/dashboard_controller.rb +2 -2
  13. data/app/controllers/admin/settings_controller.rb +2 -2
  14. data/app/controllers/admin/users_controller.rb +4 -7
  15. data/app/controllers/concerns/tb_core/error_handling.rb +16 -7
  16. data/app/controllers/concerns/tb_core/user_authentication.rb +5 -5
  17. data/app/controllers/tb_core/application_controller.rb +1 -1
  18. data/app/controllers/user_sessions_controller.rb +2 -2
  19. data/app/helpers/tb_core/application_helper.rb +4 -36
  20. data/app/mailers/tb_core_mailer.rb +3 -3
  21. data/app/models/concerns/tb_core/user_model.rb +131 -0
  22. data/app/models/spud/spud_user_model.rb +6 -138
  23. data/app/models/spud_permission.rb +4 -4
  24. data/app/models/spud_role.rb +1 -1
  25. data/app/models/spud_user.rb +2 -1
  26. data/app/views/admin/dashboard/index.html.erb +1 -1
  27. data/app/views/admin/settings/_form.html.erb +1 -1
  28. data/app/views/admin/settings/edit.html.erb +1 -1
  29. data/app/views/admin/setup/new.html.erb +1 -1
  30. data/app/views/admin/users/_form.html.erb +1 -1
  31. data/app/views/admin/users/index.html.erb +2 -2
  32. data/app/views/admin/users/show.html.erb +1 -1
  33. data/app/views/layouts/admin/application.html.erb +6 -6
  34. data/app/views/layouts/admin/login.html.erb +1 -1
  35. data/app/views/tb_core_mailer/forgot_password_notification.html.erb +2 -2
  36. data/app/views/tb_core_mailer/user_credentials.html.erb +2 -2
  37. data/app/views/user_sessions/_form.html.erb +1 -1
  38. data/app/views/user_sessions/new.html.erb +1 -1
  39. data/lib/generators/spud/module_generator.rb +7 -7
  40. data/lib/generators/spud/setup_generator.rb +6 -7
  41. data/lib/generators/spud/templates/assets/admin/application.js +1 -1
  42. data/lib/generators/spud/templates/assets/application.js +3 -4
  43. data/lib/generators/spud/templates/controller_spec.rb.erb +5 -5
  44. data/lib/generators/spud/templates/views/admin/_form.html.erb +1 -1
  45. data/lib/generators/spud/templates/views/admin/index.html.erb +1 -1
  46. data/lib/generators/spud/templates/views/admin/show.html.erb +1 -1
  47. data/lib/generators/spud/templates/views/frontend/index.html.erb +1 -1
  48. data/lib/generators/spud/templates/views/frontend/show.html.erb +1 -1
  49. data/lib/tb_core.rb +3 -5
  50. data/lib/tb_core/belongs_to_app.rb +47 -46
  51. data/lib/tb_core/catch_all_route.rb +3 -0
  52. data/lib/tb_core/configuration.rb +28 -0
  53. data/lib/tb_core/engine.rb +61 -0
  54. data/lib/tb_core/errors.rb +50 -0
  55. data/lib/tb_core/responder.rb +0 -26
  56. data/lib/{spud_core → tb_core}/searchable.rb +4 -1
  57. data/lib/tb_core/spud_core.rb +23 -0
  58. data/lib/{spud_core → tb_core}/test_files.rb +0 -0
  59. data/lib/tb_core/test_helper.rb +3 -3
  60. data/lib/tb_core/version.rb +3 -0
  61. data/spec/controllers/admin/application_controller_spec.rb +5 -5
  62. data/spec/controllers/admin/dashboard_controller_spec.rb +5 -5
  63. data/spec/controllers/admin/password_reset_controller_spec.rb +1 -1
  64. data/spec/controllers/admin/settings_controller_spec.rb +1 -1
  65. data/spec/controllers/admin/setup_controller_spec.rb +2 -2
  66. data/spec/controllers/admin/user_sessions_controller_spec.rb +2 -2
  67. data/spec/controllers/admin/users_controller_spec.rb +17 -17
  68. data/spec/dummy/app/assets/javascripts/admin/application.js +1 -1
  69. data/spec/dummy/app/assets/javascripts/application.js +1 -1
  70. data/spec/dummy/config/application.rb +1 -1
  71. data/spec/factories/spud_admin_permission_factories.rb +2 -2
  72. data/spec/factories/spud_role_factories.rb +2 -2
  73. data/spec/factories/spud_user_factories.rb +6 -6
  74. data/spec/helpers/spud/admin/application_helper_spec.rb +1 -1
  75. data/spec/helpers/tb_core/application_helper_spec.rb +0 -35
  76. data/spec/lib/spud_core/configuration_spec.rb +2 -2
  77. data/spec/lib/tb_core/belongs_to_app_spec.rb +4 -3
  78. data/spec/models/spud_role_spec.rb +2 -2
  79. data/spec/models/spud_user_spec.rb +13 -13
  80. data/spec/rails_helper.rb +1 -1
  81. metadata +59 -67
  82. data/app/assets/javascripts/tb_core.js.erb +0 -9
  83. data/app/assets/javascripts/tb_core/configuration.js.erb +0 -9
  84. data/app/assets/javascripts/tb_core/console.js +0 -12
  85. data/app/assets/javascripts/tb_core/remote.js +0 -237
  86. data/app/assets/javascripts/tb_core/utility.js +0 -55
  87. data/app/controllers/concerns/tb_core/sortable_params.rb +0 -80
  88. data/app/controllers/spud/application_controller.rb +0 -10
  89. data/lib/generators/spud/templates/assets/bootstrap.js +0 -14
  90. data/lib/spud_core/catch_all_route.rb +0 -3
  91. data/lib/spud_core/configuration.rb +0 -56
  92. data/lib/spud_core/engine.rb +0 -76
  93. data/lib/spud_core/errors.rb +0 -47
  94. data/lib/spud_core/version.rb +0 -5
  95. data/lib/tb_core/table_header.rb +0 -92
  96. data/spec/controllers/tb_core/sortable_params_spec.rb +0 -64
@@ -10,24 +10,24 @@ class SpudPermission
10
10
 
11
11
  # Find a permission by tag
12
12
  def self.find(tag)
13
- return Spud::Core.permissions.find{ |p| p.tag == tag }
13
+ return TbCore.permissions.find{ |p| p.tag == tag }
14
14
  end
15
15
 
16
16
  # Returns hash of permissions, grouped by tag namespace
17
17
  def self.grouped_by_tag
18
- return Spud::Core.permissions.group_by do |p|
18
+ return TbCore.permissions.group_by do |p|
19
19
  p.tag.split('.').first
20
20
  end
21
21
  end
22
22
 
23
23
  # Returns array permissions sorted by tag
24
24
  def self.sorted_by_tag
25
- return Spud::Core.permissions.sort_by(&:tag)
25
+ return TbCore.permissions.sort_by(&:tag)
26
26
  end
27
27
 
28
28
  # Returns all permissions
29
29
  def self.all
30
- return Spud::Core.permissions
30
+ return TbCore.permissions
31
31
  end
32
32
 
33
33
  end
@@ -1,7 +1,7 @@
1
1
  class SpudRole < ActiveRecord::Base
2
2
 
3
3
  has_many :spud_role_permissions, dependent: :destroy
4
- has_many :users, class_name: 'SpudUser'
4
+ has_many :users, class_name: 'SpudUser', dependent: :nullify
5
5
 
6
6
  validates :name, presence: true, uniqueness: true
7
7
 
@@ -1,3 +1,4 @@
1
- class SpudUser < Spud::SpudUserModel
1
+ class SpudUser < ActiveRecord::Base
2
+ include TbCore::UserModel
2
3
  # Copy this file to your app to extend the base SpudUser model
3
4
  end
@@ -10,5 +10,5 @@
10
10
  <% end %>
11
11
  </div>
12
12
  <script type="text/javascript">
13
- $(document).ready(spud.admin.dashboard.init);
13
+ document.addEventListener('DOMContentLoaded', tb.dashboard.init);
14
14
  </script>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <h4>User Details</h4>
4
4
 
5
- <% if !Spud::Core.config.use_email_as_login %>
5
+ <% if !TbCore.config.use_email_as_login %>
6
6
  <div class="form-group">
7
7
  <%= f.label :login, :required => true, :class => "col-sm-2 control-label" %>
8
8
  <div class="col-sm-10">
@@ -9,6 +9,6 @@
9
9
  <%= render :partial => "form", :locals => {:f => f} %>
10
10
  <div class="form-actions">
11
11
  <%= f.submit "Save Settings", :class=>"btn btn-primary"%> or
12
- <%=link_to "cancel", (@current_user.has_admin_rights? ? admin_root_path : root_path), :class => "btn btn-default" %>
12
+ <%=link_to "cancel", (@current_user.admin_rights? ? admin_root_path : root_path), :class => "btn btn-default" %>
13
13
  </div>
14
14
  <% end %>
@@ -7,7 +7,7 @@
7
7
  <% tb_form_for @spud_user, :url => admin_setup_path do |f| %>
8
8
  <%= tb_form_errors f.object %>
9
9
 
10
- <% if !Spud::Core.config.use_email_as_login %>
10
+ <% if !TbCore.config.use_email_as_login %>
11
11
  <%= f.tb_text_field :login %>
12
12
  <% end %>
13
13
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  <%= f.tb_sub_title 'User Details' %>
6
6
 
7
- <% if !Spud::Core.config.use_email_as_login %>
7
+ <% if !TbCore.config.use_email_as_login %>
8
8
  <%= f.tb_text_field :login %>
9
9
  <% end %>
10
10
  <%= f.tb_text_field :email %>
@@ -8,7 +8,7 @@
8
8
  <%= content_for :detail do %>
9
9
  <div class="table-responsive">
10
10
  <table class="table table-striped table-hover">
11
- <%= tb_table_header :admin_users_path, model: SpudUser do |t| %>
11
+ <%= sortable_table_header :admin_users_path, model: SpudUser do |t| %>
12
12
  <%= t.sortable :name %>
13
13
  <%= t.sortable :email %>
14
14
  <%= t.sortable :current_login_at %>
@@ -34,6 +34,6 @@
34
34
  <%= will_paginate @spud_users, :renderer => BootstrapPagination::Rails %>
35
35
 
36
36
  <script>
37
- $(document).ready(spud.admin.users.index);
37
+ document.addEventListener('DOMContentLoaded', tb.users.index);
38
38
  </script>
39
39
  <% end %>
@@ -3,7 +3,7 @@
3
3
  <% end %>
4
4
 
5
5
  <dl class="dl-horizontal">
6
- <% if !Spud::Core.config.use_email_as_login %>
6
+ <% if !TbCore.config.use_email_as_login %>
7
7
  <dt>Login</dt>
8
8
  <dd><%= @user.login %></dd>
9
9
  <% end %>
@@ -1,24 +1,24 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
- <title><%= Spud::Core.config.site_name %> Admin</title>
5
- <%= stylesheet_link_tag *Spud::Core.config.admin_stylesheets %>
6
- <%= javascript_include_tag *Spud::Core.config.admin_javascripts %>
4
+ <title><%= TbCore.config.site_name %> Admin</title>
5
+ <%= stylesheet_link_tag *TbCore.config.admin_stylesheets %>
6
+ <%= javascript_include_tag *TbCore.config.admin_javascripts %>
7
7
  <%= csrf_meta_tags %>
8
8
  <meta name="viewport" content="width=device-width, initial-scale=1" />
9
9
  <meta name="viewport" content="width=device-width"/>
10
10
  <%= yield :head %>
11
11
  </head>
12
12
  <body>
13
- <% if Spud::Core.production_alert_domain %>
13
+ <% if TbCore.production_alert_domain %>
14
14
  <div class="production-alert-header">
15
- <p><strong>Notice:</strong> This is a staging version of your website. To update your live website, please <%= link_to 'log in to production.', "http://#{Spud::Core.production_alert_domain}/admin" %></p>
15
+ <p><strong>Notice:</strong> This is a staging version of your website. To update your live website, please <%= link_to 'log in to production.', "http://#{TbCore.production_alert_domain}/admin" %></p>
16
16
  </div>
17
17
  <% end %>
18
18
  <div id="header">
19
19
  <div class="container">
20
20
  <%= link_to '/' do %>
21
- <h1><%= Spud::Core.config.site_name %></h1>
21
+ <h1><%= TbCore.config.site_name %></h1>
22
22
  <% end %>
23
23
  <% if current_user %>
24
24
  <div class="pull-right">
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title><%= Spud::Core.config.site_name %> Admin: Login</title>
4
+ <title><%= TbCore.config.site_name %> Admin: Login</title>
5
5
  <%= stylesheet_link_tag 'admin/core/application' %>
6
6
  <%= javascript_include_tag 'admin/core/application' %>
7
7
  <%= csrf_meta_tags %>
@@ -1,6 +1,6 @@
1
1
  <h1>Hello <%= @user.full_name %>,</h1>
2
2
 
3
- <p>A password reset has recently been requested for your user account on <strong><%= Spud::Core.config.site_name %></strong>. Click the link below to set your new password.</p>
3
+ <p>A password reset has recently been requested for your user account on <strong><%= TbCore.config.site_name %></strong>. Click the link below to set your new password.</p>
4
4
 
5
5
  <p><%= link_to @url, @url %></p>
6
6
 
@@ -8,5 +8,5 @@
8
8
 
9
9
  <p>
10
10
  Thanks,<br/>
11
- <strong><%= Spud::Core.config.site_name %></strong>
11
+ <strong><%= TbCore.config.site_name %></strong>
12
12
  </p>
@@ -1,6 +1,6 @@
1
1
  <h1>Hello <%= @user.full_name %>,</h1>
2
2
 
3
- <p><%= t('tb_core_mailer.user_credentials.greeting', :site_name => Spud::Core.config.site_name) %></p>
3
+ <p><%= t('tb_core_mailer.user_credentials.greeting', :site_name => TbCore.config.site_name) %></p>
4
4
 
5
5
  <ul>
6
6
  <li><strong>Username:</strong> <%= @user.login %></li>
@@ -15,5 +15,5 @@
15
15
 
16
16
  <p>
17
17
  Thanks,<br/>
18
- <strong><%= Spud::Core.config.site_name %></strong>
18
+ <strong><%= TbCore.config.site_name %></strong>
19
19
  </p>
@@ -5,7 +5,7 @@
5
5
  <%= tb_form_errors(@user_session) %>
6
6
  <%= hidden_field_tag :return_to, return_to %>
7
7
  <div class="form-group">
8
- <% if Spud::Core.config.use_email_as_login %>
8
+ <% if TbCore.config.use_email_as_login %>
9
9
  <%= f.label :email %>
10
10
  <%= f.text_field :email, :placeholder => 'Email', :autofocus => 'autofocus', :autocomplete => 'username', :class => 'form-control' %>
11
11
  <% else %>
@@ -1,5 +1,5 @@
1
1
  <% @page_title = 'Login' %>
2
2
 
3
- <h1><%= Spud::Core.config.site_name %> Login</h1>
3
+ <h1><%= TbCore.config.site_name %> Login</h1>
4
4
 
5
5
  <%= render 'form' %>
@@ -41,7 +41,7 @@ class Spud::ModuleGenerator < ::Rails::Generators::Base
41
41
 
42
42
  def inject_code
43
43
  environment(
44
- "Spud::Core.config.admin_applications += [{name: '#{module_name_formatted.humanize.titlecase}',
44
+ "TbCore.config.admin_applications += [{name: '#{module_name_formatted.humanize.titlecase}',
45
45
  thumbnail: \"admin/module_icon.png\", url: \"/admin/#{module_name_formatted}\"}]"
46
46
  )
47
47
  Rails::Generators.invoke 'model', [module_name_formatted.singularize] + attributes, behavior: behavior
@@ -54,12 +54,12 @@ class Spud::ModuleGenerator < ::Rails::Generators::Base
54
54
  end
55
55
 
56
56
  def create_routes
57
- route <<EOF
58
- namespace :admin do
59
- resources :#{module_name_formatted}
60
- end
61
- resources :#{module_name_formatted}, :only => [:index, :show]
62
- EOF
57
+ route <<~RUBY
58
+ namespace :admin do
59
+ resources :#{module_name_formatted}
60
+ end
61
+ resources :#{module_name_formatted}, :only => [:index, :show]
62
+ RUBY
63
63
  end
64
64
 
65
65
  def create_specs
@@ -39,18 +39,17 @@ private
39
39
  template theme_file, 'app/assets/stylesheets/imports/bootstrap_theme.scss' if File.exist?(theme_file)
40
40
  modules_file = Bootstrap::Rails::Engine.root.join('assets', 'stylesheets', '_bootstrap.scss')
41
41
  template modules_file, 'app/assets/stylesheets/imports/bootstrap_modules.scss' if File.exist?(modules_file)
42
- template 'assets/bootstrap.js', 'app/assets/javascripts/bootstrap_modules.js'
43
42
  end
44
43
 
45
44
  def spud_core_configs
46
45
  site_name = application_name().titleize
47
46
  domain_name = application_name().dasherize
48
- return <<EOF
49
- Spud::Core.configure do |config|
50
- config.site_name = "#{site_name}"
51
- config.from_address = "no-reply@#{domain_name}.com"
52
- end
53
- EOF
47
+ return <<~RUBY
48
+ TbCore.configure do |config|
49
+ config.site_name = "#{site_name}"
50
+ config.from_address = "no-reply@#{domain_name}.com"
51
+ end
52
+ RUBY
54
53
  end
55
54
 
56
55
  def application_name
@@ -11,6 +11,6 @@ window.app = {
11
11
  }
12
12
  };
13
13
 
14
- $(document).ready(app.admin.init);
14
+ document.addEventListener('DOMContentLoaded', app.admin.init);
15
15
 
16
16
  })();
@@ -1,6 +1,5 @@
1
- //= require jquery
2
- //= require tb_core
3
- //= require bootstrap_modules
1
+ //= require rails-ujs
2
+ //= require rails-validator
4
3
  //= require_self
5
4
  //= require_directory .
6
5
 
@@ -12,6 +11,6 @@ window.app = {
12
11
  }
13
12
  };
14
13
 
15
- $(document).ready(app.init);
14
+ document.addEventListener('DOMContentLoaded', app.init);
16
15
 
17
16
  })();
@@ -16,7 +16,7 @@ RSpec.describe <%= controller_class_name %>, type: :controller do
16
16
 
17
17
  describe 'show' do
18
18
  it 'should render the show page' do
19
- <%= model_variable_name %> = FactoryGirl.create(:<%= model_variable_name %>)
19
+ <%= model_variable_name %> = FactoryBot.create(:<%= model_variable_name %>)
20
20
  get :show, id: <%= model_variable_name %>.id
21
21
  expect(response).to have_http_status :success
22
22
  end
@@ -36,7 +36,7 @@ RSpec.describe <%= controller_class_name %>, type: :controller do
36
36
 
37
37
  describe 'edit' do
38
38
  it 'should render the edit page' do
39
- <%= model_variable_name %> = FactoryGirl.create(:<%= model_variable_name %>)
39
+ <%= model_variable_name %> = FactoryBot.create(:<%= model_variable_name %>)
40
40
  get :edit, id: <%= model_variable_name %>.id
41
41
  expect(response).to have_http_status :success
42
42
  end
@@ -45,14 +45,14 @@ RSpec.describe <%= controller_class_name %>, type: :controller do
45
45
  describe 'create' do
46
46
  it 'should create the record' do
47
47
  expect do
48
- post :create, <%= model_variable_name %>: FactoryGirl.attributes_for(:<%= model_variable_name %>)
48
+ post :create, <%= model_variable_name %>: FactoryBot.attributes_for(:<%= model_variable_name %>)
49
49
  end.to change(<%= model_class_name %>, :count).by(1)
50
50
  end
51
51
  end
52
52
 
53
53
  describe 'update' do
54
54
  it 'should update the record' do
55
- <%= model_variable_name %> = FactoryGirl.create(:<%= model_variable_name %>)
55
+ <%= model_variable_name %> = FactoryBot.create(:<%= model_variable_name %>)
56
56
  current_value = <%= model_variable_name %>.<%= model_string_attribute_name %>
57
57
  new_value = current_value + '-Updated'
58
58
  expect do
@@ -64,7 +64,7 @@ RSpec.describe <%= controller_class_name %>, type: :controller do
64
64
 
65
65
  describe 'destroy' do
66
66
  it 'should destroy the record' do
67
- <%= model_variable_name %> = FactoryGirl.create(:<%= model_variable_name %>)
67
+ <%= model_variable_name %> = FactoryBot.create(:<%= model_variable_name %>)
68
68
  expect do
69
69
  delete :destroy, id: <%= model_variable_name %>.id
70
70
  end.to change(<%= model_class_name %>, :count).by(-1)
@@ -9,5 +9,5 @@
9
9
  <%% end %>
10
10
 
11
11
  <script>
12
- $(document).ready(app.admin.<%= module_name_formatted %>.edit);
12
+ document.addEventListener('DOMContentLoaded', app.admin.<%= module_name_formatted %>.edit);
13
13
  </script>
@@ -31,7 +31,7 @@
31
31
  <%%= will_paginate @<%=module_name_formatted%>, :renderer => BootstrapPagination::Rails %>
32
32
 
33
33
  <script>
34
- $(document).ready(app.admin.<%= module_name_formatted %>.index);
34
+ document.addEventListener('DOMContentLoaded', app.admin.<%= module_name_formatted %>.index);
35
35
  </script>
36
36
 
37
37
  <%% end %>
@@ -11,5 +11,5 @@
11
11
  </dl>
12
12
 
13
13
  <script>
14
- $(document).ready(app.admin.<%= module_name_formatted %>.show);
14
+ document.addEventListener('DOMContentLoaded', app.admin.<%= module_name_formatted %>.show);
15
15
  </script>
@@ -27,5 +27,5 @@
27
27
  <%%= will_paginate @<%=module_name_formatted%> %>
28
28
 
29
29
  <script>
30
- $(document).ready(app.<%= module_name_formatted %>.index);
30
+ document.addEventListener('DOMContentLoaded', app.<%= module_name_formatted %>.index);
31
31
  </script>
@@ -10,5 +10,5 @@
10
10
  <p><%%= link_to 'Back', <%=module_name_formatted.pluralize%>_path %></p>
11
11
 
12
12
  <script>
13
- $(document).ready(app.<%= module_name_formatted %>.show);
13
+ document.addEventListener('DOMContentLoaded', app.<%= module_name_formatted %>.show);
14
14
  </script>
@@ -1,6 +1,4 @@
1
- module Tb
2
- module Core
3
- require 'spud_core/engine'
4
- require 'spud_core/configuration'
5
- end
1
+ module TbCore
2
+ require 'tb_core/engine'
3
+ require 'tb_core/configuration'
6
4
  end
@@ -1,58 +1,59 @@
1
- module TbCore::BelongsToApp
2
- extend ActiveSupport::Concern
1
+ module TbCore
2
+ module BelongsToApp
3
+ extend ActiveSupport::Concern
3
4
 
4
- module ClassMethods
5
- def belongs_to_spud_app(name, options={})
6
- ActiveSupport::Deprecation.warn(
7
- 'ApplicationController#belongs_to_spud_app is deprecated. Please use #belongs_to_app instead.',
8
- caller
9
- )
10
- belongs_to_app(name, page_title: options[:page_title])
5
+ module ClassMethods
6
+ def belongs_to_spud_app(name, options={})
7
+ ActiveSupport::Deprecation.warn(
8
+ 'ApplicationController#belongs_to_spud_app is deprecated. Please use #belongs_to_app instead.',
9
+ caller
10
+ )
11
+ belongs_to_app(name, page_title: options[:page_title])
12
+ end
13
+
14
+ # Adds a before action to the current controller to act like the specified twice baked app
15
+ #
16
+ # symbol: This should be the :key value for the app you want to use
17
+ # page_title: Override the base name value for the app (optional)
18
+ # only: An array of controller actions you want this to apply to (optional)
19
+ #
20
+ def belongs_to_app(name, page_title: nil, only: nil)
21
+ before_action ->(){
22
+ act_as_app(name, page_title: page_title)
23
+ }, only: only
24
+ end
11
25
  end
12
26
 
13
- # Adds a before action to the current controller to act like the specified twice baked app
27
+ private
28
+
29
+ # Call the make the current controller behave as though it belongs to the specified twice baked app
14
30
  #
15
31
  # symbol: This should be the :key value for the app you want to use
16
32
  # page_title: Override the base name value for the app (optional)
17
- # only: An array of controller actions you want this to apply to (optional)
18
33
  #
19
- def belongs_to_app(name, page_title: nil, only: nil)
20
- before_action ->(){
21
- act_as_app(name, page_title: page_title)
22
- }, only: only
34
+ def act_as_app(symbol, page_title: nil)
35
+ @page_application = TbCore.admin_applications.find{ |app| app[:key] == symbol }
36
+ if @page_application.blank?
37
+ raise "Requested application '#{symbol}' could not be found"
38
+ elsif !current_user.can_view_app?(@page_application)
39
+ raise AccessDeniedError.new(item: 'module', template: '/layouts/admin/error_page')
40
+ end
41
+ @page_thumbnail = @page_application[:thumbnail]
42
+ @page_name = determine_page_name(page_title || @page_application[:name], action_name)
23
43
  end
24
- end
25
44
 
26
- private
27
-
28
- # Call the make the current controller behave as though it belongs to the specified twice baked app
29
- #
30
- # symbol: This should be the :key value for the app you want to use
31
- # page_title: Override the base name value for the app (optional)
32
- #
33
- def act_as_app(symbol, page_title: nil)
34
- @page_application = Spud::Core.admin_applications.find{ |app| app[:key] == symbol }
35
- if @page_application.blank?
36
- raise "Requested application '#{symbol}' could not be found"
37
- elsif !current_user.can_view_app?(@page_application)
38
- raise Spud::AccessDeniedError.new(item: 'module', template: '/layouts/admin/error_page')
39
- end
40
- @page_thumbnail = @page_application[:thumbnail]
41
- @page_name = determine_page_name(page_title || @page_application[:name], action_name)
42
- end
43
-
44
- # Takes a base app name and controller action name and returns an appropriate page title
45
- #
46
- def determine_page_name(base_name, action_name)
47
- if action_name == 'new' || action_name == 'create'
48
- return "New #{base_name.singularize}"
49
- elsif action_name == 'edit' || action_name == 'update'
50
- return "Edit #{base_name.singularize}"
51
- elsif action_name == 'show'
52
- return "#{base_name.singularize} Detail"
53
- else
54
- return base_name
45
+ # Takes a base app name and controller action name and returns an appropriate page title
46
+ #
47
+ def determine_page_name(base_name, action_name)
48
+ if ['new', 'create'].include?(action_name)
49
+ return "New #{base_name.singularize}"
50
+ elsif ['edit', 'update'].include?(action_name)
51
+ return "Edit #{base_name.singularize}"
52
+ elsif action_name == 'show'
53
+ return "#{base_name.singularize} Detail"
54
+ else
55
+ return base_name
56
+ end
55
57
  end
56
58
  end
57
-
58
59
  end