Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:rails/rails
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Jun 12, 2008
2 parents 556204a + dd4181f commit ea3a7e1
Show file tree
Hide file tree
Showing 101 changed files with 2,728 additions and 4,074 deletions.
3 changes: 2 additions & 1 deletion actionmailer/lib/action_mailer/base.rb
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions actionpack/CHANGELOG
@@ -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]
Expand Down
7 changes: 0 additions & 7 deletions actionpack/lib/action_controller/base.rb
Expand Up @@ -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.
Expand Down
41 changes: 29 additions & 12 deletions actionpack/lib/action_controller/caching/actions.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions actionpack/lib/action_controller/rack_process.rb
Expand Up @@ -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
Expand Down
29 changes: 18 additions & 11 deletions actionpack/lib/action_controller/record_identifier.rb
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/routing/segments.rb
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions 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)
Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions actionpack/lib/action_view.rb
Expand Up @@ -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'
Expand Down
23 changes: 12 additions & 11 deletions actionpack/lib/action_view/base.rb
Expand Up @@ -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 = '-'
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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.
Expand Down
55 changes: 13 additions & 42 deletions actionpack/lib/action_view/helpers/capture_helper.rb
Expand Up @@ -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>.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_view/helpers/form_helper.rb
Expand Up @@ -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:
Expand Down

0 comments on commit ea3a7e1

Please sign in to comment.