Permalink
Browse files

Use a consistent load path to avoid double requires. Fix some scatter…

…ed Ruby warnings.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6057 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 4ac332f commit 0eacdcf9a3e37e05f47a4ded7f0a4aff3b65fbe4 @jeremy jeremy committed Jan 28, 2007
Showing with 89 additions and 106 deletions.
  1. +4 −2 actionpack/lib/action_controller.rb
  2. +1 −1 actionpack/lib/action_controller/assertions/response_assertions.rb
  3. +1 −1 actionpack/lib/action_controller/assertions/selector_assertions.rb
  4. +2 −2 actionpack/lib/action_controller/assertions/tag_assertions.rb
  5. +3 −0 actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb
  6. +1 −1 actionpack/lib/action_controller/integration.rb
  7. +1 −1 actionpack/lib/action_controller/mime_type.rb
  8. +1 −0 actionpack/lib/action_controller/request.rb
  9. +2 −2 actionpack/lib/action_controller/routing.rb
  10. +3 −3 actionpack/lib/action_controller/test_process.rb
  11. +3 −4 actionpack/lib/action_controller/vendor/html-scanner/html/document.rb
  12. +10 −5 actionpack/lib/action_controller/vendor/html-scanner/html/selector.rb
  13. +1 −2 actionpack/lib/action_view.rb
  14. +8 −6 actionpack/lib/action_view/base.rb
  15. +1 −1 actionpack/lib/action_view/helpers/active_record_helper.rb
  16. +2 −2 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  17. +2 −2 actionpack/lib/action_view/helpers/form_helper.rb
  18. +1 −1 actionpack/lib/action_view/helpers/form_options_helper.rb
  19. +1 −1 actionpack/lib/action_view/helpers/form_tag_helper.rb
  20. +1 −1 actionpack/lib/action_view/helpers/java_script_macros_helper.rb
  21. +2 −2 actionpack/lib/action_view/helpers/javascript_helper.rb
  22. +2 −2 actionpack/lib/action_view/helpers/prototype_helper.rb
  23. +1 −1 actionpack/lib/action_view/helpers/scriptaculous_helper.rb
  24. +2 −14 actionpack/lib/action_view/helpers/text_helper.rb
  25. +1 −1 actionpack/lib/action_view/helpers/url_helper.rb
  26. +1 −1 actionpack/test/activerecord/active_record_store_test.rb
  27. +2 −2 actionpack/test/controller/assert_select_test.rb
  28. +2 −2 actionpack/test/controller/raw_post_test.rb
  29. +3 −4 actionpack/test/controller/routing_test.rb
  30. +2 −2 actionpack/test/controller/selector_test.rb
  31. +1 −8 actionpack/test/template/active_record_helper_test.rb
  32. +1 −1 actionpack/test/template/asset_tag_helper_test.rb
  33. +2 −2 actionpack/test/template/benchmark_helper_test.rb
  34. +3 −5 actionpack/test/template/compiled_templates_test.rb
  35. +1 −2 actionpack/test/template/date_helper_test.rb
  36. +1 −1 actionpack/test/template/deprecated_helper_test.rb
  37. +1 −1 actionpack/test/template/deprecated_instance_variables_test.rb
  38. +1 −1 actionpack/test/template/form_helper_test.rb
  39. +1 −1 actionpack/test/template/form_options_helper_test.rb
  40. +1 −1 actionpack/test/template/form_tag_helper_test.rb
  41. +1 −1 actionpack/test/template/java_script_macros_helper_test.rb
  42. +1 −1 actionpack/test/template/javascript_helper_test.rb
  43. +1 −2 actionpack/test/template/number_helper_test.rb
  44. +1 −1 actionpack/test/template/prototype_helper_test.rb
  45. +2 −2 actionpack/test/template/scriptaculous_helper_test.rb
  46. +1 −1 actionpack/test/template/tag_helper_test.rb
  47. +1 −1 actionpack/test/template/text_helper_test.rb
  48. +1 −5 actionpack/test/template/url_helper_test.rb
@@ -26,14 +26,16 @@
unless defined?(ActiveSupport)
begin
- $:.unshift(File.dirname(__FILE__) + "/../../activesupport/lib")
- require 'active_support'
+ $:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib"
+ require 'active_support'
rescue LoadError
require 'rubygems'
require_gem 'activesupport'
end
end
+$:.unshift "#{File.dirname(__FILE__)}/action_controller/vendor/html-scanner"
+
require 'action_controller/base'
require 'action_controller/deprecated_redirects'
require 'action_controller/request'
@@ -1,5 +1,5 @@
require 'rexml/document'
-require File.dirname(__FILE__) + "/../vendor/html-scanner/html/document"
+require 'html/document'
module ActionController
module Assertions
@@ -4,7 +4,7 @@
#++
require 'rexml/document'
-require File.dirname(__FILE__) + "/../vendor/html-scanner/html/document"
+require 'html/document'
module ActionController
module Assertions
@@ -1,5 +1,5 @@
require 'rexml/document'
-require File.dirname(__FILE__) + "/../vendor/html-scanner/html/document"
+require 'html/document'
module ActionController
module Assertions
@@ -114,4 +114,4 @@ def assert_no_tag(*opts)
end
end
end
-end
+end
@@ -1,5 +1,8 @@
class CGI #:nodoc:
module QueryExtension
+ # Remove the old initialize_query method before redefining it.
+ remove_method :initialize_query
+
# Initialize the data from the query.
#
# Handles multipart forms (in particular, forms that involve file uploads).
@@ -72,7 +72,7 @@ def reset!
self.remote_addr = "127.0.0.1"
self.accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
- unless @named_routes_configured
+ unless defined? @named_routes_configured
# install the named routes in this session instance.
klass = class<<self; self; end
Routing::Routes.named_routes.install(klass)
@@ -142,4 +142,4 @@ def ==(mime_type)
end
end
-require File.dirname(__FILE__) + "/mime_types"
+require 'action_controller/mime_types'
@@ -3,6 +3,7 @@ module ActionController
# CgiRequest and TestRequest
class AbstractRequest
cattr_accessor :relative_url_root
+ remove_method :relative_url_root
# Returns the hash of environment variables for this request,
# such as { 'RAILS_ENV' => 'production' }.
@@ -507,9 +507,9 @@ def defaults
end
end
end
-
+
def matches_controller_and_action?(controller, action)
- unless @matching_prepared
+ unless defined? @matching_prepared
@controller_requirement = requirement_for(:controller)
@action_requirement = requirement_for(:action)
@matching_prepared = true
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/assertions'
+require 'action_controller/assertions'
module ActionController #:nodoc:
class Base
@@ -90,11 +90,11 @@ def remote_addr
end
def request_uri
- @request_uri || super()
+ @request_uri || super
end
def path
- @path || super()
+ @path || super
end
def assign_parameters(controller_path, action, parameters)
@@ -1,9 +1,8 @@
-require File.dirname(__FILE__) + '/tokenizer'
-require File.dirname(__FILE__) + '/node'
-require File.dirname(__FILE__) + '/selector'
+require 'html/tokenizer'
+require 'html/node'
+require 'html/selector'
module HTML #:nodoc:
-
# A top-level HTMl document. You give it a body of text, and it will parse that
# text into a tree of nodes.
class Document #:nodoc:
@@ -240,19 +240,24 @@ def initialize(selector, *values)
raise ArgumentError, "CSS expression cannot be empty" if selector.empty?
@source = ""
values = values[0] if values.size == 1 && values[0].is_a?(Array)
+
# We need a copy to determine if we failed to parse, and also
# preserve the original pass by-ref statement.
statement = selector.strip.dup
+
# Create a simple selector, along with negation.
simple_selector(statement, values).each { |name, value| instance_variable_set("@#{name}", value) }
+ @alternates = []
+ @depends = nil
+
# Alternative selector.
if statement.sub!(/^\s*,\s*/, "")
second = Selector.new(statement, values)
- (@alternates ||= []) << second
+ @alternates << second
# If there are alternate selectors, we group them in the top selector.
if alternates = second.instance_variable_get(:@alternates)
- second.instance_variable_set(:@alternates, nil)
+ second.instance_variable_set(:@alternates, [])
@alternates.concat alternates
end
@source << " , " << second.to_s
@@ -412,7 +417,7 @@ def match(element, first_only = false)
# If this selector is part of the group, try all the alternative
# selectors (unless first_only).
- if @alternates && (!first_only || !matches)
+ if !first_only || !matches
@alternates.each do |alternate|
break if matches && first_only
if subset = alternate.match(element, first_only)
@@ -796,8 +801,8 @@ def next_selector(statement, values)
second = Selector.new(statement, values)
# If there are alternate selectors, we group them in the top selector.
if alternates = second.instance_variable_get(:@alternates)
- second.instance_variable_set(:@alternates, nil)
- (@alternates ||= []).concat alternates
+ second.instance_variable_set(:@alternates, [])
+ @alternates.concat alternates
end
second
end
@@ -21,12 +21,11 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-$:.unshift(File.dirname(__FILE__) + "/action_view/vendor")
require 'action_view/base'
require 'action_view/partials'
ActionView::Base.class_eval do
include ActionView::Partials
end
-ActionView::Base.load_helpers(File.dirname(__FILE__) + "/action_view/helpers/")
+ActionView::Base.load_helpers
@@ -157,7 +157,7 @@ class Base
attr_accessor :controller
attr_reader :logger, :response, :headers
- attr_internal *ActionController::Base::DEPRECATED_INSTANCE_VARIABLES
+ attr_internal(*ActionController::Base::DEPRECATED_INSTANCE_VARIABLES)
# Specify trim mode for the ERB compiler. Defaults to '-'.
# See ERB documentation for suitable values.
@@ -210,12 +210,14 @@ module CompiledTemplates #:nodoc:
class ObjectWrapper < Struct.new(:value) #:nodoc:
end
- def self.load_helpers(helper_dir)#:nodoc:
- Dir.entries(helper_dir).sort.each do |helper_file|
- next unless helper_file =~ /^([a-z][a-z_]*_helper).rb$/
- require File.join(helper_dir, $1)
+ def self.load_helpers #:nodoc:
+ Dir.entries("#{File.dirname(__FILE__)}/helpers").sort.each do |file|
+ next unless file =~ /^([a-z][a-z_]*_helper).rb$/
+ require "action_view/helpers/#{$1}"
helper_module_name = $1.camelize
- class_eval("include ActionView::Helpers::#{helper_module_name}") if Helpers.const_defined?(helper_module_name)
+ if Helpers.const_defined?(helper_module_name)
+ include Helpers.const_get(helper_module_name)
+ end
end
end
@@ -1,5 +1,5 @@
require 'cgi'
-require File.dirname(__FILE__) + '/form_helper'
+require 'action_view/helpers/form_helper'
module ActionView
class Base
@@ -1,6 +1,6 @@
require 'cgi'
-require File.dirname(__FILE__) + '/url_helper'
-require File.dirname(__FILE__) + '/tag_helper'
+require 'action_view/helpers/url_helper'
+require 'action_view/helpers/tag_helper'
module ActionView
module Helpers #:nodoc:
@@ -1,6 +1,6 @@
require 'cgi'
-require File.dirname(__FILE__) + '/date_helper'
-require File.dirname(__FILE__) + '/tag_helper'
+require 'action_view/helpers/date_helper'
+require 'action_view/helpers/tag_helper'
module ActionView
module Helpers
@@ -1,6 +1,6 @@
require 'cgi'
require 'erb'
-require File.dirname(__FILE__) + '/form_helper'
+require 'action_view/helpers/form_helper'
module ActionView
module Helpers
@@ -1,5 +1,5 @@
require 'cgi'
-require File.dirname(__FILE__) + '/tag_helper'
+require 'action_view/helpers/tag_helper'
module ActionView
module Helpers
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/tag_helper'
+require 'action_view/helpers/tag_helper'
module ActionView
module Helpers
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/tag_helper'
-require File.dirname(__FILE__) + '/prototype_helper'
+require 'action_view/helpers/tag_helper'
+require 'action_view/helpers/prototype_helper'
module ActionView
module Helpers
@@ -860,7 +860,7 @@ def enumerate(enumerable, options = {}, &block)
add_variable_assignment!(options[:variable]) if options[:variable]
append_enumerable_function!("#{enumerable.to_s.camelize(:lower)}(#{method_args}function(#{yield_args}) {")
# only yield as many params as were passed in the block
- yield *options[:yield_args].collect { |p| JavaScriptVariableProxy.new(@generator, p) }[0..block.arity-1]
+ yield(*options[:yield_args].collect { |p| JavaScriptVariableProxy.new(@generator, p) }[0..block.arity-1])
add_return_statement! if options[:return]
@generator << '});'
end
@@ -889,4 +889,4 @@ def initialize(generator, pattern)
end
end
-require File.dirname(__FILE__) + '/javascript_helper'
+require 'action_view/helpers/javascript_helper'
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/javascript_helper'
+require 'action_view/helpers/javascript_helper'
module ActionView
module Helpers
@@ -1,4 +1,5 @@
-require File.dirname(__FILE__) + '/tag_helper'
+require 'action_view/helpers/tag_helper'
+require 'html/document'
module ActionView
module Helpers #:nodoc:
@@ -192,19 +193,6 @@ def strip_links(text)
text.gsub(/<a\b.*?>(.*?)<\/a>/mi, '\1')
end
- # Try to require the html-scanner library
- begin
- require 'html/tokenizer'
- require 'html/node'
- rescue LoadError
- # if there isn't a copy installed, use the vendor version in
- # ActionController
- $:.unshift File.join(File.dirname(__FILE__), "..", "..",
- "action_controller", "vendor", "html-scanner")
- require 'html/tokenizer'
- require 'html/node'
- end
-
VERBOTEN_TAGS = %w(form script plaintext) unless defined?(VERBOTEN_TAGS)
VERBOTEN_ATTRS = /^on/i unless defined?(VERBOTEN_ATTRS)
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/javascript_helper'
+require 'action_view/helpers/javascript_helper'
module ActionView
module Helpers #:nodoc:
@@ -128,7 +128,7 @@ def teardown
class SqlBypassActiveRecordStoreTest < ActiveRecordStoreTest
def session_class
- unless @session_class
+ unless defined? @session_class
@session_class = CGI::Session::ActiveRecordStore::SqlBypass
@session_class.connection = CGI::Session::ActiveRecordStore::Session.connection
end
@@ -3,8 +3,8 @@
# Under MIT and/or CC By license.
#++
-require File.dirname(__FILE__) + '/../abstract_unit'
-require File.dirname(__FILE__) + '/fake_controllers'
+require "#{File.dirname(__FILE__)}/../abstract_unit"
+require "#{File.dirname(__FILE__)}/fake_controllers"
unless defined?(ActionMailer)
@@ -1,7 +1,7 @@
-require 'test/unit'
+require "#{File.dirname(__FILE__)}/../abstract_unit"
require 'cgi'
require 'stringio'
-require File.dirname(__FILE__) + '/../../lib/action_controller/cgi_ext/raw_post_data_fix'
+require 'action_controller/cgi_ext/raw_post_data_fix'
class RawPostDataTest < Test::Unit::TestCase
def setup
@@ -1,6 +1,5 @@
-require File.dirname(__FILE__) + '/../abstract_unit'
-require 'test/unit'
-require File.dirname(__FILE__) + '/fake_controllers'
+require "#{File.dirname(__FILE__)}/../abstract_unit"
+require "#{File.dirname(__FILE__)}/fake_controllers"
require 'action_controller/routing'
RunTimeTests = ARGV.include? 'time'
@@ -789,7 +788,7 @@ def slash_segment(is_optional = false)
end
def default_route
- unless @default_route
+ unless defined?(@default_route)
@default_route = ROUTING::Route.new
@default_route.segments << (s = ROUTING::StaticSegment.new)
@@ -3,8 +3,8 @@
# Under MIT and/or CC By license.
#++
-require File.dirname(__FILE__) + '/../abstract_unit'
-require File.dirname(__FILE__) + '/fake_controllers'
+require "#{File.dirname(__FILE__)}/../abstract_unit"
+require "#{File.dirname(__FILE__)}/fake_controllers"
class SelectorTest < Test::Unit::TestCase
#
@@ -1,11 +1,4 @@
-require File.dirname(__FILE__) + '/../abstract_unit'
-require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
-require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_helper'
-require File.dirname(__FILE__) + '/../../lib/action_view/helpers/text_helper'
-require File.dirname(__FILE__) + '/../../lib/action_view/helpers/tag_helper'
-require File.dirname(__FILE__) + '/../../lib/action_view/helpers/url_helper'
-require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_tag_helper'
-# require File.dirname(__FILE__) + '/../../lib/action_view/helpers/active_record_helper'
+require "#{File.dirname(__FILE__)}/../abstract_unit"
class ActiveRecordHelperTest < Test::Unit::TestCase
include ActionView::Helpers::FormHelper
Oops, something went wrong.

0 comments on commit 0eacdcf

Please sign in to comment.