diff options
Diffstat (limited to 'actionpack')
44 files changed, 223 insertions, 203 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 9581442208..1d6e5455da 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -27,7 +27,9 @@ * Fixed RedCloth and BlueCloth shouldn't preload. Instead just assume that they're available if you want to use textilize and markdown and let autoload require them [DHH] -*2.2.1 [RC2] (November 14th, 2008)* +*2.2.2 (November 21st, 2008)* + +* I18n: translate number_to_human_size. Add storage_units: [Bytes, KB, MB, GB, TB] to your translations. #1448 [Yaroslav Markin] * Restore backwards compatible functionality for setting relative_url_root. Include deprecation diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index ff8ec0d2fc..5f87429aca 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -32,47 +32,63 @@ rescue LoadError end $:.unshift "#{File.dirname(__FILE__)}/action_controller/vendor/html-scanner" -require 'action_controller/vendor/rack' -require 'action_controller/base' -require 'action_controller/request' -require 'action_controller/rescue' -require 'action_controller/benchmarking' -require 'action_controller/flash' -require 'action_controller/filters' -require 'action_controller/layout' -require 'action_controller/mime_responds' -require 'action_controller/helpers' -require 'action_controller/cookies' -require 'action_controller/cgi_process' -require 'action_controller/caching' -require 'action_controller/verification' -require 'action_controller/streaming' -require 'action_controller/session_management' -require 'action_controller/http_authentication' -require 'action_controller/rack_process' -require 'action_controller/record_identifier' -require 'action_controller/request_forgery_protection' -require 'action_controller/headers' -require 'action_controller/translation' +module ActionController + # TODO: Review explicit to see if they will automatically be handled by + # the initilizer if they are really needed. + def self.load_all! + [Base, CgiRequest, CgiResponse, RackRequest, RackRequest, Http::Headers, UrlRewriter, UrlWriter] + end -require 'action_view' + autoload :AbstractRequest, 'action_controller/request' + autoload :AbstractResponse, 'action_controller/response' + autoload :Base, 'action_controller/base' + autoload :Benchmarking, 'action_controller/benchmarking' + autoload :Caching, 'action_controller/caching' + autoload :CgiRequest, 'action_controller/cgi_process' + autoload :CgiResponse, 'action_controller/cgi_process' + autoload :Cookies, 'action_controller/cookies' + autoload :Dispatcher, 'action_controller/dispatcher' + autoload :Filters, 'action_controller/filters' + autoload :Flash, 'action_controller/flash' + autoload :Helpers, 'action_controller/helpers' + autoload :HttpAuthentication, 'action_controller/http_authentication' + autoload :IntegrationTest, 'action_controller/integration' + autoload :Layout, 'action_controller/layout' + autoload :MimeResponds, 'action_controller/mime_responds' + autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes' + autoload :RackRequest, 'action_controller/rack_process' + autoload :RackResponse, 'action_controller/rack_process' + autoload :RecordIdentifier, 'action_controller/record_identifier' + autoload :RequestForgeryProtection, 'action_controller/request_forgery_protection' + autoload :Rescue, 'action_controller/rescue' + autoload :Resources, 'action_controller/resources' + autoload :Routing, 'action_controller/routing' + autoload :SessionManagement, 'action_controller/session_management' + autoload :StatusCodes, 'action_controller/status_codes' + autoload :Streaming, 'action_controller/streaming' + autoload :TestCase, 'action_controller/test_case' + autoload :TestProcess, 'action_controller/test_process' + autoload :Translation, 'action_controller/translation' + autoload :UrlRewriter, 'action_controller/url_rewriter' + autoload :UrlWriter, 'action_controller/url_rewriter' + autoload :Verification, 'action_controller/verification' -ActionController::Base.class_eval do - include ActionController::Flash - include ActionController::Filters - include ActionController::Layout - include ActionController::Benchmarking - include ActionController::Rescue - include ActionController::MimeResponds - include ActionController::Helpers - include ActionController::Cookies - include ActionController::Caching - include ActionController::Verification - include ActionController::Streaming - include ActionController::SessionManagement - include ActionController::HttpAuthentication::Basic::ControllerMethods - include ActionController::RecordIdentifier - include ActionController::RequestForgeryProtection - include ActionController::Translation + module Http + autoload :Headers, 'action_controller/headers' + end end + +class CGI + class Session + autoload :ActiveRecordStore, 'action_controller/session/active_record_store' + autoload :CookieStore, 'action_controller/session/cookie_store' + autoload :DRbStore, 'action_controller/session/drb_store' + autoload :MemCacheStore, 'action_controller/session/mem_cache_store' + end +end + +autoload :Mime, 'action_controller/mime_type' +autoload :Rack, 'action_controller/vendor/rack' + +ActionController.load_all! diff --git a/actionpack/lib/action_controller/assertions/response_assertions.rb b/actionpack/lib/action_controller/assertions/response_assertions.rb index e2e8bbdc71..7ab24389b8 100644 --- a/actionpack/lib/action_controller/assertions/response_assertions.rb +++ b/actionpack/lib/action_controller/assertions/response_assertions.rb @@ -1,6 +1,3 @@ -require 'rexml/document' -require 'html/document' - module ActionController module Assertions # A small suite of assertions that test responses from Rails applications. diff --git a/actionpack/lib/action_controller/assertions/selector_assertions.rb b/actionpack/lib/action_controller/assertions/selector_assertions.rb index bcbb570e4b..40ac572fdb 100644 --- a/actionpack/lib/action_controller/assertions/selector_assertions.rb +++ b/actionpack/lib/action_controller/assertions/selector_assertions.rb @@ -3,8 +3,7 @@ # Under MIT and/or CC By license. #++ -require 'rexml/document' -require 'html/document' +require 'action_controller/vendor/html-scanner' module ActionController module Assertions diff --git a/actionpack/lib/action_controller/assertions/tag_assertions.rb b/actionpack/lib/action_controller/assertions/tag_assertions.rb index 90ba3668fb..80249e0e83 100644 --- a/actionpack/lib/action_controller/assertions/tag_assertions.rb +++ b/actionpack/lib/action_controller/assertions/tag_assertions.rb @@ -1,6 +1,3 @@ -require 'rexml/document' -require 'html/document' - module ActionController module Assertions # Pair of assertions to testing elements in the HTML output of the response. @@ -127,4 +124,4 @@ module ActionController end end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index ad6562024a..041ff62a74 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -1,12 +1,4 @@ -require 'action_controller/mime_type' -require 'action_controller/request' -require 'action_controller/response' -require 'action_controller/routing' -require 'action_controller/resources' -require 'action_controller/url_rewriter' -require 'action_controller/status_codes' require 'action_view' -require 'drb' require 'set' module ActionController #:nodoc: @@ -1332,4 +1324,11 @@ module ActionController #:nodoc: close_session end end + + Base.class_eval do + include Flash, Filters, Layout, Benchmarking, Rescue, MimeResponds, Helpers + include Cookies, Caching, Verification, Streaming + include SessionManagement, HttpAuthentication::Basic::ControllerMethods + include RecordIdentifier, RequestForgeryProtection, Translation + end end diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index c4063dfb4b..b4d251eb3c 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -2,13 +2,6 @@ require 'fileutils' require 'uri' require 'set' -require 'action_controller/caching/pages' -require 'action_controller/caching/actions' -require 'action_controller/caching/sql_cache' -require 'action_controller/caching/sweeping' -require 'action_controller/caching/fragments' - - module ActionController #:nodoc: # Caching is a cheap way of speeding up slow applications by keeping the result of calculations, renderings, and database calls # around for subsequent requests. Action Controller affords you three approaches in varying levels of granularity: Page, Action, Fragment. @@ -31,6 +24,12 @@ module ActionController #:nodoc: # ActionController::Base.cache_store = :mem_cache_store, "localhost" # ActionController::Base.cache_store = MyOwnStore.new("parameter") module Caching + autoload :Actions, 'action_controller/caching/actions' + autoload :Fragments, 'action_controller/caching/fragments' + autoload :Pages, 'action_controller/caching/pages' + autoload :SqlCache, 'action_controller/caching/sql_cache' + autoload :Sweeping, 'action_controller/caching/sweeping' + def self.included(base) #:nodoc: base.class_eval do @@cache_store = nil @@ -63,10 +62,9 @@ module ActionController #:nodoc: end end - - private + private def cache_configured? self.class.cache_configured? end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_controller/cgi_process.rb b/actionpack/lib/action_controller/cgi_process.rb index fabacd9b83..45b51a7488 100644 --- a/actionpack/lib/action_controller/cgi_process.rb +++ b/actionpack/lib/action_controller/cgi_process.rb @@ -1,5 +1,4 @@ require 'action_controller/cgi_ext' -require 'action_controller/session/cookie_store' module ActionController #:nodoc: class Base diff --git a/actionpack/lib/action_controller/integration.rb b/actionpack/lib/action_controller/integration.rb index b3771c1ebc..333fb742e4 100644 --- a/actionpack/lib/action_controller/integration.rb +++ b/actionpack/lib/action_controller/integration.rb @@ -1,7 +1,3 @@ -require 'action_controller/test_case' -require 'action_controller/dispatcher' -require 'action_controller/test_process' - require 'stringio' require 'uri' diff --git a/actionpack/lib/action_controller/performance_test.rb b/actionpack/lib/action_controller/performance_test.rb index 85543fffae..d88180087d 100644 --- a/actionpack/lib/action_controller/performance_test.rb +++ b/actionpack/lib/action_controller/performance_test.rb @@ -1,4 +1,3 @@ -require 'action_controller/integration' require 'active_support/testing/performance' require 'active_support/testing/default' diff --git a/actionpack/lib/action_controller/rack_process.rb b/actionpack/lib/action_controller/rack_process.rb index e8ea3704a8..58d7b53e31 100644 --- a/actionpack/lib/action_controller/rack_process.rb +++ b/actionpack/lib/action_controller/rack_process.rb @@ -1,5 +1,4 @@ require 'action_controller/cgi_ext' -require 'action_controller/session/cookie_store' module ActionController #:nodoc: class RackRequest < AbstractRequest #:nodoc: diff --git a/actionpack/lib/action_controller/request_profiler.rb b/actionpack/lib/action_controller/request_profiler.rb index a6471d0c08..70bb77e7ac 100644 --- a/actionpack/lib/action_controller/request_profiler.rb +++ b/actionpack/lib/action_controller/request_profiler.rb @@ -1,5 +1,4 @@ require 'optparse' -require 'action_controller/integration' module ActionController class RequestProfiler diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index 7700b9d4d0..b5ea764911 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -669,7 +669,3 @@ module ActionController end end end - -class ActionController::Routing::RouteSet::Mapper - include ActionController::Resources -end diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 8d51e823a6..efd474097e 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -1,6 +1,5 @@ require 'cgi' require 'uri' -require 'action_controller/polymorphic_routes' require 'action_controller/routing/optimisations' require 'action_controller/routing/routing_ext' require 'action_controller/routing/route' diff --git a/actionpack/lib/action_controller/routing/route_set.rb b/actionpack/lib/action_controller/routing/route_set.rb index 1b8b52ad10..3bb25dbba9 100644 --- a/actionpack/lib/action_controller/routing/route_set.rb +++ b/actionpack/lib/action_controller/routing/route_set.rb @@ -7,6 +7,8 @@ module ActionController # Mapper instances have relatively few instance methods, in order to avoid # clashes with named routes. class Mapper #:doc: + include ActionController::Resources + def initialize(set) #:nodoc: @set = set end diff --git a/actionpack/lib/action_controller/session_management.rb b/actionpack/lib/action_controller/session_management.rb index fd3d94ed97..60a9aec39c 100644 --- a/actionpack/lib/action_controller/session_management.rb +++ b/actionpack/lib/action_controller/session_management.rb @@ -1,10 +1,3 @@ -require 'action_controller/session/cookie_store' -require 'action_controller/session/drb_store' -require 'action_controller/session/mem_cache_store' -if Object.const_defined?(:ActiveRecord) - require 'action_controller/session/active_record_store' -end - module ActionController #:nodoc: module SessionManagement #:nodoc: def self.included(base) diff --git a/actionpack/lib/action_controller/vendor/html-scanner.rb b/actionpack/lib/action_controller/vendor/html-scanner.rb new file mode 100644 index 0000000000..5c6db99858 --- /dev/null +++ b/actionpack/lib/action_controller/vendor/html-scanner.rb @@ -0,0 +1,9 @@ +$LOAD_PATH << "#{File.dirname(__FILE__)}/html-scanner" + +module HTML + autoload :Document, 'html/document' + autoload :Sanitizer, 'html/sanitizer' + autoload :FullSanitizer, 'html/sanitizer' + autoload :LinkSanitizer, 'html/sanitizer' + autoload :WhiteListSanitizer, 'html/sanitizer' +end diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb index 7b1d3f8e7c..0c76204060 100644 --- a/actionpack/lib/action_view.rb +++ b/actionpack/lib/action_view.rb @@ -31,23 +31,29 @@ rescue LoadError end end -require 'action_view/template_handlers' -require 'action_view/renderable' -require 'action_view/renderable_partial' +module ActionView + def self.load_all! + [Base, InlineTemplate, TemplateError] + end -require 'action_view/template' -require 'action_view/inline_template' -require 'action_view/paths' + autoload :Base, 'action_view/base' + autoload :Helpers, 'action_view/helpers' + autoload :InlineTemplate, 'action_view/inline_template' + autoload :Partials, 'action_view/partials' + autoload :PathSet, 'action_view/paths' + autoload :Renderable, 'action_view/renderable' + autoload :RenderablePartial, 'action_view/renderable_partial' + autoload :Template, 'action_view/template' + autoload :TemplateError, 'action_view/template_error' + autoload :TemplateHandler, 'action_view/template_handler' + autoload :TemplateHandlers, 'action_view/template_handlers' + autoload :Helpers, 'action_view/helpers' +end -require 'action_view/base' -require 'action_view/partials' -require 'action_view/template_error' +class ERB + autoload :Util, 'action_view/erb/util' +end I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml" -require 'action_view/helpers' - -ActionView::Base.class_eval do - include ActionView::Partials - include ActionView::Helpers -end +ActionView.load_all! diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 0d3752d875..7697848713 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -157,7 +157,7 @@ module ActionView #:nodoc: # # See the ActionView::Helpers::PrototypeHelper::GeneratorMethods documentation for more details. class Base - include ERB::Util + include Helpers, Partials, ::ERB::Util extend ActiveSupport::Memoizable attr_accessor :base_path, :assigns, :template_extension diff --git a/actionpack/lib/action_view/erb/util.rb b/actionpack/lib/action_view/erb/util.rb new file mode 100644 index 0000000000..3c77c5ce76 --- /dev/null +++ b/actionpack/lib/action_view/erb/util.rb @@ -0,0 +1,38 @@ +require 'erb' + +class ERB + module Util + HTML_ESCAPE = { '&' => '&', '>' => '>', '<' => '<', '"' => '"' } + JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' } + + # A utility method for escaping HTML tag characters. + # This method is also aliased as <tt>h</tt>. + # + # In your ERb templates, use this method to escape any unsafe content. For example: + # <%=h @person.name %> + # + # ==== Example: + # puts html_escape("is a > 0 & a < 10?") + # # => is a > 0 & a < 10? + def html_escape(s) + s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] } + end + + # A utility method for escaping HTML entities in JSON strings. + # This method is also aliased as <tt>j</tt>. + # + # In your ERb templates, use this method to escape any HTML entities: + # <%=j @person.to_json %> + # + # ==== Example: + # puts json_escape("is a > 0 & a < 10?") + # # => is a \u003E 0 \u0026 a \u003C 10? + def json_escape(s) + s.to_s.gsub(/[&"><]/) { |special| JSON_ESCAPE[special] } + end + + alias j json_escape + module_function :j + module_function :json_escape + end +end diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb index ff97df204c..693ab7c2e0 100644 --- a/actionpack/lib/action_view/helpers.rb +++ b/actionpack/lib/action_view/helpers.rb @@ -1,10 +1,28 @@ -Dir.entries(File.expand_path("#{File.dirname(__FILE__)}/helpers")).sort.each do |file| - next unless file =~ /^([a-z][a-z_]*_helper).rb$/ - require "action_view/helpers/#{$1}" -end - module ActionView #:nodoc: module Helpers #:nodoc: + autoload :ActiveRecordHelper, 'action_view/helpers/active_record_helper' + autoload :AssetTagHelper, 'action_view/helpers/asset_tag_helper' + autoload :AtomFeedHelper, 'action_view/helpers/atom_feed_helper' + autoload :BenchmarkHelper, 'action_view/helpers/benchmark_helper' + autoload :CacheHelper, 'action_view/helpers/cache_helper' + autoload :CaptureHelper, 'action_view/helpers/capture_helper' + autoload :DateHelper, 'action_view/helpers/date_helper' + autoload :DebugHelper, 'action_view/helpers/debug_helper' + autoload :FormHelper, 'action_view/helpers/form_helper' + autoload :FormOptionsHelper, 'action_view/helpers/form_options_helper' + autoload :FormTagHelper, 'action_view/helpers/form_tag_helper' + autoload :JavascriptHelper, 'action_view/helpers/javascript_helper' + autoload :NumberHelper, 'action_view/helpers/number_helper' + autoload :PrototypeHelper, 'action_view/helpers/prototype_helper' + autoload :RecordIdentificationHelper, 'action_view/helpers/record_identification_helper' + autoload :RecordTagHelper, 'action_view/helpers/record_tag_helper' + autoload :SanitizeHelper, 'action_view/helpers/sanitize_helper' + autoload :ScriptaculousHelper, 'action_view/helpers/scriptaculous_helper' + autoload :TagHelper, 'action_view/helpers/tag_helper' + autoload :TextHelper, 'action_view/helpers/text_helper' + autoload :TranslationHelper, 'action_view/helpers/translation_helper' + autoload :UrlHelper, 'action_view/helpers/url_helper' + def self.included(base) base.extend(ClassMethods) end @@ -24,6 +42,7 @@ module ActionView #:nodoc: include FormHelper include FormOptionsHelper include FormTagHelper + include JavaScriptHelper include NumberHelper include PrototypeHelper include RecordIdentificationHelper diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 77f19b36a6..3e734ccaab 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -220,8 +220,6 @@ module ActionView end end - STORAGE_UNITS = %w( Bytes KB MB GB TB ).freeze - # Formats the bytes in +size+ into a more understandable representation # (e.g., giving it 1500 yields 1.5 KB). This method is useful for # reporting file sizes to users. This method returns nil if @@ -257,6 +255,7 @@ module ActionView defaults = I18n.translate(:'number.format', :locale => options[:locale], :raise => true) rescue {} human = I18n.translate(:'number.human.format', :locale => options[:locale], :raise => true) rescue {} defaults = defaults.merge(human) + storage_units = I18n.translate(:'number.human.storage_units', :locale => options[:locale], :raise => true) unless args.empty? ActiveSupport::Deprecation.warn('number_to_human_size takes an option hash ' + @@ -268,12 +267,12 @@ module ActionView separator ||= (options[:separator] || defaults[:separator]) delimiter ||= (options[:delimiter] || defaults[:delimiter]) - max_exp = STORAGE_UNITS.size - 1 + max_exp = storage_units.size - 1 number = Float(number) exponent = (Math.log(number) / Math.log(1024)).to_i # Convert to base 1024 exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit number /= 1024 ** exponent - unit = STORAGE_UNITS[exponent] + unit = storage_units[exponent] begin escaped_separator = Regexp.escape(separator) diff --git a/actionpack/lib/action_view/helpers/sanitize_helper.rb b/actionpack/lib/action_view/helpers/sanitize_helper.rb index 435ba936e1..200c1d6085 100644 --- a/actionpack/lib/action_view/helpers/sanitize_helper.rb +++ b/actionpack/lib/action_view/helpers/sanitize_helper.rb @@ -1,14 +1,5 @@ require 'action_view/helpers/tag_helper' - -begin - require 'html/document' -rescue LoadError - html_scanner_path = "#{File.dirname(__FILE__)}/../../action_controller/vendor/html-scanner" - if File.directory?(html_scanner_path) - $:.unshift html_scanner_path - require 'html/document' - end -end +require 'action_controller/vendor/html-scanner' module ActionView module Helpers #:nodoc: diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 510c1a6a76..506138a735 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -1,15 +1,5 @@ require 'action_view/helpers/tag_helper' -begin - require 'html/document' -rescue LoadError - html_scanner_path = "#{File.dirname(__FILE__)}/../../action_controller/vendor/html-scanner" - if File.directory?(html_scanner_path) - $:.unshift html_scanner_path - require 'html/document' - end -end - module ActionView module Helpers #:nodoc: # The TextHelper module provides a set of methods for filtering, formatting diff --git a/actionpack/lib/action_view/locale/en.yml b/actionpack/lib/action_view/locale/en.yml index 002226fd9c..9542b035aa 100644 --- a/actionpack/lib/action_view/locale/en.yml +++ b/actionpack/lib/action_view/locale/en.yml @@ -44,6 +44,7 @@ # separator: delimiter: "" precision: 1 + storage_units: [Bytes, KB, MB, GB, TB] # Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words() datetime: diff --git a/actionpack/lib/action_view/template_handler.rb b/actionpack/lib/action_view/template_handler.rb index d7e7c9b199..672da0ed2b 100644 --- a/actionpack/lib/action_view/template_handler.rb +++ b/actionpack/lib/action_view/template_handler.rb @@ -1,14 +1,34 @@ # Legacy TemplateHandler stub - module ActionView - module TemplateHandlers + module TemplateHandlers #:nodoc: module Compilable + def self.included(base) + base.extend(ClassMethods) + end + + module ClassMethods + def call(template) + new.compile(template) + end + end + + def compile(template) + raise "Need to implement #{self.class.name}#compile(template)" + end end end class TemplateHandler def self.call(template) - new.compile(template) + "#{name}.new(self).render(template, local_assigns)" + end + + def initialize(view = nil) + @view = view + end + + def render(template, local_assigns) + raise "Need to implement #{self.class.name}#render(template, local_assigns)" end end end diff --git a/actionpack/lib/action_view/template_handlers.rb b/actionpack/lib/action_view/template_handlers.rb index 6c8aa4c2a7..d06ddd5fb5 100644 --- a/actionpack/lib/action_view/template_handlers.rb +++ b/actionpack/lib/action_view/template_handlers.rb @@ -1,10 +1,9 @@ -require 'action_view/template_handler' -require 'action_view/template_handlers/builder' -require 'action_view/template_handlers/erb' -require 'action_view/template_handlers/rjs' - module ActionView #:nodoc: module TemplateHandlers #:nodoc: + autoload :ERB, 'action_view/template_handlers/erb' + autoload :RJS, 'action_view/template_handlers/rjs' + autoload :Builder, 'action_view/template_handlers/builder' + def self.extended(base) base.register_default_template_handler :erb, TemplateHandlers::ERB base.register_template_handler :rjs, TemplateHandlers::RJS diff --git a/actionpack/lib/action_view/template_handlers/erb.rb b/actionpack/lib/action_view/template_handlers/erb.rb index 3def949f1e..f8d3da15be 100644 --- a/actionpack/lib/action_view/template_handlers/erb.rb +++ b/actionpack/lib/action_view/template_handlers/erb.rb @@ -1,42 +1,3 @@ -require 'erb' - -class ERB - module Util - HTML_ESCAPE = { '&' => '&', '>' => '>', '<' => '<', '"' => '"' } - JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' } - - # A utility method for escaping HTML tag characters. - # This method is also aliased as <tt>h</tt>. - # - # In your ERb templates, use this method to escape any unsafe content. For example: - # <%=h @person.name %> - # - # ==== Example: - # puts html_escape("is a > 0 & a < 10?") - # # => is a > 0 & a < 10? - def html_escape(s) - s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] } - end - - # A utility method for escaping HTML entities in JSON strings. - # This method is also aliased as <tt>j</tt>. - # - # In your ERb templates, use this method to escape any HTML entities: - # <%=j @person.to_json %> - # - # ==== Example: - # puts json_escape("is a > 0 & a < 10?") - # # => is a \u003E 0 \u0026 a \u003C 10? - def json_escape(s) - s.to_s.gsub(/[&"><]/) { |special| JSON_ESCAPE[special] } - end - - alias j json_escape - module_function :j - module_function :json_escape - end -end - module ActionView module TemplateHandlers class ERB < TemplateHandler diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index cdea1def92..4ab4ed233f 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -1,5 +1,3 @@ -require 'action_controller/test_case' - module ActionView class TestCase < ActiveSupport::TestCase include ActionController::TestCase::Assertions diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 76812b94df..bee598e1ef 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -8,7 +8,7 @@ require 'yaml' require 'stringio' require 'test/unit' -gem 'mocha', '>= 0.9.0' +gem 'mocha', '>= 0.9.3' require 'mocha' begin diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb index fd7da89aa7..677d434f9c 100644 --- a/actionpack/test/activerecord/active_record_store_test.rb +++ b/actionpack/test/activerecord/active_record_store_test.rb @@ -1,7 +1,6 @@ # These tests exercise CGI::Session::ActiveRecordStore, so you're going to # need AR in a sibling directory to AP and have SQLite installed. require 'active_record_unit' -require 'action_controller/session/active_record_store' module CommonActiveRecordStoreTests def test_basics diff --git a/actionpack/test/controller/assert_select_test.rb b/actionpack/test/controller/assert_select_test.rb index a79278159d..ed8c4427c9 100644 --- a/actionpack/test/controller/assert_select_test.rb +++ b/actionpack/test/controller/assert_select_test.rb @@ -9,9 +9,10 @@ require 'controller/fake_controllers' unless defined?(ActionMailer) begin - $:.unshift(File.dirname(__FILE__) + "/../../../actionmailer/lib") + $:.unshift("#{File.dirname(__FILE__)}/../../../actionmailer/lib") require 'action_mailer' - rescue LoadError + rescue LoadError => e + raise unless e.message =~ /action_mailer/ require 'rubygems' gem 'actionmailer' end diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb index 87fbf1a4cd..ac1c8abc59 100644 --- a/actionpack/test/controller/cgi_test.rb +++ b/actionpack/test/controller/cgi_test.rb @@ -1,5 +1,4 @@ require 'abstract_unit' -require 'action_controller/cgi_process' class BaseCgiTest < Test::Unit::TestCase def setup diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 3ee78a6156..61bfb2b6e9 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -2,8 +2,6 @@ require 'abstract_unit' uses_mocha 'dispatcher tests' do -require 'action_controller/dispatcher' - class DispatcherTest < Test::Unit::TestCase Dispatcher = ActionController::Dispatcher diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 7e4c3e171a..b39d35930d 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -1,6 +1,4 @@ require 'abstract_unit' -require 'action_controller/integration' -require 'action_controller/routing' uses_mocha 'integration' do diff --git a/actionpack/test/controller/integration_upload_test.rb b/actionpack/test/controller/integration_upload_test.rb index 4af9b7e697..b1dd6a6341 100644 --- a/actionpack/test/controller/integration_upload_test.rb +++ b/actionpack/test/controller/integration_upload_test.rb @@ -1,6 +1,4 @@ require 'abstract_unit' -require 'action_controller/integration' -require 'action_controller/routing' unless defined? ApplicationController class ApplicationController < ActionController::Base diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index d5e56b9584..7e8b0f9bf2 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -1,5 +1,4 @@ require 'abstract_unit' -require 'action_controller/rack_process' class BaseRackTest < Test::Unit::TestCase def setup diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 7e264289e6..316a203e97 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -1,5 +1,4 @@ require 'abstract_unit' -require 'action_controller/integration' class RequestTest < ActiveSupport::TestCase def setup diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index b8a143cfd9..d62c7a1743 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -1,6 +1,5 @@ require 'abstract_unit' require 'controller/fake_controllers' -require 'action_controller/routing' class MilestonesController < ActionController::Base def index() head :ok end diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb index 52c1f7559c..b5f14acc1f 100644 --- a/actionpack/test/controller/session/cookie_store_test.rb +++ b/actionpack/test/controller/session/cookie_store_test.rb @@ -1,7 +1,4 @@ require 'abstract_unit' -require 'action_controller/cgi_process' -require 'action_controller/cgi_ext' - require 'stringio' diff --git a/actionpack/test/controller/session/mem_cache_store_test.rb b/actionpack/test/controller/session/mem_cache_store_test.rb index a7d48431f8..9ab927a01f 100644 --- a/actionpack/test/controller/session/mem_cache_store_test.rb +++ b/actionpack/test/controller/session/mem_cache_store_test.rb @@ -1,7 +1,4 @@ require 'abstract_unit' -require 'action_controller/cgi_process' -require 'action_controller/cgi_ext' - class CGI::Session def cache diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index a33eb85b66..86a0bb6a79 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'tzinfo' TZInfo::Timezone.cattr_reader :loaded_zones @@ -682,4 +683,4 @@ uses_mocha "FormOptionsHelperTest" do end end -end
\ No newline at end of file +end diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index 67c61a5f2e..2528bead36 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -10,6 +10,7 @@ class NumberHelperI18nTests < Test::Unit::TestCase @number_defaults = { :precision => 3, :delimiter => ',', :separator => '.' } @currency_defaults = { :unit => '$', :format => '%u%n', :precision => 2 } @human_defaults = { :precision => 1 } + @human_storage_units_defaults = %w(Bytes KB MB GB TB) @percentage_defaults = { :delimiter => '' } @precision_defaults = { :delimiter => '' } @@ -47,6 +48,8 @@ class NumberHelperI18nTests < Test::Unit::TestCase I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) I18n.expects(:translate).with(:'number.human.format', :locale => 'en', :raise => true).returns(@human_defaults) + I18n.expects(:translate).with(:'number.human.storage_units', :locale => 'en', + :raise => true).returns(@human_storage_units_defaults) # can't be called with 1 because this directly returns without calling I18n.translate number_to_human_size(1025, :locale => 'en') end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 0323c33b95..b316d5c23e 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -175,6 +175,17 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) end + class LegacyHandler < ActionView::TemplateHandler + def render(template, local_assigns) + "source: #{template.source}; locals: #{local_assigns.inspect}" + end + end + + def test_render_legacy_handler_with_custom_type + ActionView::Template.register_template_handler :foo, LegacyHandler + assert_equal 'source: Hello, <%= name %>!; locals: {:name=>"Josh"}', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) + end + def test_render_with_layout assert_equal %(<title></title>\nHello world!\n), @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield") |