Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rewired how Refinery gets access to its core components when installe…

…d as a gem vs as a clone. This solves some problems that people were having with friendly_id (among other plugins installed via gems) being included by plugins that complained before it was possible to run rake gems:install to fix it.
  • Loading branch information...
commit 5187f54f86d483b6585f636197ad2165399ba62d 1 parent f2d2836
@parndt parndt authored
View
2  Gemfile
@@ -3,7 +3,7 @@
#===REFINERY REQUIRED GEMS===
source "http://rubygems.org"
gem "aasm", ">= 2.1.3", :require => "aasm"
-gem "friendly_id", ">= 2.2.2", :require => "friendly_id"
+gem "friendly_id", ">= 2.3.2", :require => "friendly_id"
gem "hpricot", ">= 0.8.1", :require => "hpricot"
gem "slim_scrooge", ">= 1.0.5", :require => "slim_scrooge"
gem "will_paginate", ">= 2.3.11", :require => "will_paginate"
View
9 Rakefile
@@ -6,9 +6,8 @@ begin
require File.join(File.dirname(__FILE__), 'config', 'environment')
rescue Exception
# Log the exception to the console/logfile.
- puts "*** Couldn't load the config/environment file because something went wrong. Trace below: ***"
- puts $!.backtrace
- puts "\n*** So, we'll attempt to load in config/boot instead... ***"
+ puts "*** Couldn't load the config/environment file because something went wrong... ***"
+ puts "*** Don't worry, we'll do it the normal way and load in config/boot instead... ***"
# Load up the boot file instead because there's something wrong with the environment.
require File.join(File.dirname(__FILE__), 'config', 'boot')
@@ -23,12 +22,12 @@ require 'tasks/rails'
# Because we use plugins that are shipped via gems, we lose their rake tasks.
# So here, we find them (if there are any) and include them into rake.
extra_rake_tasks = []
-if Refinery.is_a_gem
+if defined?(Refinery) && Refinery.is_a_gem
extra_rake_tasks << Dir[Refinery.root.join("vendor", "plugins", "*", "**", "tasks", "**", "*", "*.rake")].sort
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?
+if $refinery_gem_plugin_lib_paths.present?
extra_rake_tasks << $refinery_gem_plugin_lib_paths.collect {|path| Dir[File.join(%W(#{path} tasks ** *.rake))].sort}
end
View
2  VERSION
@@ -1 +1 @@
-0.9.6.13
+0.9.6.14
View
17 config/application.rb
@@ -1,4 +1,4 @@
-if defined?(Rails::Application)
+if defined?(Rails::Application) # e.g. Rails 3
module Refinery
class Application < Rails::Application
config.action_controller.session = {
@@ -8,7 +8,7 @@ class Application < Rails::Application
end
def gem_version
- #0.9.6
+ #"0.9.6.14"
end
end
else
@@ -21,21 +21,20 @@ def gem_version
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
# Freeze to a specific version of refinerycms when running as a gem
- # REFINERY_GEM_VERSION = '0.9.6.13' unless defined? REFINERY_GEM_VERSION
+ # REFINERY_GEM_VERSION = '0.9.6.14' unless defined? REFINERY_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
- eval("#{(defined? Refinery::Initializer) ? Refinery : Rails}::Initializer").run do |config|
+ # require the refinery initializer.
+ require Refinery.root.join("lib", "refinery_initializer").to_s
+
+ Refinery::Initializer.run do |config|
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# See Rails::Configuration for more options.
- # Skip frameworks you're not going to use (only works if using vendor/rails).
- # To use Rails without a database, you must remove the Active Record framework
- # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
-
# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
# :all can be used as a placeholder for all plugins not explicitly named
@@ -78,7 +77,7 @@ def gem_version
#===REFINERY REQUIRED GEMS===
config.gem "bundler", :version => ">= 0.9.4"
config.gem "rake", :version => ">= 0.8.3", :lib => "rake"
- config.gem "friendly_id", :version => ">= 2.2.2", :lib => "friendly_id"
+ config.gem "friendly_id", :version => ">= 2.3.2", :lib => "friendly_id"
config.gem "will_paginate", :version => ">= 2.3.11", :lib => "will_paginate"
config.gem "rails", :version => ">= 2.3.5", :lib => "rails"
config.gem "aasm", :version => ">= 2.1.3", :lib => "aasm"
View
8 config/preinitializer.rb
@@ -1,12 +1,8 @@
require 'pathname'
-
-# until Rails 3
-# ENV["GEM_HOME"] = File.expand_path('../../vendor/bundler_gems', __FILE__)
-
# pick the refinery root path
rails_root = (defined?(Rails.root) ? Rails.root : Pathname.new(RAILS_ROOT)).cleanpath
-if (non_gem_path = rails_root.join("lib", "refinery_initializer.rb")).exist?
- require non_gem_path.to_s
+if (non_gem_path = rails_root.join("vendor", "plugins", "refinery", "lib", "refinery.rb")).exist?
+ require non_gem_path.realpath.to_s
else
require 'rubygems'
version = if defined? REFINERY_GEM_VERSION
View
18 lib/refinery_initializer.rb
@@ -1,23 +1,23 @@
require 'pathname'
root_directory = Pathname.new(File.expand_path(File.dirname(__FILE__) << "/.."))
-rails_root = ((defined?(Rails.root) && Rails.root.realpath.length > 0) ? Rails.root : Pathname.new(RAILS_ROOT))
+rails_root = ((defined?(Rails.root) && Rails.root.realpath.to_s.length > 0) ? Rails.root : Pathname.new(RAILS_ROOT))
if (non_gem_refinery = rails_root.join("vendor", "plugins", "refinery", "lib", "refinery.rb")).exist?
require non_gem_refinery.realpath.to_s # this won't exist when using a gem.
+ Refinery.is_a_gem = false
else
- require root_directory.join("vendor", "plugins", "refinery", "lib", "refinery.rb").realpath.to_s
+ require root_directory.join("vendor", "plugins", "refinery", "lib", "refinery").realpath.to_s
+ Refinery.is_a_gem = true
end
# Now we need to set some things that are used by the rest of the application.
Refinery.root = root_directory.cleanpath
-if (Refinery.is_a_gem = (Refinery.root.realpath != rails_root.realpath))
- # If Refinery is installed from a gem then we need to load in a few extra files.
- $LOAD_PATH.unshift Refinery.root.join("vendor", "plugins").to_s
- $LOAD_PATH.unshift Refinery.root.join("vendor", "plugins", "refinery", "lib").to_s
+$LOAD_PATH.unshift Refinery.root.join("vendor", "plugins").to_s
+$LOAD_PATH.unshift Refinery.root.join("vendor", "plugins", "refinery", "lib").to_s
+$LOAD_PATH.uniq!
- # We also need the refinery initializer when using a gem because this won't be autoloaded.
- require 'refinery/initializer'
-end
+# We also need the other refinery initializer.
+require 'refinery/initializer'
# Pull in attachment_fu patch for windows
require 'refinery/attachment_fu_patch' if RUBY_PLATFORM =~ /mswin/
View
2  readme.md
@@ -30,7 +30,7 @@ Unlike other content managers, Refinery is truly aimed at the end user making it
Refinery runs using a number of gems which (as of Refinery version 0.9.5.29) are outlined below:
* [rake >= 0.8.3](http://rubygems.org/gems/rake)
-* [friendly_id >= 2.2.2](http://rubygems.org/gems/friendly_id)
+* [friendly_id >= 2.3.2](http://rubygems.org/gems/friendly_id)
* [will_paginate >= 2.3.11](http://rubygems.org/gems/will_paginate)
* [rails >= 2.3.5](http://rubygems.org/gems/rails)
* [aasm >= 2.1.3](http://rubygems.org/gems/aasm)
View
3  vendor/plugins/refinery/lib/refinery.rb
@@ -2,6 +2,9 @@ module Refinery
class << self
attr_accessor :root
+ def root
+ @root ||= Pathname.new(File.dirname(__FILE__).split("vendor").first.to_s)
+ end
attr_accessor :is_a_gem
end
View
84 vendor/plugins/refinery/lib/refinery/initializer.rb
@@ -1,6 +1,6 @@
+# Try to include the rails initializer. If this isn't in a gem, this will fail.
if Refinery.is_a_gem
begin
- # Try to include the rails initializer. If this isn't in a gem, this will fail.
require 'initializer'
rescue LoadError => load_error
# we don't need to do anything.
@@ -10,39 +10,71 @@
module Refinery
- if defined? Rails::Configuration
- class Configuration < Rails::Configuration
- def default_plugin_paths
- paths = super.push(Refinery.root.join("vendor", "plugins")).uniq
+ class Configuration < Rails::Configuration
+ def default_plugin_paths
+ paths = super.push(Refinery.root.join("vendor", "plugins").to_s).uniq
+ end
+ end if defined?(Rails::Configuration)
+
+ class PluginLoader < Rails::Plugin::Loader
+ def add_plugin_load_paths
+ # call rails' 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 for refinery or gems for plugins.
+ search_for = Regexp.new(File.join(%W(\( #{Refinery.root.join("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.to_s) } unless Refinery.is_a_gem
+ paths.uniq!
+ ($refinery_gem_plugin_lib_paths = paths).each do |path|
+ $LOAD_PATH.unshift path
end
+ $LOAD_PATH.uniq!
end
- end
- if defined? Rails::Plugin::Loader
- class PluginLoader < Rails::Plugin::Loader
- def add_plugin_load_paths
+ # We need to overload this because some gems raise errors if they're not installed
+ # rather than just letting the framework handle it so we need to trap them here.
+ def ensure_all_registered_plugins_are_loaded!
+ begin
super
- # 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(%W(\( #{Refinery.root.join("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.to_s) } unless Refinery.is_a_gem
- paths.uniq!
- ($refinery_gem_plugin_lib_paths = paths).each do |path|
- $LOAD_PATH.unshift path
- end
- $LOAD_PATH.uniq!
+ rescue LoadError => load_error
+ raise LoadError, load_error.to_s unless load_error.to_s =~ /friendly_id|aasm|will_paginate/
end
end
- end
+ end if defined?(Rails::Plugin::Loader)
- if defined? Rails::Initializer
- class Initializer < Rails::Initializer
- def self.run(command = :process, configuration = Configuration.new)
- configuration.plugin_loader = Refinery::PluginLoader
- Rails.configuration = configuration
- super
+ class Initializer < Rails::Initializer
+ def self.run(command = :process, configuration = Configuration.new)
+ configuration.plugin_loader = Refinery::PluginLoader
+ Rails.configuration = configuration
+
+ # call rails' run
+ super
+ end
+
+ def load_plugins
+ # inject all gems that manipulate ActiveRecord::Base into the application
+ # and stub any calls that are dangerous.
+ ::ActiveRecord::Base.module_eval do
+ begin
+ require 'friendly_id'
+ require 'will_paginate'
+ require 'aasm'
+ rescue LoadError => load_error
+ # this will stop us running rake gems:install which we don't really want so just trap this error.
+ puts "*** Trapping error caused by missing gems ***"
+ end
+
+ # Stub has_friendly_id. This will get overriden when/if included.
+ # The config will still complain that the gem is missing but this allows it to do so.
+ def self.has_friendly_id(column, options = {}, &block)
+ super if defined? super and table_exists?
+ end
end
+
+ # call rails' load_plugins
+ super
end
- end
+ end if defined?(Rails::Initializer)
end
Please sign in to comment.
Something went wrong with that request. Please try again.