Skip to content

Commit

Permalink
Allow the application to access rake tasks belonging to gems used by …
Browse files Browse the repository at this point in the history
…Refinery. Should fall back to the original way of doing things if there's a problem with it.
  • Loading branch information
parndt committed Dec 10, 2009
1 parent 416ac26 commit 9bbf11e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
17 changes: 15 additions & 2 deletions Rakefile
@@ -1,19 +1,32 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require(File.join(File.dirname(__FILE__), 'config', 'boot'))
begin
# Load up the environment instead of just the boot file because we want all of the tasks available.
require(File.join(File.dirname(__FILE__), 'config', 'environment'))
rescue
# Load up the boot file instead because there's something wrong with the environment.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
end

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

require 'tasks/rails'

# When running Refinery from a gem we lose the rake tasks, so add them back in:
unless REFINERY_ROOT == RAILS_ROOT
# Load any custom rakefile extensions (for the gem only)
Dir[File.join(REFINERY_ROOT, %w(vendor plugins * ** tasks ** *.rake))].sort.each { |ext| load ext }
end

# We also need to load in the rake tasks from gem plugins whether Refinery is a gem or not:
if defined?($refinery_gem_plugin_lib_paths) && !$refinery_gem_plugin_lib_paths.nil?
$refinery_gem_plugin_lib_paths.each do |path|
Dir[File.join(path, %w(tasks ** *.rake))].sort.each { |ext| load ext }
end
end

desc 'Removes trailing whitespace'
task :whitespace do
sh %{find . -name '*.*rb' -exec sed -i '' 's/\t/ /g' {} \\; -exec sed -i '' 's/ *$//g' {} \\; }
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.9.5.24
0.9.5.25
3 changes: 3 additions & 0 deletions bin/refinery-update-core
Expand Up @@ -17,6 +17,9 @@ unless RAILS_ROOT.nil? or RAILS_ROOT.length == 0
# copy in any new migrations.
FileUtils::cp Dir[File.join(REFINERY_ROOT, %w(db migrate *.rb))], File.join(RAILS_ROOT, %w(db migrate))

# replace rakefile.
FileUtils::cp File.join(REFINERY_ROOT, %w(Rakefile)), File.join(RAILS_ROOT, %w(Rakefile))

# read in the config files
app_config = File.open(File.join(RAILS_ROOT, %w(config environment.rb)), "r").read
environment_updated = false
Expand Down
16 changes: 9 additions & 7 deletions vendor/plugins/refinery/lib/refinery/initializer.rb
Expand Up @@ -13,15 +13,17 @@ def default_plugin_paths
end
end
if defined? Rails::Plugin::Loader
class GemedPluginLoader < Rails::Plugin::Loader
class PluginLoader < Rails::Plugin::Loader
def add_plugin_load_paths
super
# add plugin lib paths to the $LOAD_PATH so that rake tasks etc. can be run when using a gem.
plugins.each do |plugin|
plugin.load_paths.reject { |path| path.scan(/refinerycms.+?vendor\/plugins\/.+?\/lib/).empty? }.each do |path|
$LOAD_PATH.unshift path
end
# add plugin lib paths to the $LOAD_PATH so that rake tasks etc. can be run when using a gem for refinery or gems for plugins.
search_for = Regexp.new(File.join('(', REFINERY_ROOT, %w(vendor plugins \)? .+? lib)))
paths = plugins.collect{ |plugin| plugin.load_paths }.flatten.reject{|path| path.scan(search_for).empty? or path.include?('/rails-') }
paths = paths.reject{ |path| path.include?(REFINERY_ROOT) } if REFINERY_ROOT == RAILS_ROOT # superfluous when not in gem.
($refinery_gem_plugin_lib_paths = paths).each do |path|
$LOAD_PATH.unshift path
end
$LOAD_PATH.uniq!
end
end
end
Expand All @@ -30,7 +32,7 @@ class Initializer < Rails::Initializer
def self.run(command = :process, configuration = Configuration.new)
Rails.configuration = configuration
configuration.reload_plugins = true if RAILS_ENV =~ /development/ and REFINERY_ROOT == RAILS_ROOT # seems to work, don't in gem.
configuration.plugin_loader = Refinery::GemedPluginLoader unless REFINERY_ROOT == RAILS_ROOT # only do this in a gem.
configuration.plugin_loader = Refinery::PluginLoader
super
end

Expand Down

0 comments on commit 9bbf11e

Please sign in to comment.