aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-04-04 17:31:11 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-04-04 17:31:11 +0100
commitc55507e8ceca44558179a705118740540d7871b4 (patch)
tree59937226af81d49ce094e1282b90f0047ef15a36 /actionpack/lib
parent4fe6d43cabe3bb2e094f308d010209c78005a3b9 (diff)
parent0e9efae4745e232b1c778fda69ee110e42a223a7 (diff)
downloadrails-c55507e8ceca44558179a705118740540d7871b4.tar.gz
rails-c55507e8ceca44558179a705118740540d7871b4.tar.bz2
rails-c55507e8ceca44558179a705118740540d7871b4.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/test_process.rb2
-rw-r--r--actionpack/lib/action_view/paths.rb2
-rw-r--r--actionpack/lib/action_view/template.rb55
3 files changed, 25 insertions, 34 deletions
diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb
index 9dd09c30b4..b2d1341573 100644
--- a/actionpack/lib/action_controller/test_process.rb
+++ b/actionpack/lib/action_controller/test_process.rb
@@ -13,6 +13,7 @@ module ActionController #:nodoc:
@query_parameters = {}
@session = TestSession.new
+ @session_options ||= {}
initialize_default_values
initialize_containers
@@ -110,6 +111,7 @@ module ActionController #:nodoc:
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
diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb
index 8cc3fe291c..a0a2f96886 100644
--- a/actionpack/lib/action_view/paths.rb
+++ b/actionpack/lib/action_view/paths.rb
@@ -61,7 +61,7 @@ module ActionView #:nodoc:
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
diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index c339c8a554..a974f2652b 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -107,9 +107,8 @@ module ActionView #:nodoc:
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
@@ -180,6 +179,12 @@ module ActionView #:nodoc:
@@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
@@ -212,46 +217,30 @@ module ActionView #:nodoc:
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