2007-11-08 05:29:44 +00:00
|
|
|
module Rails
|
|
|
|
class Plugin
|
2009-11-03 01:19:03 +00:00
|
|
|
include Initializable
|
2007-11-08 05:29:44 +00:00
|
|
|
|
2009-12-23 22:55:12 +00:00
|
|
|
def self.plugin_name(plugin_name = nil)
|
|
|
|
@plugin_name ||= name.demodulize.underscore
|
|
|
|
@plugin_name = plugin_name if plugin_name
|
|
|
|
@plugin_name
|
2009-12-16 06:07:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.inherited(klass)
|
|
|
|
@plugins ||= []
|
|
|
|
@plugins << klass unless klass == Vendored
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.plugins
|
|
|
|
@plugins
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.plugin_names
|
|
|
|
plugins.map { |p| p.plugin_name }
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.config
|
2009-12-23 22:55:12 +00:00
|
|
|
Configuration.default
|
2009-12-16 06:07:12 +00:00
|
|
|
end
|
|
|
|
|
2009-11-07 01:21:39 +00:00
|
|
|
class Vendored < Plugin
|
|
|
|
def self.all(list, paths)
|
|
|
|
plugins = []
|
|
|
|
paths.each do |path|
|
|
|
|
Dir["#{path}/*"].each do |plugin_path|
|
|
|
|
plugin = new(plugin_path)
|
|
|
|
next unless list.include?(plugin.name) || list.include?(:all)
|
|
|
|
plugins << plugin
|
|
|
|
end
|
|
|
|
end
|
2008-05-28 19:30:44 +00:00
|
|
|
|
2009-11-07 01:21:39 +00:00
|
|
|
plugins.sort_by do |p|
|
|
|
|
[list.index(p.name) || list.index(:all), p.name.to_s]
|
|
|
|
end
|
|
|
|
end
|
2008-05-28 19:30:44 +00:00
|
|
|
|
2009-11-07 01:21:39 +00:00
|
|
|
attr_reader :name, :path
|
2008-11-26 13:41:20 +00:00
|
|
|
|
2009-11-07 01:21:39 +00:00
|
|
|
def initialize(path)
|
|
|
|
@name = File.basename(path).to_sym
|
|
|
|
@path = path
|
|
|
|
end
|
2008-11-26 13:41:20 +00:00
|
|
|
|
2009-11-07 01:21:39 +00:00
|
|
|
def load_paths
|
|
|
|
Dir["#{path}/{lib}", "#{path}/app/{models,controllers,helpers}"]
|
|
|
|
end
|
2007-11-08 05:29:44 +00:00
|
|
|
|
2009-11-07 01:21:39 +00:00
|
|
|
initializer :add_to_load_path, :after => :set_autoload_paths do |app|
|
|
|
|
load_paths.each do |path|
|
|
|
|
$LOAD_PATH << path
|
|
|
|
require "active_support/dependencies"
|
2007-11-08 05:29:44 +00:00
|
|
|
|
2009-11-07 01:21:39 +00:00
|
|
|
ActiveSupport::Dependencies.load_paths << path
|
2008-11-26 13:41:20 +00:00
|
|
|
|
2009-11-07 01:21:39 +00:00
|
|
|
unless app.config.reload_plugins
|
|
|
|
ActiveSupport::Dependencies.load_once_paths << path
|
|
|
|
end
|
2008-06-08 18:04:04 +00:00
|
|
|
end
|
2009-11-03 01:19:03 +00:00
|
|
|
end
|
|
|
|
|
2009-11-07 01:21:39 +00:00
|
|
|
initializer :load_init_rb, :before => :load_application_initializers do |app|
|
|
|
|
file = "#{@path}/init.rb"
|
|
|
|
config = app.config
|
|
|
|
eval File.read(file), binding, file if File.file?(file)
|
2009-11-03 01:19:03 +00:00
|
|
|
end
|
2008-03-27 18:37:53 +00:00
|
|
|
|
2009-11-07 01:21:39 +00:00
|
|
|
initializer :add_view_paths, :after => :initialize_framework_views do
|
|
|
|
ActionController::Base.view_paths.concat ["#{path}/app/views"] if File.directory?("#{path}/app/views")
|
|
|
|
end
|
2008-03-27 18:37:53 +00:00
|
|
|
|
2009-11-07 01:21:39 +00:00
|
|
|
initializer :add_routing_file, :after => :initialize_routing do |app|
|
|
|
|
routing_file = "#{path}/config/routes.rb"
|
|
|
|
if File.exist?(routing_file)
|
2009-12-14 23:54:41 +00:00
|
|
|
app.route_configuration_files << routing_file
|
|
|
|
app.reload_routes!
|
2009-11-07 01:21:39 +00:00
|
|
|
end
|
|
|
|
end
|
2008-03-27 18:37:53 +00:00
|
|
|
end
|
|
|
|
end
|
2009-11-07 01:21:39 +00:00
|
|
|
end
|