Permalink
Browse files

Merge branch 'master' of git@github.com:rails/rails

  • Loading branch information...
2 parents 556204a + dd4181f commit ea3a7e1bb1efc8b3ca10c4163bc116f3d5e23af1 @dhh dhh committed Jun 12, 2008
Showing with 2,728 additions and 4,074 deletions.
  1. +2 −1 actionmailer/lib/action_mailer/base.rb
  2. +6 −0 actionpack/CHANGELOG
  3. +0 −7 actionpack/lib/action_controller/base.rb
  4. +29 −12 actionpack/lib/action_controller/caching/actions.rb
  5. +2 −0 actionpack/lib/action_controller/rack_process.rb
  6. +18 −11 actionpack/lib/action_controller/record_identifier.rb
  7. +1 −1 actionpack/lib/action_controller/routing/segments.rb
  8. +2 −7 actionpack/lib/action_controller/session_management.rb
  9. +1 −6 actionpack/lib/action_view.rb
  10. +12 −11 actionpack/lib/action_view/base.rb
  11. +13 −42 actionpack/lib/action_view/helpers/capture_helper.rb
  12. +2 −2 actionpack/lib/action_view/helpers/form_helper.rb
  13. +2 −2 actionpack/lib/action_view/helpers/form_options_helper.rb
  14. +7 −7 actionpack/lib/action_view/helpers/form_tag_helper.rb
  15. +10 −18 actionpack/lib/action_view/helpers/javascript_helper.rb
  16. +2 −2 actionpack/lib/action_view/helpers/prototype_helper.rb
  17. +2 −3 actionpack/lib/action_view/helpers/record_tag_helper.rb
  18. +6 −12 actionpack/lib/action_view/helpers/tag_helper.rb
  19. +13 −5 actionpack/lib/action_view/helpers/text_helper.rb
  20. +1 −1 actionpack/lib/action_view/partial_template.rb
  21. +26 −65 actionpack/lib/action_view/template.rb
  22. +2 −32 actionpack/lib/action_view/template_finder.rb
  23. +0 −1 actionpack/lib/action_view/template_handler.rb
  24. +46 −0 actionpack/lib/action_view/template_handlers.rb
  25. +4 −3 actionpack/lib/action_view/template_handlers/builder.rb
  26. +2 −2 actionpack/lib/action_view/template_handlers/compilable.rb
  27. +2 −4 actionpack/lib/action_view/template_handlers/erb.rb
  28. +5 −0 actionpack/lib/action_view/test_case.rb
  29. +52 −6 actionpack/test/controller/caching_test.rb
  30. +1 −19 actionpack/test/controller/capture_test.rb
  31. +26 −24 actionpack/test/controller/cgi_test.rb
  32. +24 −5 actionpack/test/controller/new_render_test.rb
  33. +1,643 −1,672 actionpack/test/controller/routing_test.rb
  34. +1 −1 actionpack/test/controller/session/mem_cache_store_test.rb
  35. +0 −2 actionpack/test/fixtures/test/block_content_for.erb
  36. +0 −2 actionpack/test/fixtures/test/erb_content_for.erb
  37. +1 −0 actionpack/test/fixtures/test/render_file_from_template.html.erb
  38. +4 −8 actionpack/test/template/date_helper_test.rb
  39. +100 −151 actionpack/test/template/form_helper_test.rb
  40. +15 −21 actionpack/test/template/form_options_helper_test.rb
  41. +13 −16 actionpack/test/template/form_tag_helper_test.rb
  42. +8 −6 actionpack/test/template/javascript_helper_test.rb
  43. +7 −13 actionpack/test/template/prototype_helper_test.rb
  44. +2 −7 actionpack/test/template/record_tag_helper_test.rb
  45. +5 −6 actionpack/test/template/tag_helper_test.rb
  46. +0 −13 actionpack/test/template/template_finder_test.rb
  47. +8 −0 actionpack/test/template/text_helper_test.rb
  48. +6 −0 activerecord/CHANGELOG
  49. +2 −2 activerecord/lib/active_record/association_preload.rb
  50. +19 −9 activerecord/lib/active_record/associations.rb
  51. +18 −11 activerecord/lib/active_record/base.rb
  52. +9 −3 activerecord/lib/active_record/calculations.rb
  53. +2 −2 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
  54. +37 −42 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  55. +58 −19 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  56. +1 −1 activerecord/lib/active_record/fixtures.rb
  57. +0 −9 activerecord/lib/active_record/validations.rb
  58. +0 −362 activerecord/lib/active_record/vendor/db2.rb
  59. +0 −1,214 activerecord/lib/active_record/vendor/mysql.rb
  60. +2 −2 activerecord/test/cases/active_schema_test_postgresql.rb
  61. +19 −0 activerecord/test/cases/associations/belongs_to_associations_test.rb
  62. +12 −1 activerecord/test/cases/associations/eager_test.rb
  63. +14 −3 activerecord/test/cases/associations/has_many_associations_test.rb
  64. +12 −0 activerecord/test/cases/associations/has_one_associations_test.rb
  65. +46 −0 activerecord/test/cases/calculations_test.rb
  66. +12 −0 activerecord/test/cases/database_statements_test.rb
  67. +3 −3 activerecord/test/cases/reflection_test.rb
  68. +3 −1 activerecord/test/models/company.rb
  69. +2 −1 activerecord/test/models/developer.rb
  70. +5 −1 activeresource/lib/active_resource/base.rb
  71. +48 −0 activeresource/test/base_test.rb
  72. +3 −0 activeresource/test/fixtures/customer.rb
  73. +3 −6 activesupport/lib/active_support/cache.rb
  74. +2 −0 activesupport/lib/active_support/cache/compressed_mem_cache_store.rb
  75. +1 −0 activesupport/lib/active_support/cache/drb_store.rb
  76. +14 −3 activesupport/lib/active_support/core_ext/enumerable.rb
  77. +4 −3 activesupport/lib/active_support/core_ext/hash/except.rb
  78. +2 −4 activesupport/lib/active_support/core_ext/hash/slice.rb
  79. +5 −0 activesupport/lib/active_support/core_ext/module.rb
  80. +22 −0 activesupport/lib/active_support/core_ext/module/model_naming.rb
  81. +9 −8 activesupport/lib/active_support/core_ext/object/extending.rb
  82. +11 −13 activesupport/lib/active_support/core_ext/string/unicode.rb
  83. +6 −6 activesupport/lib/active_support/inflector.rb
  84. +1 −0 activesupport/lib/active_support/ordered_hash.rb
  85. +31 −7 activesupport/lib/active_support/testing/setup_and_teardown.rb
  86. +1 −1 activesupport/test/core_ext/class_test.rb
  87. +19 −0 activesupport/test/core_ext/module/model_naming_test.rb
  88. +18 −16 activesupport/test/core_ext/time_with_zone_test.rb
  89. +6 −0 activesupport/test/test_test.rb
  90. +1 −1 railties/configs/initializers/inflections.rb
  91. +15 −16 railties/lib/rails/gem_dependency.rb
  92. +9 −1 railties/lib/rails/plugin.rb
  93. +2 −11 railties/lib/webrick_server.rb
  94. +1 −0 railties/test/fixtures/plugins/default/gemlike/init.rb
  95. +2 −0 railties/test/fixtures/plugins/default/gemlike/lib/gemlike.rb
  96. +7 −0 railties/test/fixtures/plugins/default/gemlike/rails/init.rb
  97. +51 −51 railties/test/initializer_test.rb
  98. +6 −6 railties/test/plugin_loader_test.rb
  99. +2 −2 railties/test/plugin_locator_test.rb
  100. +12 −4 railties/test/plugin_test.rb
  101. +4 −0 railties/test/rails_info_controller_test.rb
@@ -530,14 +530,15 @@ def initialize_defaults(method_name)
end
def render_message(method_name, body)
- render :file => method_name, :body => body
+ render :file => method_name, :body => body, :use_full_path => true
end
def render(opts)
body = opts.delete(:body)
if opts[:file] && opts[:file] !~ /\//
opts[:file] = "#{mailer_name}/#{opts[:file]}"
end
+ opts[:use_full_path] = true
initialize_template_class(body).render(opts)
end
View
@@ -1,5 +1,11 @@
*Edge*
+* Make caching more aware of mime types. Ensure request format is not considered while expiring cache. [Jonathan del Strother]
+
+* Drop ActionController::Base.allow_concurrency flag [Josh Peek]
+
+* More efficient concat and capture helpers. Remove ActionView::Base.erb_variable. [Jeremy Kemper]
+
* Added page.reload functionality. Resolves #277. [Sean Huber]
* Fixed Request#remote_ip to only raise hell if the HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR doesn't match (not just if they're both present) [Mark Imbriaco, Bradford Folkens]
@@ -283,13 +283,6 @@ class Base
@@debug_routes = true
cattr_accessor :debug_routes
- # Indicates to Mongrel or Webrick whether to allow concurrent action
- # processing. Your controller actions and any other code they call must
- # also behave well when called from concurrent threads. Turned off by
- # default.
- @@allow_concurrency = false
- cattr_accessor :allow_concurrency
-
# Modern REST web services often need to submit complex data to the web application.
# The <tt>@@param_parsers</tt> hash lets you register handlers which will process the HTTP body and add parameters to the
# <tt>params</tt> hash. These handlers are invoked for POST and PUT requests.
@@ -67,10 +67,10 @@ def expire_action(options = {})
if options[:action].is_a?(Array)
options[:action].dup.each do |action|
- expire_fragment(ActionCachePath.path_for(self, options.merge({ :action => action })))
+ expire_fragment(ActionCachePath.path_for(self, options.merge({ :action => action }), false))
end
else
- expire_fragment(ActionCachePath.path_for(self, options))
+ expire_fragment(ActionCachePath.path_for(self, options, false))
end
end
@@ -125,16 +125,24 @@ class ActionCachePath
attr_reader :path, :extension
class << self
- def path_for(controller, options)
- new(controller, options).path
+ def path_for(controller, options, infer_extension=true)
+ new(controller, options, infer_extension).path
end
end
-
- def initialize(controller, options = {})
- @extension = extract_extension(controller.request.path)
+
+ # When true, infer_extension will look up the cache path extension from the request's path & format.
+ # This is desirable when reading and writing the cache, but not when expiring the cache - expire_action should expire the same files regardless of the request format.
+ def initialize(controller, options = {}, infer_extension=true)
+ if infer_extension and options.is_a? Hash
+ request_extension = extract_extension(controller.request)
+ options = options.reverse_merge(:format => request_extension)
+ end
path = controller.url_for(options).split('://').last
normalize!(path)
- add_extension!(path, @extension)
+ if infer_extension
+ @extension = request_extension
+ add_extension!(path, @extension)
+ end
@path = URI.unescape(path)
end
@@ -144,13 +152,22 @@ def normalize!(path)
end
def add_extension!(path, extension)
- path << ".#{extension}" if extension
+ path << ".#{extension}" if extension and !path.ends_with?(extension)
end
-
- def extract_extension(file_path)
+
+ def extract_extension(request)
# Don't want just what comes after the last '.' to accommodate multi part extensions
# such as tar.gz.
- file_path[/^[^.]+\.(.+)$/, 1]
+ extension = request.path[/^[^.]+\.(.+)$/, 1]
+
+ # If there's no extension in the path, check request.format
+ if extension.nil?
+ extension = request.format.to_sym.to_s
+ if extension=='all'
+ extension = nil
+ end
+ end
+ extension
end
end
end
@@ -189,6 +189,8 @@ def each(&callback)
if @body.respond_to?(:call)
@writer = lambda { |x| callback.call(x) }
@body.call(self, self)
+ elsif @body.is_a?(String)
+ @body.each_line(&callback)
else
@body.each(&callback)
end
@@ -31,18 +31,21 @@ module ActionController
module RecordIdentifier
extend self
+ JOIN = '_'.freeze
+ NEW = 'new'.freeze
+
# Returns plural/singular for a record or class. Example:
#
# partial_path(post) # => "posts/post"
# partial_path(Person) # => "people/person"
# partial_path(Person, "admin/games") # => "admin/people/person"
def partial_path(record_or_class, controller_path = nil)
- klass = class_from_record_or_class(record_or_class)
+ name = model_name_from_record_or_class(record_or_class)
if controller_path && controller_path.include?("/")
- "#{File.dirname(controller_path)}/#{klass.name.tableize}/#{klass.name.demodulize.underscore}"
+ "#{File.dirname(controller_path)}/#{name.partial_path}"
else
- "#{klass.name.tableize}/#{klass.name.demodulize.underscore}"
+ name.partial_path
end
end
@@ -56,7 +59,8 @@ def partial_path(record_or_class, controller_path = nil)
# dom_class(post, :edit) # => "edit_post"
# dom_class(Person, :edit) # => "edit_person"
def dom_class(record_or_class, prefix = nil)
- [ prefix, singular_class_name(record_or_class) ].compact * '_'
+ singular = singular_class_name(record_or_class)
+ prefix ? "#{prefix}#{JOIN}#{singular}" : singular
end
# The DOM id convention is to use the singular form of an object or class with the id following an underscore.
@@ -69,29 +73,32 @@ def dom_class(record_or_class, prefix = nil)
#
# dom_id(Post.new(:id => 45), :edit) # => "edit_post_45"
def dom_id(record, prefix = nil)
- prefix ||= 'new' unless record.id
- [ prefix, singular_class_name(record), record.id ].compact * '_'
+ if record_id = record.id
+ "#{dom_class(record, prefix)}#{JOIN}#{record_id}"
+ else
+ dom_class(record, prefix || NEW)
+ end
end
# Returns the plural class name of a record or class. Examples:
#
# plural_class_name(post) # => "posts"
# plural_class_name(Highrise::Person) # => "highrise_people"
def plural_class_name(record_or_class)
- singular_class_name(record_or_class).pluralize
+ model_name_from_record_or_class(record_or_class).plural
end
# Returns the singular class name of a record or class. Examples:
#
# singular_class_name(post) # => "post"
# singular_class_name(Highrise::Person) # => "highrise_person"
def singular_class_name(record_or_class)
- class_from_record_or_class(record_or_class).name.underscore.tr('/', '_')
+ model_name_from_record_or_class(record_or_class).singular
end
private
- def class_from_record_or_class(record_or_class)
- record_or_class.is_a?(Class) ? record_or_class : record_or_class.class
+ def model_name_from_record_or_class(record_or_class)
+ (record_or_class.is_a?(Class) ? record_or_class : record_or_class.class).model_name
end
end
-end
+end
@@ -249,7 +249,7 @@ def interpolation_chunk(value_code = "#{local_name}")
end
def extract_value
- "#{local_name} = hash[:#{key}] && hash[:#{key}].collect { |path_component| URI.escape(path_component.to_param, ActionController::Routing::Segment::UNSAFE_PCHAR) }.to_param #{"|| #{default.inspect}" if default}"
+ "#{local_name} = hash[:#{key}] && Array(hash[:#{key}]).collect { |path_component| URI.escape(path_component.to_param, ActionController::Routing::Segment::UNSAFE_PCHAR) }.to_param #{"|| #{default.inspect}" if default}"
end
def default
@@ -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)
@@ -22,6 +15,8 @@ module ClassMethods
# <tt>:p_store</tt>, <tt>:drb_store</tt>, <tt>:mem_cache_store</tt>, or
# <tt>:memory_store</tt>) or your own custom class.
def session_store=(store)
+ require "action_controller/session/#{store.to_s}" if [:active_record_store, :drb_store, :mem_cache_store].include?(store)
+
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:database_manager] =
store.is_a?(Symbol) ? CGI::Session.const_get(store == :drb_store ? "DRbStore" : store.to_s.camelize) : store
end
@@ -21,12 +21,7 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-require 'action_view/template_handler'
-require 'action_view/template_handlers/compilable'
-require 'action_view/template_handlers/builder'
-require 'action_view/template_handlers/erb'
-require 'action_view/template_handlers/rjs'
-
+require 'action_view/template_handlers'
require 'action_view/template_finder'
require 'action_view/template'
require 'action_view/partial_template'
@@ -156,10 +156,12 @@ class Base
attr_reader :finder
attr_accessor :base_path, :assigns, :template_extension, :first_render
attr_accessor :controller
-
+
attr_writer :template_format
attr_accessor :current_render_extension
+ attr_accessor :output_buffer
+
# Specify trim mode for the ERB compiler. Defaults to '-'.
# See ERb documentation for suitable values.
@@erb_trim_mode = '-'
@@ -178,14 +180,11 @@ def self.cache_template_extensions=(*args)
# that alert()s the caught exception (and then re-raises it).
@@debug_rjs = false
cattr_accessor :debug_rjs
-
- @@erb_variable = '_erbout'
- cattr_accessor :erb_variable
-
+
attr_internal :request
delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
- :flash, :logger, :action_name, :to => :controller
+ :flash, :logger, :action_name, :controller_name, :to => :controller
module CompiledTemplates #:nodoc:
# holds compiled template code
@@ -253,20 +252,21 @@ def render(options = {}, local_assigns = {}, &block) #:nodoc:
elsif options == :update
update_page(&block)
elsif options.is_a?(Hash)
+ use_full_path = options[:use_full_path]
options = options.reverse_merge(:locals => {}, :use_full_path => true)
if partial_layout = options.delete(:layout)
if block_given?
wrap_content_for_layout capture(&block) do
- concat(render(options.merge(:partial => partial_layout)), block.binding)
+ concat(render(options.merge(:partial => partial_layout)))
end
else
wrap_content_for_layout render(options) do
render(options.merge(:partial => partial_layout))
end
end
elsif options[:file]
- render_file(options[:file], options[:use_full_path], options[:locals])
+ render_file(options[:file], use_full_path || false, options[:locals])
elsif options[:partial] && options[:collection]
render_partial_collection(options[:partial], options[:collection], options[:spacer_template], options[:locals])
elsif options[:partial]
@@ -316,9 +316,10 @@ def template_format
private
def wrap_content_for_layout(content)
- original_content_for_layout = @content_for_layout
- @content_for_layout = content
- returning(yield) { @content_for_layout = original_content_for_layout }
+ original_content_for_layout, @content_for_layout = @content_for_layout, content
+ yield
+ ensure
+ @content_for_layout = original_content_for_layout
end
# Evaluate the local assigns and pushes them to the view.
@@ -31,20 +31,13 @@ module CaptureHelper
# </body></html>
#
def capture(*args, &block)
- # execute the block
- begin
- buffer = eval(ActionView::Base.erb_variable, block.binding)
- rescue
- buffer = nil
- end
-
- if buffer.nil?
- capture_block(*args, &block).to_s
+ if output_buffer
+ with_output_buffer { block.call(*args) }
else
- capture_erb_with_buffer(buffer, *args, &block).to_s
+ block.call(*args)
end
end
-
+
# Calling content_for stores a block of markup in an identifier for later use.
# You can make subsequent calls to the stored content in other templates or the layout
# by passing the identifier as an argument to <tt>yield</tt>.
@@ -121,40 +114,18 @@ def capture(*args, &block)
# named <tt>@content_for_#{name_of_the_content_block}</tt>. The preferred usage is now
# <tt><%= yield :footer %></tt>.
def content_for(name, content = nil, &block)
- existing_content_for = instance_variable_get("@content_for_#{name}").to_s
- new_content_for = existing_content_for + (block_given? ? capture(&block) : content)
- instance_variable_set("@content_for_#{name}", new_content_for)
+ ivar = "@content_for_#{name}"
+ content = capture(&block) if block_given?
+ instance_variable_set(ivar, "#{instance_variable_get(ivar)}#{content}")
end
private
- def capture_block(*args, &block)
- block.call(*args)
- end
-
- def capture_erb(*args, &block)
- buffer = eval(ActionView::Base.erb_variable, block.binding)
- capture_erb_with_buffer(buffer, *args, &block)
- end
-
- def capture_erb_with_buffer(buffer, *args, &block)
- pos = buffer.length
- block.call(*args)
-
- # extract the block
- data = buffer[pos..-1]
-
- # replace it in the original with empty string
- buffer[pos..-1] = ''
-
- data
- end
-
- def erb_content_for(name, &block)
- eval "@content_for_#{name} = (@content_for_#{name} || '') + capture_erb(&block)"
- end
-
- def block_content_for(name, &block)
- eval "@content_for_#{name} = (@content_for_#{name} || '') + capture_block(&block)"
+ def with_output_buffer(buf = '')
+ self.output_buffer, old_buffer = buf, output_buffer
+ yield
+ output_buffer
+ ensure
+ self.output_buffer = old_buffer
end
end
end
@@ -249,9 +249,9 @@ def form_for(record_or_name_or_array, *args, &proc)
args.unshift object
end
- concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {}), proc.binding)
+ concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {}))
fields_for(object_name, *(args << options), &proc)
- concat('</form>', proc.binding)
+ concat('</form>')
end
def apply_form_for_options!(object_or_array, options) #:nodoc:
Oops, something went wrong.

0 comments on commit ea3a7e1

Please sign in to comment.