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)
71 72 73 74 75 |
# File 'lib/trusty_cms/initializer.rb', line 71 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.
153 154 155 |
# File 'lib/trusty_cms/initializer.rb', line 153 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
121 122 123 124 125 126 |
# File 'lib/trusty_cms/initializer.rb', line 121 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.
35 36 37 |
# File 'lib/trusty_cms/initializer.rb', line 35 def deployed_as_app? TRUSTY_CMS_ROOT == Rails.root end |
#extension_loader ⇒ Object
Returns the ExtensionLoader singleton that will eventually load extensions.
159 160 161 |
# File 'lib/trusty_cms/initializer.rb', line 159 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.
138 139 140 |
# File 'lib/trusty_cms/initializer.rb', line 138 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.
62 63 64 65 66 |
# File 'lib/trusty_cms/initializer.rb', line 62 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.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/trusty_cms/initializer.rb', line 48 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.
145 146 147 148 149 |
# File 'lib/trusty_cms/initializer.rb', line 145 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.
131 132 133 134 |
# File 'lib/trusty_cms/initializer.rb', line 131 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.
99 100 101 102 103 |
# File 'lib/trusty_cms/initializer.rb', line 99 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
80 81 82 |
# File 'lib/trusty_cms/initializer.rb', line 80 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).
86 87 88 89 |
# File 'lib/trusty_cms/initializer.rb', line 86 def load_plugins super extension_loader.load_extensions end |
#load_radiant_initializers ⇒ Object
Loads initializers found in TRUSTY_CMS_ROOT/config/initializers.
107 108 109 110 111 |
# File 'lib/trusty_cms/initializer.rb', line 107 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.
42 43 44 |
# File 'lib/trusty_cms/initializer.rb', line 42 def set_autoload_patf super end |