Module: TrustyCms::Initializer
- Defined in:
- lib/trusty_cms/initializer.rb
Instance Method Summary collapse
-
#admin ⇒ Object
Returns the TrustyCms::AdminUI singleton so that the initializer can set up the admin interface.
-
#after_initialize ⇒ Object
Extends the Rails initializer with some extra steps at the end of initialization: * hook up trusty view paths in controllers and notifiers * initialize the navigation tabs in the admin interface * initialize the extendable partial sets that make up the admin interface * call
activate
on all trusty extensions * add extension controller paths * mark extension app paths for eager loading. -
#deployed_as_app? ⇒ Boolean
Returns true in the very unusual case where trusty has been deployed as a rails app itself, rather than loaded as a gem or from vendor/.
-
#extension_loader ⇒ Object
Returns the ExtensionLoader singleton that will eventually load extensions.
-
#initialize_default_admin_tabs ⇒ Object
Initializes the core admin tabs.
-
#initialize_i18n ⇒ Object
Extends the Rails initializer to add locale paths from TRUSTY_CMS_ROOT and from trusty extensions.
-
#initialize_metal ⇒ Object
Overrides the Rails initializer to load metal from TRUSTY_CMS_ROOT and from trusty extensions.
-
#initialize_routing ⇒ Object
Extends the Rails initializer to make sure that extension controller paths are available when routes are initialized.
-
#initialize_views ⇒ Object
Initializes all the admin interface elements and views.
-
#load_application_initializers ⇒ Object
Extends the Rails initializer to run initializers from trusty and from extensions.
-
#load_gems ⇒ Object
Overrides the standard gem-loader to use Bundler instead of config.gem.
-
#load_plugins ⇒ Object
Extends the Rails initializer also to load trusty extensions (which have been excluded from the list of plugins).
-
#load_trusty_initializers ⇒ Object
Loads initializers found in TRUSTY_CMS_ROOT/config/initializers.
-
#set_autoload_patf ⇒ Object
Extends the Rails::Initializer default to add extension paths to the autoload list.
Instance Method Details
#admin ⇒ Object
Returns the TrustyCms::AdminUI singleton so that the initializer can set up the admin interface.
143 144 145 |
# File 'lib/trusty_cms/initializer.rb', line 143 def admin TrustyCms::Application.config.admin end |
#after_initialize ⇒ Object
Extends the Rails initializer with some extra steps at the end of initialization:
-
hook up trusty view paths in controllers and notifiers
-
initialize the navigation tabs in the admin interface
-
initialize the extendable partial sets that make up the admin interface
-
call
activate
on all trusty extensions -
add extension controller paths
-
mark extension app paths for eager loading
111 112 113 114 115 116 |
# File 'lib/trusty_cms/initializer.rb', line 111 def after_initialize super extension_loader.activate_extensions # also calls initialize_views TrustyCms::Application.config.add_controller_paths(extension_loader.paths(:controller)) TrustyCms::Application.config.add_eager_load_paths(extension_loader.paths(:eager_load)) end |
#deployed_as_app? ⇒ Boolean
Returns true in the very unusual case where trusty has been deployed as a rails app itself, rather than loaded as a gem or from vendor/. This is only likely in situations where trusty is customised so heavily that extensions are not sufficient.
23 24 25 |
# File 'lib/trusty_cms/initializer.rb', line 23 def deployed_as_app? TRUSTY_CMS_ROOT == Rails.root end |
#extension_loader ⇒ Object
Returns the ExtensionLoader singleton that will eventually load extensions.
149 150 151 |
# File 'lib/trusty_cms/initializer.rb', line 149 def extension_loader ExtensionLoader.instance { |l| l.initializer = self } end |
#initialize_default_admin_tabs ⇒ Object
Initializes the core admin tabs. Separate so that it can be invoked by itself in tests.
128 129 130 |
# File 'lib/trusty_cms/initializer.rb', line 128 def initialize_default_admin_tabs admin.initialize_nav end |
#initialize_i18n ⇒ Object
Extends the Rails initializer to add locale paths from TRUSTY_CMS_ROOT and from trusty extensions.
51 52 53 54 55 |
# File 'lib/trusty_cms/initializer.rb', line 51 def initialize_i18n trusty_locale_paths = Dir[File.join(TRUSTY_CMS_ROOT, 'config', 'locales', '*.{rb,yml}')] configuration.i18n.load_path = trusty_locale_paths + extension_loader.paths(:locale) super end |
#initialize_metal ⇒ Object
Overrides the Rails initializer to load metal from TRUSTY_CMS_ROOT and from trusty extensions.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/trusty_cms/initializer.rb', line 36 def Rails::Rack::Metal. = configuration. Rails::Rack::Metal. = ["#{TRUSTY_CMS_ROOT}/app/metal"] # reset Rails default to TRUSTY_CMS_ROOT Rails::Rack::Metal. += plugin_loader. Rails::Rack::Metal. += extension_loader.paths(:metal) Rails::Rack::Metal..uniq! configuration.middleware.insert_before( :"ActionController::ParamsParser", Rails::Rack::Metal, if: Rails::Rack::Metal..any? ) end |
#initialize_routing ⇒ Object
Extends the Rails initializer to make sure that extension controller paths are available when routes are initialized.
135 136 137 138 139 |
# File 'lib/trusty_cms/initializer.rb', line 135 def initialize_routing configuration.add_controller_paths(extension_loader.paths(:controller)) configuration.add_eager_load_paths(extension_loader.paths(:eager_load)) super end |
#initialize_views ⇒ Object
Initializes all the admin interface elements and views. Separate here so that it can be called to reset the interface before extension (re)activation.
121 122 123 124 |
# File 'lib/trusty_cms/initializer.rb', line 121 def initialize_views initialize_default_admin_tabs admin.load_default_regions end |
#load_application_initializers ⇒ Object
Extends the Rails initializer to run initializers from trusty and from extensions. The load order will be:
-
TRUSTY_CMS_ROOT/config/intializers/*.rb
-
Rails.root/config/intializers/*.rb
-
config/initializers/*.rb found in extensions, in extension load order.
In the now rare case where trusty is deployed as an ordinary rails application, step 1 is skipped because it is equivalent to step 2.
89 90 91 92 93 |
# File 'lib/trusty_cms/initializer.rb', line 89 def load_application_initializers load_trusty_initializers unless deployed_as_app? super extension_loader.load_extension_initializers end |
#load_gems ⇒ Object
Overrides the standard gem-loader to use Bundler instead of config.gem. This is the method normally monkey-patched into Rails::Initializer from boot.rb if you follow the instructions at gembundler.com/rails23.html
70 71 72 |
# File 'lib/trusty_cms/initializer.rb', line 70 def load_gems @bundler_loaded ||= Bundler.require :default, Rails.env end |
#load_plugins ⇒ Object
Extends the Rails initializer also to load trusty extensions (which have been excluded from the list of plugins).
76 77 78 79 |
# File 'lib/trusty_cms/initializer.rb', line 76 def load_plugins super extension_loader.load_extensions end |
#load_trusty_initializers ⇒ Object
Loads initializers found in TRUSTY_CMS_ROOT/config/initializers.
97 98 99 100 101 |
# File 'lib/trusty_cms/initializer.rb', line 97 def load_trusty_initializers Dir["#{TRUSTY_CMS_ROOT}/config/initializers/**/*.rb"].sort.each do |initializer| load(initializer) end end |
#set_autoload_patf ⇒ Object
Extends the Rails::Initializer default to add extension paths to the autoload list. Note that default_autoload_paths
is also overridden to point to TRUSTY_CMS_ROOT.
30 31 32 |
# File 'lib/trusty_cms/initializer.rb', line 30 def set_autoload_patf super end |