Skip to content

Commit

Permalink
Merge commit 'mainstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lifo committed Apr 4, 2009
2 parents 4fe6d43 + 0e9efae commit c55507e
Show file tree
Hide file tree
Showing 17 changed files with 395 additions and 314 deletions.
2 changes: 2 additions & 0 deletions actionpack/lib/action_controller/test_process.rb
Expand Up @@ -13,6 +13,7 @@ def initialize(env = {})

@query_parameters = {}
@session = TestSession.new
@session_options ||= {}

initialize_default_values
initialize_containers
Expand Down Expand Up @@ -110,6 +111,7 @@ def assign_parameters(controller_path, action, parameters)
end

def recycle!
@env["action_controller.request.request_parameters"] = {}
self.query_parameters = {}
self.path_parameters = {}
@headers, @request_method, @accepts, @content_type = nil, nil, nil, nil
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/paths.rb
Expand Up @@ -61,7 +61,7 @@ def find_template(original_template_path, format = nil, html_fallback = true)
end
end

return Template.new(original_template_path, original_template_path.to_s =~ /\A\// ? "" : ".") if File.file?(original_template_path)
return Template.new(original_template_path) if File.file?(original_template_path)

raise MissingTemplate.new(self, original_template_path, format)
end
Expand Down
55 changes: 22 additions & 33 deletions actionpack/lib/action_view/template.rb
Expand Up @@ -107,9 +107,8 @@ def self.exempt_from_layout(*extensions)
attr_accessor :locale, :name, :format, :extension
delegate :to_s, :to => :path

def initialize(template_path, load_path)
@template_path = template_path.dup
@load_path, @filename = load_path, File.join(load_path, template_path)
def initialize(template_path, load_path = nil)
@template_path, @load_path = template_path.dup, load_path
@base_path, @name, @locale, @format, @extension = split(template_path)
@base_path.to_s.gsub!(/\/$/, '') # Push to split method

Expand Down Expand Up @@ -180,6 +179,12 @@ def exempt_from_layout?
@@exempt_from_layout.any? { |exempted| path =~ exempted }
end

def filename
# no load_path means this is an "absolute pathed" template
load_path ? File.join(load_path, template_path) : template_path
end
memoize :filename

def source
File.read(filename)
end
Expand Down Expand Up @@ -212,46 +217,30 @@ def valid_extension?(extension)
end

def valid_locale?(locale)
I18n.available_locales.include?(locale.to_sym)
locale && I18n.available_locales.include?(locale.to_sym)
end

# Returns file split into an array
# [base_path, name, locale, format, extension]
def split(file)
if m = file.to_s.match(/^(.*\/)?([^\.]+)\.(.*)$/)
base_path = m[1]
name = m[2]
extensions = m[3]
else
return
[m[1], m[2], *parse_extensions(m[3])]
end
end

locale = nil
format = nil
extension = nil

if m = extensions.split(".")
if valid_locale?(m[0]) && m[1] && valid_extension?(m[2]) # All three
locale = m[0]
format = m[1]
extension = m[2]
elsif m[0] && m[1] && valid_extension?(m[2]) # Multipart formats
format = "#{m[0]}.#{m[1]}"
extension = m[2]
elsif valid_locale?(m[0]) && valid_extension?(m[1]) # locale and extension
locale = m[0]
extension = m[1]
elsif valid_extension?(m[1]) # format and extension
format = m[0]
extension = m[1]
elsif valid_extension?(m[0]) # Just extension
extension = m[0]
else # No extension
format = m[0]
end
# returns parsed extensions as an array
# [locale, format, extension]
def parse_extensions(extensions)
exts = extensions.split(".")

if extension = valid_extension?(exts.last) && exts.pop || nil
locale = valid_locale?(exts.first) && exts.shift || nil
format = exts.join('.') if exts.any? # join('.') is needed for multipart templates
else # no extension, just format
format = exts.last
end

[base_path, name, locale, format, extension]
[locale, format, extension]
end
end
end

0 comments on commit c55507e

Please sign in to comment.