Eric Davis 7b0cb6aba8 Upgraded to Rails 2.3.4 (#3597)
* Ran the Rails upgrade
* Upgraded to Rails Engines 2.3.2
* Added a plugin to let Engines override application views.
* Converted tests to use the new classes:
** ActionController::TestCase for functional
** ActiveSupport::TestCase for units
* Converted ActiveRecord::Error message to a string.
* ActiveRecord grouping returns an ordered hash which doesn't have #sort!
* Updated the I18n storage_units format.
* Added some default initializers from a fresh rails app
* Changed the order of check_box_tags and hidden_field_tags.  The hidden tag
  needs to appear first in Rails 2.3, otherwise it will override any value in
  the check_box_tag.
* Removed the custom handler for when the cookie store is tampered with.
  Rails 2.3 removed the TamperedWithCookie exception and instead Rails will not
  load the data from it when it's been tampered with (e.g. no user login).
* Fixed mail layouts, 2.3 has problems with implicit multipart emails that
  use layouts.  Also removed some custom Redmine mailer code.
* Fixed a bug that occurred in tests where the "required" span tag would be
  added to the :field_status translation.  This resulted in an email string of:

    <li>Status<span class="required"> *</span><span class="required"> *</span>

  Instead of:

    <li>Status: New</li>

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2887 e93f8b46-1217-0410-a6f0-8f06a7374b81
2009-09-13 17:14:35 +00:00

98 lines
3.2 KiB
Ruby

# An instance of Plugin is created for each plugin loaded by Rails, and
# stored in the <tt>Engines.plugins</tt> PluginList
# (see Engines::RailsExtensions::RailsInitializer for more details).
#
# Engines.plugins[:plugin_name]
#
# Other properties of the Plugin instance can also be set.
module Engines
class Plugin < Rails::Plugin
# Plugins can add paths to this attribute in init.rb if they need
# controllers loaded from additional locations.
attr_accessor :controller_paths
# The directory in this plugin to mirror into the shared directory
# under +public+.
#
# Defaults to "assets" (see default_public_directory).
attr_accessor :public_directory
protected
# The default set of code paths which will be added to the routing system
def default_controller_paths
%w(app/controllers components)
end
# Attempts to detect the directory to use for public files.
# If +assets+ exists in the plugin, this will be used. If +assets+ is missing
# but +public+ is found, +public+ will be used.
def default_public_directory
Engines.select_existing_paths(%w(assets public).map { |p| File.join(directory, p) }).first
end
public
def initialize(directory)
super directory
@controller_paths = default_controller_paths
@public_directory = default_public_directory
end
# Extends the superclass' load method to additionally mirror public assets
def load(initializer)
return if loaded?
super initializer
add_plugin_locale_paths
Assets.mirror_files_for(self)
end
# select those paths that actually exist in the plugin's directory
def select_existing_paths(name)
Engines.select_existing_paths(self.send(name).map { |p| File.join(directory, p) })
end
def add_plugin_locale_paths
locale_path = File.join(directory, 'locales')
return unless File.exists?(locale_path)
locale_files = Dir[File.join(locale_path, '*.{rb,yml}')]
return if locale_files.blank?
first_app_element =
I18n.load_path.select{ |e| e =~ /^#{ RAILS_ROOT }/ }.reject{ |e| e =~ /^#{ RAILS_ROOT }\/vendor\/plugins/ }.first
app_index = I18n.load_path.index(first_app_element) || - 1
I18n.load_path.insert(app_index, *locale_files)
end
# The path to this plugin's public files
def public_asset_directory
"#{File.basename(Engines.public_directory)}/#{name}"
end
# The directory containing this plugin's migrations (<tt>plugin/db/migrate</tt>)
def migration_directory
File.join(self.directory, 'db', 'migrate')
end
# Returns the version number of the latest migration for this plugin. Returns
# nil if this plugin has no migrations.
def latest_migration
migrations.last
end
# Returns the version numbers of all migrations for this plugin.
def migrations
migrations = Dir[migration_directory+"/*.rb"]
migrations.map { |p| File.basename(p).match(/0*(\d+)\_/)[1].to_i }.sort
end
# Migrate this plugin to the given version. See Engines::Plugin::Migrator for more
# information.
def migrate(version = nil)
Engines::Plugin::Migrator.migrate_plugin(self, version)
end
end
end