Require relative to the load path instead of using the more convoluted approach of File.join(File.dirname(__FILE__), ...).

Also, don't ever muck with the load paths or rubygems without first
trying to require the library without doing so.
This commit is contained in:
Chris Eppstein 2009-09-02 19:47:01 -07:00
parent 60ad1e2425
commit b13fd43a2e
26 changed files with 75 additions and 58 deletions

View File

@ -12,7 +12,8 @@ end
require 'rubygems' require 'rubygems'
require 'rake' require 'rake'
require 'lib/compass' $:.unshift File.join(File.dirname(__FILE__), 'lib')
require 'compass'
# ----- Default: Testing ------ # ----- Default: Testing ------

View File

@ -1,8 +1,19 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# The compass command line utility # The compass command line utility
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'compass')) begin
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'compass', 'exec')) retried = false
require 'compass'
require 'compass/exec'
rescue LoadError
if retried
raise
else
$: << File.join(File.dirname(__FILE__), '..', 'lib')
retried = true
retry
end
end
command = Compass::Exec::Compass.new(ARGV) command = Compass::Exec::Compass.new(ARGV)
exit command.run! exit command.run!

View File

@ -1,8 +1,8 @@
module Compass module Compass
end end
['dependencies', 'sass_extensions', 'core_ext', 'version', 'errors'].each do |file| %w(dependencies sass_extensions core_ext version errors).each do |lib|
require File.join(File.dirname(__FILE__), 'compass', file) require "compass/#{lib}"
end end
module Compass module Compass
@ -16,6 +16,6 @@ module Compass
module_function :base_directory, :lib_directory module_function :base_directory, :lib_directory
end end
require File.join(File.dirname(__FILE__), 'compass', 'configuration') %w(configuration frameworks app_integration).each do |lib|
require File.join(File.dirname(__FILE__), 'compass', 'frameworks') require "compass/#{lib}"
require File.join(File.dirname(__FILE__), 'compass', 'app_integration') end

View File

@ -1,3 +1,3 @@
%w(stand_alone rails merb).each do |lib| %w(stand_alone rails merb).each do |lib|
require File.join(File.dirname(__FILE__), 'app_integration', lib) require "compass/app_integration/#{lib}"
end end

View File

@ -1 +1 @@
require File.join(File.dirname(__FILE__), 'merb', 'runtime') if defined?(Merb::Plugins) require 'compass/app_integration/merb/runtime' if defined?(Merb::Plugins)

View File

@ -1,8 +1,8 @@
%w(configuration_defaults installer).each do |lib| %w(configuration_defaults installer).each do |lib|
require File.join(File.dirname(__FILE__), 'rails', lib) require "compass/app_integration/rails/#{lib}"
end end
require File.join(File.dirname(__FILE__), 'rails', 'runtime') if defined?(ActionController::Base) require 'compass/app_integration/rails/runtime' if defined?(ActionController::Base)

View File

@ -2,7 +2,7 @@ unless defined?(Compass::RAILS_LOADED)
Compass::RAILS_LOADED = true Compass::RAILS_LOADED = true
%w(action_controller sass_plugin urls).each do |lib| %w(action_controller sass_plugin urls).each do |lib|
require File.join(File.dirname(__FILE__), lib) require "compass/app_integration/rails/#{lib}"
end end
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug? # Wierd that this has to be re-included to pick up sub-modules. Ruby bug?

View File

@ -1,3 +1,3 @@
['configuration_defaults', 'installer'].each do |lib| %w(configuration_defaults installer).each do |lib|
require File.join(File.dirname(__FILE__), 'stand_alone', lib) require "compass/app_integration/stand_alone/#{lib}"
end end

View File

@ -1,6 +1,5 @@
require 'fileutils' require 'fileutils'
require File.join(File.dirname(__FILE__), 'stamp_pattern') require 'compass/commands/stamp_pattern'
require File.join(File.dirname(__FILE__), 'update_project')
module Compass module Compass
module Commands module Commands

View File

@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), 'project_base') require 'compass/commands/project_base'
require File.join(File.dirname(__FILE__), 'update_project') require 'compass/commands/update_project'
require File.join(File.dirname(__FILE__), '..', 'grid_builder') require 'compass/grid_builder'
module Compass module Compass
module Commands module Commands

View File

@ -1,4 +1,4 @@
require File.join(Compass.lib_directory, 'compass', 'installers') require 'compass/installers'
module Compass module Compass
module Commands module Commands

View File

@ -1,7 +1,7 @@
require 'fileutils' require 'fileutils'
require 'pathname' require 'pathname'
require File.join(File.dirname(__FILE__), 'base') require 'compass/commands/base'
require File.join(File.dirname(__FILE__), 'installer_command') require 'compass/commands/installer_command'
module Compass module Compass
module Commands module Commands

View File

@ -1,6 +1,6 @@
require 'fileutils' require 'fileutils'
require File.join(File.dirname(__FILE__), 'base') require 'compass/commands/base'
require File.join(File.dirname(__FILE__), 'update_project') require 'compass/commands/update_project'
module Compass module Compass
module Commands module Commands

View File

@ -1,5 +1,5 @@
require File.join(File.dirname(__FILE__), 'project_base') require 'compass/commands/project_base'
require File.join(Compass.lib_directory, 'compass', 'compiler') require 'compass/compiler'
module Compass module Compass
module Commands module Commands

View File

@ -1,5 +1,5 @@
require File.join(File.dirname(__FILE__), 'project_base') require 'compass/commands/project_base'
require File.join(File.dirname(__FILE__), 'update_project') require 'compass/commands/update_project'
module Compass module Compass
module Commands module Commands
@ -11,7 +11,7 @@ module Compass
end end
def perform def perform
require File.join(File.dirname(__FILE__), '..', 'validator') require 'compass/validator'
UpdateProject.new(working_path, options).perform UpdateProject.new(working_path, options).perform
Validator.new(project_css_subdirectory).validate() Validator.new(project_css_subdirectory).validate()
end end

View File

@ -1,7 +1,7 @@
require 'fileutils' require 'fileutils'
require 'pathname' require 'pathname'
require File.join(File.dirname(__FILE__), 'base') require 'compass/commands/base'
require File.join(File.dirname(__FILE__), 'update_project') require 'compass/commands/update_project'
module Compass module Compass
module Commands module Commands
@ -19,7 +19,12 @@ module Compass
puts ">>> Compass is watching for changes. Press Ctrl-C to Stop." puts ">>> Compass is watching for changes. Press Ctrl-C to Stop."
require File.join(Compass.lib_directory, 'vendor', 'fssm') begin
require 'fssm'
rescue LoadError
$: << File.join(Compass.lib_directory, 'vendor')
retry
end
FSSM.monitor do |monitor| FSSM.monitor do |monitor|
Compass.configuration.sass_load_paths.each do |load_path| Compass.configuration.sass_load_paths.each do |load_path|

View File

@ -1,4 +1,4 @@
require File.join(File.dirname(__FILE__), 'project_base') require 'compass/commands/project_base'
module Compass module Compass
module Commands module Commands

View File

@ -34,5 +34,5 @@ module Compass
end end
['adapters', 'comments', 'defaults', 'helpers', 'inheritance', 'serialization', 'data'].each do |lib| ['adapters', 'comments', 'defaults', 'helpers', 'inheritance', 'serialization', 'data'].each do |lib|
require File.join(File.dirname(__FILE__), 'configuration', lib) require "compass/configuration/#{lib}"
end end

View File

@ -1,8 +1,6 @@
unless defined?(Sass) begin
begin
require 'sass' require 'sass'
rescue LoadError rescue LoadError
require 'rubygems' require 'rubygems'
require 'sass' require 'sass'
end
end end

View File

@ -1,8 +1,8 @@
require File.join(Compass.lib_directory, 'compass', 'dependencies') require 'compass/dependencies'
require 'optparse' require 'optparse'
require File.join(Compass.lib_directory, 'compass', 'logger') require 'compass/logger'
require File.join(Compass.lib_directory, 'compass', 'errors') require 'compass/errors'
require File.join(Compass.lib_directory, 'compass', 'actions') require 'compass/actions'
module Compass module Compass
module Exec module Exec
@ -245,6 +245,8 @@ END
end end
end end
Dir.glob(File.join(File.dirname(__FILE__), 'commands', "*.rb")).each do |file| %w(base generate_grid_background list_frameworks project_base
require file update_project watch_project create_project installer_command
print_version stamp_pattern validate_project write_configuration).each do |lib|
require "compass/commands/#{lib}"
end end

View File

@ -1,3 +1,3 @@
%w(manifest template_context base).each do |f| %w(manifest template_context base).each do |f|
require File.join(File.dirname(__FILE__), 'installers', f) require "compass/installers/#{f}"
end end

View File

@ -1,5 +1,5 @@
module Compass::SassExtensions module Compass::SassExtensions
end end
require File.join(File.dirname(__FILE__), 'sass_extensions', 'functions') require 'compass/sass_extensions/functions'
require File.join(File.dirname(__FILE__), 'sass_extensions', 'monkey_patches') require 'compass/sass_extensions/monkey_patches'

View File

@ -1,8 +1,8 @@
module Compass::SassExtensions::Functions module Compass::SassExtensions::Functions
end end
['selectors', 'enumerate', 'urls', 'display', 'inline_image'].each do |func| %w(selectors enumerate urls display inline_image).each do |func|
require File.join(File.dirname(__FILE__), 'functions', func) require "compass/sass_extensions/functions/#{func}"
end end
module Sass::Script::Functions module Sass::Script::Functions

View File

@ -1,3 +1,3 @@
['stylesheet_updating'].each do |patch| %w(stylesheet_updating).each do |patch|
require File.join(File.dirname(__FILE__), 'monkey_patches', patch) require "compass/sass_extensions/monkey_patches/#{patch}"
end end

2
lib/vendor/fssm.rb vendored
View File

@ -16,7 +16,6 @@ module FSSM
end end
end end
$:.unshift(File.dirname(__FILE__))
require 'pathname' require 'pathname'
require 'fssm/ext' require 'fssm/ext'
require 'fssm/support' require 'fssm/support'
@ -26,5 +25,4 @@ require 'fssm/monitor'
require "fssm/backends/#{FSSM::Support.backend.downcase}" require "fssm/backends/#{FSSM::Support.backend.downcase}"
FSSM::Backends::Default = FSSM::Backends.const_get(FSSM::Support.backend) FSSM::Backends::Default = FSSM::Backends.const_get(FSSM::Support.backend)
$:.shift

View File

@ -1,5 +1,8 @@
need_gems = false need_gems = false
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
$:.unshift(lib_dir) unless $:.include?(lib_dir)
# allows testing with edge Haml by creating a test/haml symlink # allows testing with edge Haml by creating a test/haml symlink
linked_haml = File.dirname(__FILE__) + '/haml' linked_haml = File.dirname(__FILE__) + '/haml'