Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / lib / radiant / .svn / text-base / initializer.rb.svn-base
blob5a96d11b4315abd48d816a39f69e1ca56d8b603a
1 # Add necessary Rails path
2 $LOAD_PATH.unshift "#{RADIANT_ROOT}/vendor/rails/railties/lib"
4 require 'initializer'
5 require 'radiant/admin_ui'
6 require 'radiant/extension_loader'
8 module Radiant
10   class Configuration < Rails::Configuration
11     attr_accessor :extension_paths
12     attr_accessor :extensions
13     attr_accessor :view_paths
15     def initialize
16       self.view_paths = []
17       self.extension_paths = default_extension_paths
18       self.extensions = [ :all ]
19       super
20     end
22     def default_extension_paths
23       env = ENV["RAILS_ENV"] || RAILS_ENV
24       paths = [RADIANT_ROOT + '/vendor/extensions', RAILS_ROOT + '/vendor/extensions'].uniq
25       # There's no other way it will work, config/environments/test.rb loads too late
26       # TODO: Should figure out how to include this extension path only for the tests that need it
27       paths.unshift(RADIANT_ROOT + "/test/fixtures/extensions") if env == "test"
28       paths
29     end
31     def admin
32       AdminUI.instance
33     end
35     private
37       def library_directories
38         Dir["#{RADIANT_ROOT}/vendor/*/lib"]
39       end
41       def framework_root_path
42         RADIANT_ROOT + '/vendor/rails'
43       end
45       # Provide the load paths for the Radiant installation
46       def default_load_paths
47         paths = ["#{RADIANT_ROOT}/test/mocks/#{environment}"]
49         # Add the app's controller directory
50         paths.concat(Dir["#{RADIANT_ROOT}/app/controllers/"])
52         # Then components subdirectories.
53         paths.concat(Dir["#{RADIANT_ROOT}/components/[_a-z]*"])
55         # Followed by the standard includes.
56         paths.concat %w(
57           app
58           app/models
59           app/controllers
60           app/helpers
61           config
62           lib
63           vendor
64         ).map { |dir| "#{RADIANT_ROOT}/#{dir}" }.select { |dir| File.directory?(dir) }
66         paths.concat builtin_directories
67         paths.concat library_directories
68       end
70       def default_plugin_paths
71         [
72           "#{RAILS_ROOT}/vendor/plugins",
73           "#{RADIANT_ROOT}/lib/plugins",
74           "#{RADIANT_ROOT}/vendor/plugins"
75         ]
76       end
78       def default_view_path
79         File.join(RADIANT_ROOT, 'app', 'views')
80       end
82       def default_controller_paths
83         [File.join(RADIANT_ROOT, 'app', 'controllers')]
84       end
85   end
87   class Initializer < Rails::Initializer
88     def self.run(command = :process, configuration = Configuration.new)
89       super
90     end
92     def set_autoload_paths
93       extension_loader.add_extension_paths
94       super
95     end
97     def add_plugin_load_paths
98       # checks for plugins within extensions:
99       extension_loader.add_plugin_paths
100       super
101     end
103     def load_plugins
104       super
105       extension_loader.load_extensions
106     end
108     def after_initialize
109       extension_loader.activate_extensions
110       super
111     end
113     def initialize_default_admin_tabs
114       admin.tabs.clear
115       admin.tabs.add "Pages",    "/admin/pages"
116       admin.tabs.add "Snippets", "/admin/snippets"
117       admin.tabs.add "Layouts",  "/admin/layouts", :visibility => [:admin, :developer]
118     end
120     def initialize_framework_views
121       view_paths = returning [] do |arr|
122         # Add the singular view path if it's not in the list
123         arr << configuration.view_path if !configuration.view_paths.include?(configuration.view_path)
124         # Add the default view paths
125         arr.concat configuration.view_paths
126         # Add the extension view paths
127         arr.concat extension_loader.view_paths
128         # Reverse the list so extensions come first
129         arr.reverse!
130       end
131       ActionMailer::Base.view_paths = view_paths if configuration.frameworks.include?(:action_mailer) || defined?(ActionMailer::Base)
132       ActionController::Base.view_paths = view_paths if configuration.frameworks.include?(:action_controller)
133     end
135     def initialize_routing
136       extension_loader.add_controller_paths
137       super
138     end
140     def admin
141       configuration.admin
142     end
144     def extension_loader
145       ExtensionLoader.instance {|l| l.initializer = self }
146     end
147   end