module TrustyCms::Initializer
def add_plugin_load_paths
and makes extension load paths reloadable (eg in development mode)
Extends the Rails initializer to add plugin paths in extensions
def add_plugin_load_paths configuration.add_plugin_paths(extension_loader.paths(:plugin)) super ActiveSupport::Dependencies.autoload_once_paths -= extension_loader.paths(:load) end
def admin
Returns the TrustyCms::AdminUI singleton so that the initializer can set up the admin interface.
def admin TrustyCms::Application.config.admin end
def after_initialize
* mark extension app paths for eager loading
* add extension controller paths
* call +activate+ on all radiant extensions
* initialize the extendable partial sets that make up the admin interface
* initialize the navigation tabs in the admin interface
* hook up radiant view paths in controllers and notifiers
Extends the Rails initializer with some extra steps at the end of initialization:
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
def deployed_as_app?
that extensions are not sufficient.
loaded as a gem or from vendor/. This is only likely in situations where radiant is customised so heavily
Returns true in the very unusual case where radiant has been deployed as a rails app itself, rather than
def deployed_as_app? TRUSTY_CMS_ROOT == Rails.root end
def extension_loader
Returns the ExtensionLoader singleton that will eventually load extensions.
def extension_loader ExtensionLoader.instance {|l| l.initializer = self } end
def initialize_default_admin_tabs
Initializes the core admin tabs. Separate so that it can be invoked by itself in tests.
def initialize_default_admin_tabs admin.initialize_nav end
def initialize_framework_views
so that new extension paths are noticed without a restart.
In environments that don't cache templates it reloads the path set on each request,
This adds extension view paths to the standard Rails::Initializer method.
def initialize_framework_views view_paths = extension_loader.paths(:view) #.push(TrustyCms::Application.config.view_path) if ActionController::Base.view_paths.count == 0 || !ActionView::Base.cache_template_loading ActionController::Base.view_paths = ActionView::PathSet.new(Array.wrap(view_paths)) end if ActionMailer::Base.view_paths.count == 0 || !ActionView::Base.cache_template_loading ActionMailer::Base.view_paths = ActionView::PathSet.new(Array.wrap(view_paths)) end end
def initialize_i18n
Extends the Rails initializer to add locale paths from TRUSTY_CMS_ROOT and from radiant extensions.
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
def initialize_metal
Overrides the Rails initializer to load metal from TRUSTY_CMS_ROOT and from radiant extensions.
def initialize_metal Rails::Rack::Metal.requested_metals = configuration.metals Rails::Rack::Metal.metal_paths = ["#{TRUSTY_CMS_ROOT}/app/metal"] # reset Rails default to TRUSTY_CMS_ROOT Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths Rails::Rack::Metal.metal_paths += extension_loader.paths(:metal) Rails::Rack::Metal.metal_paths.uniq! configuration.middleware.insert_before( :"ActionController::ParamsParser", Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?) end
def initialize_routing
are initialized.
Extends the Rails initializer to make sure that extension controller paths are available when routes
def initialize_routing configuration.add_controller_paths(extension_loader.paths(:controller)) configuration.add_eager_load_paths(extension_loader.paths(:eager_load)) super end
def initialize_views
to reset the interface before extension (re)activation.
Initializes all the admin interface elements and views. Separate here so that it can be called
def initialize_views initialize_default_admin_tabs initialize_framework_views admin.load_default_regions end
def load_application_initializers
because it is equivalent to step 2.
In the now rare case where radiant is deployed as an ordinary rails application, step 1 is skipped
3. config/initializers/*.rb found in extensions, in extension load order.
2. Rails.root/config/intializers/*.rb
1. TRUSTY_CMS_ROOT/config/intializers/*.rb
Extends the Rails initializer to run initializers from radiant and from extensions. The load order will be:
def load_application_initializers load_radiant_initializers unless deployed_as_app? super extension_loader.load_extension_initalizers end
def load_gems
into Rails::Initializer from boot.rb if you follow the instructions at http://gembundler.com/rails23.html
Overrides the standard gem-loader to use Bundler instead of config.gem. This is the method normally monkey-patched
def load_gems @bundler_loaded ||= Bundler.require :default, Rails.env end
def load_plugins
Extends the Rails initializer also to load radiant extensions (which have been excluded from the list of plugins).
def load_plugins super extension_loader.load_extensions end
def load_radiant_initializers
Loads initializers found in TRUSTY_CMS_ROOT/config/initializers.
def load_radiant_initializers Dir["#{TRUSTY_CMS_ROOT}/config/initializers/**/*.rb"].sort.each do |initializer| load(initializer) end end
def set_autoload_patf
Note that +default_autoload_paths+ is also overridden to point to TRUSTY_CMS_ROOT.
Extends the Rails::Initializer default to add extension paths to the autoload list.
def set_autoload_patf super end