Module: TrustyCms::Initializer
- Defined in:
- lib/trusty_cms/initializer.rb
Instance Method Summary collapse
-
#add_plugin_load_paths ⇒ Object
Extends the Rails initializer to add plugin paths in extensions and makes extension load paths reloadable (eg in development mode).
-
#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 radiant 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 radiant extensions * add extension controller paths * mark extension app paths for eager loading. -
#deployed_as_app? ⇒ Boolean
Returns true in the very unusual case where radiant 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 radiant extensions.
-
#initialize_metal ⇒ Object
Overrides the Rails initializer to load metal from TRUSTY_CMS_ROOT and from radiant 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 radiant 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 radiant extensions (which have been excluded from the list of plugins).
-
#load_radiant_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
#add_plugin_load_paths ⇒ Object
Extends the Rails initializer to add plugin paths in extensions and makes extension load paths reloadable (eg in development mode)
72 73 74 75 76 |
# File 'lib/trusty_cms/initializer.rb', line 72 def add_plugin_load_paths configuration.add_plugin_paths(extension_loader.paths(:plugin)) super ActiveSupport::Dependencies.autoload_once_paths -= extension_loader.paths(:load) end |
#admin ⇒ Object
Returns the TrustyCms::AdminUI singleton so that the initializer can set up the admin interface.
154 155 156 |
# File 'lib/trusty_cms/initializer.rb', line 154 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 radiant 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 radiant extensions -
add extension controller paths
-
mark extension app paths for eager loading
122 123 124 125 126 127 |
# File 'lib/trusty_cms/initializer.rb', line 122 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 radiant has been deployed as a rails app itself, rather than loaded as a gem or from vendor/. This is only likely in situations where radiant is customised so heavily that extensions are not sufficient.
36 37 38 |
# File 'lib/trusty_cms/initializer.rb', line 36 def deployed_as_app? TRUSTY_CMS_ROOT == Rails.root end |
#extension_loader ⇒ Object
Returns the ExtensionLoader singleton that will eventually load extensions.
160 161 162 |
# File 'lib/trusty_cms/initializer.rb', line 160 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.
139 140 141 |
# File 'lib/trusty_cms/initializer.rb', line 139 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 radiant extensions.
63 64 65 66 67 |
# File 'lib/trusty_cms/initializer.rb', line 63 def initialize_i18n radiant_locale_paths = Dir[File.join(TRUSTY_CMS_ROOT, 'config', 'locales', '*.{rb,yml}')] configuration.i18n.load_path = radiant_locale_paths + extension_loader.paths(:locale) super end |
#initialize_metal ⇒ Object
Overrides the Rails initializer to load metal from TRUSTY_CMS_ROOT and from radiant extensions.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/trusty_cms/initializer.rb', line 49 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.
146 147 148 149 150 |
# File 'lib/trusty_cms/initializer.rb', line 146 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.
132 133 134 135 |
# File 'lib/trusty_cms/initializer.rb', line 132 def initialize_views initialize_default_admin_tabs admin.load_default_regions end |
#load_application_initializers ⇒ Object
Extends the Rails initializer to run initializers from radiant 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 radiant is deployed as an ordinary rails application, step 1 is skipped because it is equivalent to step 2.
100 101 102 103 104 |
# File 'lib/trusty_cms/initializer.rb', line 100 def load_application_initializers load_radiant_initializers unless deployed_as_app? super extension_loader.load_extension_initalizers 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
81 82 83 |
# File 'lib/trusty_cms/initializer.rb', line 81 def load_gems @bundler_loaded ||= Bundler.require :default, Rails.env end |
#load_plugins ⇒ Object
Extends the Rails initializer also to load radiant extensions (which have been excluded from the list of plugins).
87 88 89 90 |
# File 'lib/trusty_cms/initializer.rb', line 87 def load_plugins super extension_loader.load_extensions end |
#load_radiant_initializers ⇒ Object
Loads initializers found in TRUSTY_CMS_ROOT/config/initializers.
108 109 110 111 112 |
# File 'lib/trusty_cms/initializer.rb', line 108 def load_radiant_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.
43 44 45 |
# File 'lib/trusty_cms/initializer.rb', line 43 def set_autoload_patf super end |