8000 Split out ApplicationSettings and NamespaceSettings classes. · stephancom/activeadmin@9b2f861 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 9b2f861

Browse files
committed
Split out ApplicationSettings and NamespaceSettings classes.
1 parent f0ea255 commit 9b2f861

File tree

3 files changed

+152
-148
lines changed

3 files changed

+152
-148
lines changed

lib/active_admin/application.rb

Lines changed: 6 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
require 'active_admin/router'
22
require 'active_admin/reloader'
3-
require 'active_admin/settings_node'
3+
require 'active_admin/application_settings'
4+
require 'active_admin/namespace_settings'
45

56
module ActiveAdmin
67
class Application
78

89
class << self
9-
def default_settings
10-
@settings ||= SettingsNode.build
11-
end
12-
13-
def namespace_default_settings
14-
@namespace_settings ||= SettingsNode.build
15-
end
16-
1710
def setting(name, default)
18-
default_settings.register name, default
11+
ApplicationSettings.register name, default
1912
end
2013

2114
def inheritable_setting(name, default)
22-
namespace_default_settings.register name, default
15+
NamespaceSettings.register name, default
2316
end
2417
end
2518

2619
def settings
27-
@settings ||= SettingsNode.build(self.class.default_settings)
20+
@settings ||= SettingsNode.build(ApplicationSettings)
2821
end
2922

3023
def namespace_settings
31-
@namespace_settings ||= SettingsNode.build(self.class.namespace_default_settings)
24+
@namespace_settings ||= SettingsNode.build(NamespaceSettings)
3225
end
3326

3427
def respond_to_missing?(method, include_private = false)
@@ -45,146 +38,11 @@ def method_missing(method, *args)
4538
end
4639
end
4740

48-
# The default namespace to put controllers and routes inside. Set this
49-
# in config/initializers/active_admin.rb using:
50-
#
51-
# config.default_namespace = :super_admin
52-
#
53-
setting :default_namespace, :admin
54-
5541
attr_reader :namespaces
5642
def initialize
5743
@namespaces = Namespace::Store.new
5844
end
5945

60-
setting :app_path, Rails.root
61-
62-
# Load paths for admin configurations. Add folders to this load path
63-
# to load up other resources for administration. External gems can
64-
# include their paths in this load path to provide active_admin UIs
65-
setting :load_paths, [File.expand_path('app/admin', Rails.root)]
66-
67-
# The default number of resources to display on index pages
68-
inheritable_setting :default_per_page, 30
69-
70-
# The max number of resources to display on index pages and batch exports
71-
inheritable_setting :max_per_page, 10_000
72-
73-
# The title which gets displayed in the main layout
74-
inheritable_setting :site_title, ""
75-
76-
# Set the site title link href (defaults to AA dashboard)
77-
inheritable_setting :site_title_link, ""
78-
79-
# Set the site title image displayed in the main layout (has precendence over :site_title)
80-
inheritable_setting :site_title_image, ""
81-
82-
# Set the site footer text (defaults to Powered by ActiveAdmin text with version)
83-
inheritable_setting :footer, ""
84-
85-
# Set a favicon
86-
inheritable_setting :favicon, false
87-
88-
# Additional meta tags to place in head of logged in pages.
89-
inheritable_setting :meta_tags, {}
90-
91-
# Additional meta tags to place in head of logged out pages.
92-
inheritable_setting :meta_tags_for_logged_out_pages, { robots: "noindex, nofollow" }
93-
94-
# The view factory to use to generate all the view classes. Take
95-
# a look at ActiveAdmin::ViewFactory
96-
inheritable_setting :view_factory, ActiveAdmin::ViewFactory.new
97-
98-
# The method to call in controllers to get the current user
99-
inheritable_setting :current_user_method, false
100-
101-
# The method to call in the controllers to ensure that there
102-
# is a currently authenticated admin user
103-
inheritable_setting :authentication_method, false
104-
105-
# The path to log user's out with. If set to a symbol, we assume
106-
# that it's a method to call which returns the path
107-
inheritable_setting :logout_link_path, :destroy_admin_user_session_path
108-
109-
# The method to use when generating the link for user logout
110-
inheritable_setting :logout_link_method, :get
111-
112-
# Whether the batch actions are enabled or not
113-
inheritable_setting :batch_actions, false
114-
115-
# Whether filters are enabled
116-
inheritable_setting :filters, true
117-
118-
# The namespace root.
119-
inheritable_setting :root_to, 'dashboard#index'
120-
121-
# Options that a passed to root_to.
122-
inheritable_setting :root_to_options, {}
123-
124-
# Options passed to the routes, i.e. { path: '/custom' }
125-
inheritable_setting :route_options, {}
126-
127-
# Display breadcrumbs
128-
inheritable_setting :breadcrumb, true
129-
130-
# Display create another checkbox on a new page
131-
# @return [Boolean] (true)
132-
inheritable_setting :create_another, false
133-
134-
# Default CSV options
135-
inheritable_setting :csv_options, { col_sep: ',', byte_order_mark: "\xEF\xBB\xBF" }
136-
137-
# Default Download Links options
138-
inheritable_setting :download_links, true
139-
140-
# The authorization adapter to use
141-
inheritable_setting :authorization_adapter, ActiveAdmin::AuthorizationAdapter
142-
143-
# A proc to be used when a user is not authorized to view the current resource
144-
inheritable_setting :on_unauthorized_access, :rescue_active_admin_access_denied
145-
146-
# A regex to detect unsupported browser, set to false to disable
147-
inheritable_setting :unsupported_browser_matcher, /MSIE [1-8]\.0/
148-
149-
# Whether to display 'Current Filters' on search screen
150-
inheritable_setting :current_filters, true
151-
152-
# class to handle ordering
153-
inheritable_setting :order_clause, ActiveAdmin::OrderClause
154-
155-
# default show_count for scopes
156-
inheritable_setting :scopes_show_count, true
157-
158-
# Request parameters that are permitted by default
159-
inheritable_setting :permitted_params, [
160-
:utf8, :_method, :authenticity_token, :commit, :id
161-
]
162-
163-
# Set flash message keys that shouldn't show in ActiveAdmin
164-
inheritable_setting :flash_keys_to_except, ['timedout']
165-
166-
# Set default localize format for Date/Time values
167-
setting :localize_format, :long
168-
169-
# Include association filters by default
170-
inheritable_setting :include_default_association_filters, true
171-
172-
# Active Admin makes educated guesses when displaying objects, this is
173-
# the list of methods it tries calling in order
174-
# Note that Formtastic also has 'collection_label_methods' similar to this
175-
# used by auto generated dropdowns in filter or belongs_to field of Active Admin
176-
setting :display_name_methods, [ :display_name,
177-
:full_name,
178-
:name,
179-
:username,
180-
:login,
181-
:title,
182-
:email,
183-
:to_s ]
184-
185-
# To make debugging easier, by default don't stream in development
186-
setting :disable_streaming_in, ['development']
187-
18846
# Event that gets triggered on load of Active Admin
18947
BeforeLoadEvent = 'active_admin.application.before_load'.freeze
19048
AfterLoadEvent = 'active_admin.application.after_load'.freeze
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'active_admin/settings_node'
2+
3+
module ActiveAdmin
4+
class ApplicationSettings < SettingsNode
5+
6+
# The default namespace to put controllers and routes inside. Set this
7+
# in config/initializers/active_admin.rb using:
8+
#
9+
# config.default_namespace = :super_admin
10+
#
11+
register :default_namespace, :admin
12+
13+
register :app_path, Rails.root
14+
15+
# Load paths for admin configurations. Add folders to this load path
16+
# to load up other resources for administration. External gems can
17+
# include their paths in this load path to provide active_admin UIs
18+
register :load_paths, [File.expand_path('app/admin', Rails.root)]
19+
20+
# Set default localize format for Date/Time values
21+
register :localize_format, :long
22+
23+
# Active Admin makes educated guesses when displaying objects, this is
24+
# the list of methods it tries calling in order
25+
# Note that Formtastic also has 'collection_label_methods' similar to this
26+
# used by auto generated dropdowns in filter or belongs_to field of Active Admin
27+
register :display_name_methods, [ :display_name,
28+
:full_name,
29+
:name,
30+
:username,
31+
:login,
32+
:title,
33+
:email,
34+
:to_s ]
35+
36+
# To make debugging easier, by default don't stream in development
37+
register :disable_streaming_in, ['development']
38+
end
39+
end
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
require 'active_admin/settings_node'
2+
3+
module ActiveAdmin
4+
class NamespaceSettings < SettingsNode
5+
# The default number of resources to display on index pages
6+
register :default_per_page, 30
7+
8+
# The max number of resources to display on index pages and batch exports
9+
register :max_per_page, 10_000
10+
11+
# The title which gets displayed in the main layout
12+
register :site_title, ""
13+
14+
# Set the site title link href (defaults to AA dashboard)
15+
register :site_title_link, ""
16+
17+
# Set the site title image displayed in the main layout (has precendence over :site_title)
18+
register :site_title_image, ""
19+
20+
# Set the site footer text (defaults to Powered by ActiveAdmin text with version)
21+
register :footer, ""
22+
23+
# Set a favicon
24+
register :favicon, false
25+
26+
# Additional meta tags to place in head of logged in pages.
27+
register :meta_tags, {}
28+
29+
# Additional meta tags to place in head of logged out pages.
30+
register :meta_tags_for_logged_out_pages, { robots: "noindex, nofollow" }
31+
32+
# The view factory to use to generate all the view classes. Take
33+
# a look at ActiveAdmin::ViewFactory
34+
register :view_factory, ActiveAdmin::ViewFactory.new
35+
36+
# The method to call in controllers to get the current user
37+
register :current_user_method, false
38+
39+
# The method to call in the controllers to ensure that there
40+
# is a currently authenticated admin user
41+
register :authentication_method, false
42+
43+
# The path to log user's out with. If set to a symbol, we assume
44+
# that it's a method to call which returns the path
45+
register :logout_link_path, :destroy_admin_user_session_path
46+
47+
# The method to use when generating the link for user logout
48+
register :logout_link_method, :get
49+
50+
# Whether the batch actions are enabled or not
51+
register :batch_actions, false
52+
53+
# Whether filters are enabled
54+
register :filters, true
55+
56+
# The namespace root.
57+
register :root_to, 'dashboard#index'
58+
59+
# Options that a passed to root_to.
60+
register :root_to_options, {}
61+
62+
# Options passed to the routes, i.e. { path: '/custom' }
63+
register :route_options, {}
64+
65+
# Display breadcrumbs
66+
register :breadcrumb, true
67+
68+
# Display create another checkbox on a new page
69+
# @return [Boolean] (true)
70+
register :create_another, false
71+
72+
# Default CSV options
73+
register :csv_options, { col_sep: ',', byte_order_mark: "\xEF\xBB\xBF" }
74+
75+
# Default Download Links options
76+
register :download_links, true
77+
78+
# The authorization adapter to use
79+
register :authorization_adapter, ActiveAdmin::AuthorizationAdapter
80+
81+
# A proc to be used when a user is not authorized to view the current resource
82+
register :on_unauthorized_access, :rescue_active_admin_access_denied
83+
84+
# A regex to detect unsupported browser, set to false to disable
85+
register :unsupported_browser_matcher, /MSIE [1-8]\.0/
86+
87+
# Whether to display 'Current Filters' on search screen
88+
register :current_filters, true
89+
90+
# class to handle ordering
91+
register :order_clause, ActiveAdmin::OrderClause
92+
93+
# default show_count for scopes
94+
register :scopes_show_count, true
95+
96+
# Request parameters that are permitted by default
97+
register :permitted_params, [
98+
:utf8, :_method, :authenticity_token, :commit, :id
99+
]
100+
101+
# Set flash message keys that shouldn't show in ActiveAdmin
102+
register :flash_keys_to_except, ['timedout']
103+
104+
# Include association filters by default
105+
register :include_default_association_filters, true
106+
end
107+
end

0 commit comments

Comments
 (0)
0