mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge branch 'master' of git@github.com:rails/rails
This commit is contained in:
commit
85b1a55f6d
26 changed files with 166 additions and 115 deletions
|
@ -465,48 +465,48 @@ module ActionMailer #:nodoc:
|
||||||
def create!(method_name, *parameters) #:nodoc:
|
def create!(method_name, *parameters) #:nodoc:
|
||||||
initialize_defaults(method_name)
|
initialize_defaults(method_name)
|
||||||
__send__(method_name, *parameters)
|
__send__(method_name, *parameters)
|
||||||
|
|
||||||
# If an explicit, textual body has not been set, we check assumptions.
|
# If an explicit, textual body has not been set, we check assumptions.
|
||||||
unless String === @body
|
unless String === @body
|
||||||
# First, we look to see if there are any likely templates that match,
|
# First, we look to see if there are any likely templates that match,
|
||||||
# which include the content-type in their file name (i.e.,
|
# which include the content-type in their file name (i.e.,
|
||||||
# "the_template_file.text.html.erb", etc.). Only do this if parts
|
# "the_template_file.text.html.erb", etc.). Only do this if parts
|
||||||
# have not already been specified manually.
|
# have not already been specified manually.
|
||||||
if @parts.empty?
|
# if @parts.empty?
|
||||||
Dir.glob("#{template_path}/#{@template}.*").each do |path|
|
template_root.find_all_by_parts(@template, {}, template_path).each do |template|
|
||||||
template = template_root.find_by_parts("#{mailer_name}/#{File.basename(path)}")
|
|
||||||
|
|
||||||
# Skip unless template has a multipart format
|
|
||||||
next unless template && template.multipart?
|
|
||||||
|
|
||||||
@parts << Part.new(
|
@parts << Part.new(
|
||||||
:content_type => template.content_type,
|
:content_type => Mime::Type.lookup_by_extension(template.content_type || "text").to_s,
|
||||||
:disposition => "inline",
|
:disposition => "inline",
|
||||||
:charset => charset,
|
:charset => charset,
|
||||||
:body => render_template(template, @body)
|
:body => render_template(template, @body)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
unless @parts.empty?
|
|
||||||
|
if @parts.size > 1
|
||||||
@content_type = "multipart/alternative" if @content_type !~ /^multipart/
|
@content_type = "multipart/alternative" if @content_type !~ /^multipart/
|
||||||
@parts = sort_parts(@parts, @implicit_parts_order)
|
@parts = sort_parts(@parts, @implicit_parts_order)
|
||||||
end
|
end
|
||||||
end
|
# end
|
||||||
|
|
||||||
# Then, if there were such templates, we check to see if we ought to
|
# Then, if there were such templates, we check to see if we ought to
|
||||||
# also render a "normal" template (without the content type). If a
|
# also render a "normal" template (without the content type). If a
|
||||||
# normal template exists (or if there were no implicit parts) we render
|
# normal template exists (or if there were no implicit parts) we render
|
||||||
# it.
|
# it.
|
||||||
template_exists = @parts.empty?
|
# ====
|
||||||
template_exists ||= template_root.find_by_parts("#{mailer_name}/#{@template}")
|
# TODO: Revisit this
|
||||||
@body = render_message(@template, @body) if template_exists
|
# template_exists = @parts.empty?
|
||||||
|
# template_exists ||= template_root.find_by_parts("#{mailer_name}/#{@template}")
|
||||||
|
# @body = render_message(@template, @body) if template_exists
|
||||||
|
|
||||||
# Finally, if there are other message parts and a textual body exists,
|
# Finally, if there are other message parts and a textual body exists,
|
||||||
# we shift it onto the front of the parts and set the body to nil (so
|
# we shift it onto the front of the parts and set the body to nil (so
|
||||||
# that create_mail doesn't try to render it in addition to the parts).
|
# that create_mail doesn't try to render it in addition to the parts).
|
||||||
if !@parts.empty? && String === @body
|
# ====
|
||||||
@parts.unshift Part.new(:charset => charset, :body => @body)
|
# TODO: Revisit this
|
||||||
@body = nil
|
# if !@parts.empty? && String === @body
|
||||||
end
|
# @parts.unshift Part.new(:charset => charset, :body => @body)
|
||||||
|
# @body = nil
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
# If this is a multipart e-mail add the mime_version if it is not
|
# If this is a multipart e-mail add the mime_version if it is not
|
||||||
|
@ -580,7 +580,7 @@ module ActionMailer #:nodoc:
|
||||||
|
|
||||||
if file
|
if file
|
||||||
prefix = mailer_name unless file =~ /\//
|
prefix = mailer_name unless file =~ /\//
|
||||||
template = view_paths.find_by_parts(file, formats, prefix)
|
template = view_paths.find_by_parts(file, {:formats => formats}, prefix)
|
||||||
end
|
end
|
||||||
|
|
||||||
layout = _pick_layout(layout,
|
layout = _pick_layout(layout,
|
||||||
|
@ -611,7 +611,7 @@ module ActionMailer #:nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def template_path
|
def template_path
|
||||||
"#{template_root}/#{mailer_name}"
|
"#{mailer_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize_template_class(assigns)
|
def initialize_template_class(assigns)
|
||||||
|
@ -622,7 +622,7 @@ module ActionMailer #:nodoc:
|
||||||
|
|
||||||
def sort_parts(parts, order = [])
|
def sort_parts(parts, order = [])
|
||||||
order = order.collect { |s| s.downcase }
|
order = order.collect { |s| s.downcase }
|
||||||
|
|
||||||
parts = parts.sort do |a, b|
|
parts = parts.sort do |a, b|
|
||||||
a_ct = a.content_type.downcase
|
a_ct = a.content_type.downcase
|
||||||
b_ct = b.content_type.downcase
|
b_ct = b.content_type.downcase
|
||||||
|
@ -663,10 +663,13 @@ module ActionMailer #:nodoc:
|
||||||
headers.each { |k, v| m[k] = v }
|
headers.each { |k, v| m[k] = v }
|
||||||
|
|
||||||
real_content_type, ctype_attrs = parse_content_type
|
real_content_type, ctype_attrs = parse_content_type
|
||||||
|
|
||||||
if @parts.empty?
|
if @parts.empty?
|
||||||
m.set_content_type(real_content_type, nil, ctype_attrs)
|
m.set_content_type(real_content_type, nil, ctype_attrs)
|
||||||
m.body = normalize_new_lines(body)
|
m.body = normalize_new_lines(body)
|
||||||
|
elsif @parts.size == 1 && @parts.first.parts.empty?
|
||||||
|
m.set_content_type(real_content_type, nil, ctype_attrs)
|
||||||
|
m.body = normalize_new_lines(@parts.first.body)
|
||||||
else
|
else
|
||||||
if String === body
|
if String === body
|
||||||
part = TMail::Mail.new
|
part = TMail::Mail.new
|
||||||
|
|
|
@ -518,6 +518,7 @@ module TMail
|
||||||
|
|
||||||
def parse_body( f = nil )
|
def parse_body( f = nil )
|
||||||
return if @body_parsed
|
return if @body_parsed
|
||||||
|
|
||||||
if f
|
if f
|
||||||
parse_body_0 f
|
parse_body_0 f
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
xml.instruct!
|
|
||||||
xml.test
|
|
|
@ -338,6 +338,7 @@ class ActionMailerTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_nested_parts_with_body
|
def test_nested_parts_with_body
|
||||||
created = nil
|
created = nil
|
||||||
|
TestMailer.create_nested_multipart_with_body(@recipient)
|
||||||
assert_nothing_raised { created = TestMailer.create_nested_multipart_with_body(@recipient)}
|
assert_nothing_raised { created = TestMailer.create_nested_multipart_with_body(@recipient)}
|
||||||
assert_equal 1,created.parts.size
|
assert_equal 1,created.parts.size
|
||||||
assert_equal 2,created.parts.first.parts.size
|
assert_equal 2,created.parts.first.parts.size
|
||||||
|
@ -351,8 +352,8 @@ class ActionMailerTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_attachment_with_custom_header
|
def test_attachment_with_custom_header
|
||||||
created = nil
|
created = nil
|
||||||
assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient)}
|
assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient) }
|
||||||
assert_equal "<test@test.com>", created.parts[1].header['content-id'].to_s
|
assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_signed_up
|
def test_signed_up
|
||||||
|
@ -824,7 +825,7 @@ EOF
|
||||||
assert_equal 3, mail.parts.length
|
assert_equal 3, mail.parts.length
|
||||||
assert_equal "1.0", mail.mime_version
|
assert_equal "1.0", mail.mime_version
|
||||||
assert_equal "multipart/alternative", mail.content_type
|
assert_equal "multipart/alternative", mail.content_type
|
||||||
assert_equal "text/yaml", mail.parts[0].content_type
|
assert_equal "application/x-yaml", mail.parts[0].content_type
|
||||||
assert_equal "utf-8", mail.parts[0].sub_header("content-type", "charset")
|
assert_equal "utf-8", mail.parts[0].sub_header("content-type", "charset")
|
||||||
assert_equal "text/plain", mail.parts[1].content_type
|
assert_equal "text/plain", mail.parts[1].content_type
|
||||||
assert_equal "utf-8", mail.parts[1].sub_header("content-type", "charset")
|
assert_equal "utf-8", mail.parts[1].sub_header("content-type", "charset")
|
||||||
|
@ -835,11 +836,11 @@ EOF
|
||||||
def test_implicitly_multipart_messages_with_custom_order
|
def test_implicitly_multipart_messages_with_custom_order
|
||||||
assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"
|
assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"
|
||||||
|
|
||||||
mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["text/yaml", "text/plain"])
|
mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
|
||||||
assert_equal 3, mail.parts.length
|
assert_equal 3, mail.parts.length
|
||||||
assert_equal "text/html", mail.parts[0].content_type
|
assert_equal "text/html", mail.parts[0].content_type
|
||||||
assert_equal "text/plain", mail.parts[1].content_type
|
assert_equal "text/plain", mail.parts[1].content_type
|
||||||
assert_equal "text/yaml", mail.parts[2].content_type
|
assert_equal "application/x-yaml", mail.parts[2].content_type
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_implicitly_multipart_messages_with_charset
|
def test_implicitly_multipart_messages_with_charset
|
||||||
|
@ -938,8 +939,7 @@ EOF
|
||||||
def test_multipart_with_template_path_with_dots
|
def test_multipart_with_template_path_with_dots
|
||||||
mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient)
|
mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient)
|
||||||
assert_equal 2, mail.parts.length
|
assert_equal 2, mail.parts.length
|
||||||
assert_equal 'text/plain', mail.parts[0].content_type
|
assert mail.parts.any? {|part| part.content_type == "text/plain" && part.charset == "utf-8"}
|
||||||
assert_equal 'utf-8', mail.parts[0].charset
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_custom_content_type_attributes
|
def test_custom_content_type_attributes
|
||||||
|
|
|
@ -38,7 +38,7 @@ module AbstractController
|
||||||
else
|
else
|
||||||
self.class_eval %{
|
self.class_eval %{
|
||||||
def _layout
|
def _layout
|
||||||
if view_paths.find_by_parts?("#{_implied_layout_name}", formats, "layouts")
|
if view_paths.find_by_parts?("#{_implied_layout_name}", {:formats => formats}, "layouts")
|
||||||
"#{_implied_layout_name}"
|
"#{_implied_layout_name}"
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
|
@ -62,7 +62,7 @@ module AbstractController
|
||||||
raise ArgumentError, "String, false, or nil expected; you passed #{name.inspect}"
|
raise ArgumentError, "String, false, or nil expected; you passed #{name.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
name && view_paths.find_by_parts(name, formats, "layouts")
|
name && view_paths.find_by_parts(name, {:formats => formats}, "layouts")
|
||||||
end
|
end
|
||||||
|
|
||||||
def _default_layout(require_layout = false)
|
def _default_layout(require_layout = false)
|
||||||
|
|
|
@ -29,7 +29,7 @@ module AbstractController
|
||||||
def render_to_body(options = {})
|
def render_to_body(options = {})
|
||||||
name = options[:_template_name] || action_name
|
name = options[:_template_name] || action_name
|
||||||
|
|
||||||
template = options[:_template] || view_paths.find_by_parts(name.to_s, formats, options[:_prefix])
|
template = options[:_template] || view_paths.find_by_parts(name.to_s, {:formats => formats}, options[:_prefix])
|
||||||
_render_template(template, options)
|
_render_template(template, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,7 @@ module ActionController #:nodoc:
|
||||||
def memoized_find_layout(layout, formats) #:nodoc:
|
def memoized_find_layout(layout, formats) #:nodoc:
|
||||||
return layout if layout.nil? || layout.respond_to?(:render)
|
return layout if layout.nil? || layout.respond_to?(:render)
|
||||||
prefix = layout.to_s =~ /layouts\// ? nil : "layouts"
|
prefix = layout.to_s =~ /layouts\// ? nil : "layouts"
|
||||||
view_paths.find_by_parts(layout.to_s, formats, prefix)
|
view_paths.find_by_parts(layout.to_s, {:formats => formats}, prefix)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_layout(*args)
|
def find_layout(*args)
|
||||||
|
|
|
@ -374,8 +374,13 @@ module ActionController
|
||||||
render_for_file(name.sub(/^\//, ''), [layout, true], options)
|
render_for_file(name.sub(/^\//, ''), [layout, true], options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ==== Arguments
|
||||||
|
# parts<Array[String, Array[Symbol*], String, Boolean]>::
|
||||||
|
# Example: ["show", [:html, :xml], "users", false]
|
||||||
def render_for_parts(parts, layout, options = {})
|
def render_for_parts(parts, layout, options = {})
|
||||||
|
parts[1] = {:formats => parts[1], :locales => [I18n.locale]}
|
||||||
|
|
||||||
tmp = view_paths.find_by_parts(*parts)
|
tmp = view_paths.find_by_parts(*parts)
|
||||||
|
|
||||||
layout = _pick_layout(*layout) unless tmp.exempt_from_layout?
|
layout = _pick_layout(*layout) unless tmp.exempt_from_layout?
|
||||||
|
|
|
@ -33,18 +33,18 @@ module ActionView #:nodoc:
|
||||||
super(*objs.map { |obj| self.class.type_cast(obj) })
|
super(*objs.map { |obj| self.class.type_cast(obj) })
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_by_parts(path, extension = nil, prefix = nil, partial = false)
|
def find_by_parts(path, details = {}, prefix = nil, partial = false)
|
||||||
template_path = path.sub(/^\//, '')
|
template_path = path.sub(/^\//, '')
|
||||||
|
|
||||||
each do |load_path|
|
each do |load_path|
|
||||||
if template = load_path.find_by_parts(template_path, extension, prefix, partial)
|
if template = load_path.find_by_parts(template_path, details, prefix, partial)
|
||||||
return template
|
return template
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.new(path, self)
|
Template.new(path, self)
|
||||||
rescue ActionView::MissingTemplate => e
|
rescue ActionView::MissingTemplate => e
|
||||||
extension ||= []
|
extension = details[:formats] || []
|
||||||
raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path}.{#{extension.join(",")}}")
|
raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path}.{#{extension.join(",")}}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -187,6 +187,7 @@ module ActionView
|
||||||
path = ActionController::RecordIdentifier.partial_path(object, controller_path)
|
path = ActionController::RecordIdentifier.partial_path(object, controller_path)
|
||||||
end
|
end
|
||||||
_, _, prefix, object = parts = partial_parts(path, options)
|
_, _, prefix, object = parts = partial_parts(path, options)
|
||||||
|
parts[1] = {:formats => parts[1]}
|
||||||
template = find_by_parts(*parts)
|
template = find_by_parts(*parts)
|
||||||
_render_partial_object(template, options, (object unless object == true))
|
_render_partial_object(template, options, (object unless object == true))
|
||||||
end
|
end
|
||||||
|
@ -225,7 +226,7 @@ module ActionView
|
||||||
def _render_partial_with_layout(layout, options)
|
def _render_partial_with_layout(layout, options)
|
||||||
if layout
|
if layout
|
||||||
prefix = controller && !layout.include?("/") ? controller.controller_path : nil
|
prefix = controller && !layout.include?("/") ? controller.controller_path : nil
|
||||||
layout = find_by_parts(layout, formats, prefix, true)
|
layout = find_by_parts(layout, {:formats => formats}, prefix, true)
|
||||||
end
|
end
|
||||||
content = _render_partial(options)
|
content = _render_partial(options)
|
||||||
return _render_content_with_layout(content, layout, options[:locals])
|
return _render_content_with_layout(content, layout, options[:locals])
|
||||||
|
@ -253,7 +254,7 @@ module ActionView
|
||||||
def _render_partial_with_layout(layout, options)
|
def _render_partial_with_layout(layout, options)
|
||||||
if layout
|
if layout
|
||||||
prefix = controller && !layout.include?("/") ? controller.controller_path : nil
|
prefix = controller && !layout.include?("/") ? controller.controller_path : nil
|
||||||
layout = find_by_parts(layout, formats, prefix, true)
|
layout = find_by_parts(layout, {:formats => formats}, prefix, true)
|
||||||
end
|
end
|
||||||
content = _render_partial(options)
|
content = _render_partial(options)
|
||||||
return _render_content_with_layout(content, layout, options[:locals])
|
return _render_content_with_layout(content, layout, options[:locals])
|
||||||
|
@ -321,7 +322,7 @@ module ActionView
|
||||||
|
|
||||||
def _pick_partial_template(partial_path) #:nodoc:
|
def _pick_partial_template(partial_path) #:nodoc:
|
||||||
prefix = controller_path unless partial_path.include?('/')
|
prefix = controller_path unless partial_path.include?('/')
|
||||||
find_by_parts(partial_path, formats, prefix, true)
|
find_by_parts(partial_path, {:formats => formats}, prefix, true)
|
||||||
end
|
end
|
||||||
memoize :_pick_partial_template
|
memoize :_pick_partial_template
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,10 +23,10 @@ module ActionView
|
||||||
return _render_partial_with_layout(layout, options) if options.key?(:partial)
|
return _render_partial_with_layout(layout, options) if options.key?(:partial)
|
||||||
return _render_partial_with_block(layout, block, options) if block_given?
|
return _render_partial_with_block(layout, block, options) if block_given?
|
||||||
|
|
||||||
layout = find_by_parts(layout, formats) if layout
|
layout = find_by_parts(layout, {:formats => formats}) if layout
|
||||||
|
|
||||||
if file = options[:file]
|
if file = options[:file]
|
||||||
template = find_by_parts(file, formats)
|
template = find_by_parts(file, {:formats => formats})
|
||||||
_render_template_with_layout(template, layout, :locals => options[:locals])
|
_render_template_with_layout(template, layout, :locals => options[:locals])
|
||||||
elsif inline = options[:inline]
|
elsif inline = options[:inline]
|
||||||
_render_inline(inline, layout, options)
|
_render_inline(inline, layout, options)
|
||||||
|
|
|
@ -16,6 +16,10 @@ module ActionView #:nodoc:
|
||||||
|
|
||||||
@@template_handlers = {}
|
@@template_handlers = {}
|
||||||
@@default_template_handlers = nil
|
@@default_template_handlers = nil
|
||||||
|
|
||||||
|
def self.extensions
|
||||||
|
@@template_handlers.keys
|
||||||
|
end
|
||||||
|
|
||||||
# Register a class that knows how to handle template files with the given
|
# Register a class that knows how to handle template files with the given
|
||||||
# extension. This can be used to implement new template types.
|
# extension. This can be used to implement new template types.
|
||||||
|
|
|
@ -1,13 +1,81 @@
|
||||||
module ActionView
|
module ActionView
|
||||||
class Template
|
class Template
|
||||||
|
# Abstract super class
|
||||||
class Path
|
class Path
|
||||||
attr_reader :path, :paths
|
|
||||||
delegate :hash, :inspect, :to => :path
|
|
||||||
|
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
@cache = options[:cache]
|
@cache = options[:cache]
|
||||||
|
@cached = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Normalizes the arguments and passes it on to find_template
|
||||||
|
def find_by_parts(*args)
|
||||||
|
find_all_by_parts(*args).first
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_all_by_parts(name, details = {}, prefix = nil, partial = nil)
|
||||||
|
details[:locales] = [I18n.locale]
|
||||||
|
name = name.to_s.gsub(handler_matcher, '').split("/")
|
||||||
|
find_templates(name.pop, details, [prefix, *name].compact.join("/"), partial)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# This is what child classes implement. No defaults are needed
|
||||||
|
# because Path guarentees that the arguments are present and
|
||||||
|
# normalized.
|
||||||
|
def find_templates(name, details, prefix, partial)
|
||||||
|
raise NotImplementedError
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: Refactor this to abstract out the file system
|
||||||
|
def initialize_template(file)
|
||||||
|
t = Template.new(file.split("#{self}/").last, self)
|
||||||
|
t.load!
|
||||||
|
t
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_handlers
|
||||||
|
@valid_handlers ||= TemplateHandlers.extensions
|
||||||
|
end
|
||||||
|
|
||||||
|
def handler_matcher
|
||||||
|
@handler_matcher ||= begin
|
||||||
|
e = valid_handlers.join('|')
|
||||||
|
/\.(?:#{e})$/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def handler_glob
|
||||||
|
e = TemplateHandlers.extensions.join(',')
|
||||||
|
".{#{e}}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def formats_glob
|
||||||
|
@formats_glob ||= begin
|
||||||
|
formats = Mime::SET.map { |m| m.symbol }
|
||||||
|
'{' + formats.map { |l| ".#{l}," }.join + '}'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def cached(key)
|
||||||
|
return yield unless @cache
|
||||||
|
return @cached[key] if @cached.key?(key)
|
||||||
|
@cached[key] = yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class FileSystemPath < Path
|
||||||
|
|
||||||
|
def initialize(path, options = {})
|
||||||
|
raise ArgumentError, "path already is a Path class" if path.is_a?(Path)
|
||||||
|
super(options)
|
||||||
|
@path = path
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: This is the currently needed API. Make this suck less
|
||||||
|
# ==== <suck>
|
||||||
|
attr_reader :path
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
if defined?(RAILS_ROOT)
|
if defined?(RAILS_ROOT)
|
||||||
path.to_s.sub(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '')
|
path.to_s.sub(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '')
|
||||||
|
@ -27,61 +95,36 @@ module ActionView
|
||||||
def eql?(path)
|
def eql?(path)
|
||||||
to_str == path.to_str
|
to_str == path.to_str
|
||||||
end
|
end
|
||||||
|
# ==== </suck>
|
||||||
def find_by_parts(name, extensions = nil, prefix = nil, partial = nil)
|
|
||||||
path = prefix ? "#{prefix}/" : ""
|
|
||||||
|
|
||||||
name = name.to_s.split("/")
|
def find_templates(name, details, prefix, partial)
|
||||||
name[-1] = "_#{name[-1]}" if partial
|
if glob = parts_to_glob(name, details, prefix, partial)
|
||||||
|
cached(glob) do
|
||||||
path << name.join("/")
|
Dir[glob].map do |path|
|
||||||
|
initialize_template(path) unless File.directory?(path)
|
||||||
template = nil
|
end.compact
|
||||||
|
end
|
||||||
Array(extensions).each do |extension|
|
|
||||||
extensioned_path = extension ? "#{path}.#{extension}" : path
|
|
||||||
break if (template = find_template(extensioned_path))
|
|
||||||
end
|
end
|
||||||
template || find_template(path)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
private
|
def parts_to_glob(name, details, prefix, partial)
|
||||||
def create_template(file)
|
path = ""
|
||||||
Template.new(file.split("#{self}/").last, self)
|
path << "#{prefix}/" unless prefix.empty?
|
||||||
end
|
path << (partial ? "_#{name}" : name)
|
||||||
end
|
|
||||||
|
|
||||||
class FileSystemPath < Path
|
|
||||||
def initialize(path, options = {})
|
|
||||||
raise ArgumentError, "path already is a Path class" if path.is_a?(Path)
|
|
||||||
|
|
||||||
super(options)
|
|
||||||
@path, @paths = path, {}
|
|
||||||
|
|
||||||
# **/*/** is a hax for symlinked directories
|
|
||||||
load_templates("#{@path}/{**/*,**}/**") if @cache
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def load_template(template)
|
|
||||||
template.load!
|
|
||||||
template.accessible_paths.each do |path|
|
|
||||||
@paths[path] = template
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_template(path)
|
|
||||||
load_templates("#{@path}/#{path}{,.*}") unless @cache
|
|
||||||
@paths[path]
|
|
||||||
end
|
|
||||||
|
|
||||||
def load_templates(glob)
|
|
||||||
Dir[glob].each do |file|
|
|
||||||
load_template(create_template(file)) unless File.directory?(file)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
extensions = ""
|
||||||
|
[:locales, :formats].each do |k|
|
||||||
|
extensions << if exts = details[k]
|
||||||
|
'{' + exts.map {|e| ".#{e},"}.join + '}'
|
||||||
|
else
|
||||||
|
k == :formats ? formats_glob : ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
"#{@path}/#{path}#{extensions}#{handler_glob}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -101,7 +101,7 @@ module ActionView #:nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_type
|
def content_type
|
||||||
format.gsub('.', '/')
|
format && format.gsub('.', '/')
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -139,10 +139,10 @@ module AbstractController
|
||||||
private
|
private
|
||||||
def self.layout(formats)
|
def self.layout(formats)
|
||||||
begin
|
begin
|
||||||
view_paths.find_by_parts(name.underscore, formats, "layouts")
|
view_paths.find_by_parts(name.underscore, {:formats => formats}t, "layouts")
|
||||||
rescue ActionView::MissingTemplate
|
rescue ActionView::MissingTemplate
|
||||||
begin
|
begin
|
||||||
view_paths.find_by_parts("application", formats, "layouts")
|
view_paths.find_by_parts("application", {:formats => formats}, "layouts")
|
||||||
rescue ActionView::MissingTemplate
|
rescue ActionView::MissingTemplate
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,23 +29,19 @@ module RenderTestCases
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_file_with_localization
|
def test_render_file_with_localization
|
||||||
pending do
|
begin
|
||||||
begin
|
old_locale = I18n.locale
|
||||||
old_locale = I18n.locale
|
I18n.locale = :da
|
||||||
I18n.locale = :da
|
assert_equal "Hey verden", @view.render(:file => "test/hello_world")
|
||||||
assert_equal "Hey verden", @view.render(:file => "test/hello_world")
|
ensure
|
||||||
ensure
|
I18n.locale = old_locale
|
||||||
I18n.locale = old_locale
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_file_with_dashed_locale
|
def test_render_file_with_dashed_locale
|
||||||
old_locale = I18n.locale
|
old_locale = I18n.locale
|
||||||
pending do
|
I18n.locale = :"pt-BR"
|
||||||
I18n.locale = :"pt-BR"
|
assert_equal "Ola mundo", @view.render(:file => "test/hello_world")
|
||||||
assert_equal "Ola mundo", @view.render(:file => "test/hello_world")
|
|
||||||
end
|
|
||||||
ensure
|
ensure
|
||||||
I18n.locale = old_locale
|
I18n.locale = old_locale
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue