aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-03-15 19:46:03 +0000
committerPratik Naik <pratiknaik@gmail.com>2010-03-15 19:46:03 +0000
commit03a62f4afedbef8bda72c8fdf9a0092273c0f2b0 (patch)
tree2155b65750757d26e3c8c8e0655ad32cc89d6c2e /actionpack/lib/action_view
parentf53fddf3665e6582768f4ab0c82b286b39e7fb19 (diff)
parenta594a22267bfd3346e00923742c4aa7edad0cef7 (diff)
downloadrails-03a62f4afedbef8bda72c8fdf9a0092273c0f2b0.tar.gz
rails-03a62f4afedbef8bda72c8fdf9a0092273c0f2b0.tar.bz2
rails-03a62f4afedbef8bda72c8fdf9a0092273c0f2b0.zip
Merge remote branch 'mainstream/master'
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/base.rb11
-rw-r--r--actionpack/lib/action_view/helpers/active_model_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb28
-rw-r--r--actionpack/lib/action_view/helpers/capture_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb1
-rw-r--r--actionpack/lib/action_view/helpers/tag_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb2
-rw-r--r--actionpack/lib/action_view/lookup_context.rb11
-rw-r--r--actionpack/lib/action_view/render/layouts.rb9
-rw-r--r--actionpack/lib/action_view/render/partials.rb2
-rw-r--r--actionpack/lib/action_view/render/rendering.rb45
-rw-r--r--actionpack/lib/action_view/template/handlers/rjs.rb3
-rw-r--r--actionpack/lib/action_view/template/text.rb14
13 files changed, 48 insertions, 84 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index ffe3060404..feaf45c333 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -194,7 +194,7 @@ module ActionView #:nodoc:
attr_accessor :base_path, :assigns, :template_extension, :lookup_context
attr_internal :captures, :request, :layout, :controller, :template, :config
- delegate :find, :exists?, :formats, :formats=, :locale, :locale=,
+ delegate :find_template, :template_exists?, :formats, :formats=, :locale, :locale=,
:view_paths, :view_paths=, :with_fallbacks, :update_details, :to => :lookup_context
delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
@@ -264,14 +264,5 @@ module ActionView #:nodoc:
response.body_parts << part
nil
end
-
- # Evaluates the local assigns and controller ivars, pushes them to the view.
- def _evaluate_assigns_and_ivars #:nodoc:
- if controller
- variables = controller.instance_variable_names
- variables -= controller.protected_instance_variables if controller.respond_to?(:protected_instance_variables)
- variables.each { |name| instance_variable_set(name, controller.instance_variable_get(name)) }
- end
- end
end
end
diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb
index 4e12cdab54..e3db2923f7 100644
--- a/actionpack/lib/action_view/helpers/active_model_helper.rb
+++ b/actionpack/lib/action_view/helpers/active_model_helper.rb
@@ -129,7 +129,7 @@ module ActionView
if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) &&
(errors = obj.errors[method])
content_tag("div",
- (options[:prepend_text].html_safe << errors.first).safe_concat(options[:append_text]),
+ "#{options[:prepend_text]}#{ERB::Util.h(errors.first)}#{options[:append_text]}".html_safe,
:class => options[:css_class]
)
else
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 0c488b6793..03ae8ce0d8 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -242,12 +242,12 @@ module ActionView
# == Caching multiple javascripts into one
#
# You can also cache multiple javascripts into one file, which requires less HTTP connections to download and can better be
- # compressed by gzip (leading to faster transfers). Caching will only happen if ActionController::Base.perform_caching
+ # compressed by gzip (leading to faster transfers). Caching will only happen if config.perform_caching
# is set to <tt>true</tt> (which is the case by default for the Rails production environment, but not for the development
# environment).
#
# ==== Examples
- # javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is false =>
+ # javascript_include_tag :all, :cache => true # when config.perform_caching is false =>
# <script type="text/javascript" src="/javascripts/prototype.js"></script>
# <script type="text/javascript" src="/javascripts/effects.js"></script>
# ...
@@ -255,15 +255,15 @@ module ActionView
# <script type="text/javascript" src="/javascripts/shop.js"></script>
# <script type="text/javascript" src="/javascripts/checkout.js"></script>
#
- # javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is true =>
+ # javascript_include_tag :all, :cache => true # when config.perform_caching is true =>
# <script type="text/javascript" src="/javascripts/all.js"></script>
#
- # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is false =>
+ # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when config.perform_caching is false =>
# <script type="text/javascript" src="/javascripts/prototype.js"></script>
# <script type="text/javascript" src="/javascripts/cart.js"></script>
# <script type="text/javascript" src="/javascripts/checkout.js"></script>
#
- # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is true =>
+ # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when config.perform_caching is true =>
# <script type="text/javascript" src="/javascripts/shop.js"></script>
#
# The <tt>:recursive</tt> option is also available for caching:
@@ -275,11 +275,11 @@ module ActionView
cache = concat || options.delete("cache")
recursive = options.delete("recursive")
- if concat || (ActionController::Base.perform_caching && cache)
+ if concat || (config.perform_caching && cache)
joined_javascript_name = (cache == true ? "all" : cache) + ".js"
joined_javascript_path = File.join(joined_javascript_name[/^#{File::SEPARATOR}/] ? config.assets_dir : config.javascripts_dir, joined_javascript_name)
- unless ActionController::Base.perform_caching && File.exists?(joined_javascript_path)
+ unless config.perform_caching && File.exists?(joined_javascript_path)
write_asset_file_contents(joined_javascript_path, compute_javascript_paths(sources, recursive))
end
javascript_src_tag(joined_javascript_name, options)
@@ -390,25 +390,25 @@ module ActionView
# == Caching multiple stylesheets into one
#
# You can also cache multiple stylesheets into one file, which requires less HTTP connections and can better be
- # compressed by gzip (leading to faster transfers). Caching will only happen if ActionController::Base.perform_caching
+ # compressed by gzip (leading to faster transfers). Caching will only happen if config.perform_caching
# is set to true (which is the case by default for the Rails production environment, but not for the development
# environment). Examples:
#
# ==== Examples
- # stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is false =>
+ # stylesheet_link_tag :all, :cache => true # when config.perform_caching is false =>
# <link href="/stylesheets/style1.css" media="screen" rel="stylesheet" type="text/css" />
# <link href="/stylesheets/styleB.css" media="screen" rel="stylesheet" type="text/css" />
# <link href="/stylesheets/styleX2.css" media="screen" rel="stylesheet" type="text/css" />
#
- # stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is true =>
+ # stylesheet_link_tag :all, :cache => true # when config.perform_caching is true =>
# <link href="/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />
#
- # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is false =>
+ # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when config.perform_caching is false =>
# <link href="/stylesheets/shop.css" media="screen" rel="stylesheet" type="text/css" />
# <link href="/stylesheets/cart.css" media="screen" rel="stylesheet" type="text/css" />
# <link href="/stylesheets/checkout.css" media="screen" rel="stylesheet" type="text/css" />
#
- # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is true =>
+ # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when config.perform_caching is true =>
# <link href="/stylesheets/payment.css" media="screen" rel="stylesheet" type="text/css" />
#
# The <tt>:recursive</tt> option is also available for caching:
@@ -426,11 +426,11 @@ module ActionView
cache = concat || options.delete("cache")
recursive = options.delete("recursive")
- if concat || (ActionController::Base.perform_caching && cache)
+ if concat || (config.perform_caching && cache)
joined_stylesheet_name = (cache == true ? "all" : cache) + ".css"
joined_stylesheet_path = File.join(joined_stylesheet_name[/^#{File::SEPARATOR}/] ? config.assets_dir : config.stylesheets_dir, joined_stylesheet_name)
- unless ActionController::Base.perform_caching && File.exists?(joined_stylesheet_path)
+ unless config.perform_caching && File.exists?(joined_stylesheet_path)
write_asset_file_contents(joined_stylesheet_path, compute_stylesheet_paths(sources, recursive))
end
stylesheet_tag(joined_stylesheet_name, options)
diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb
index 75fc2fddeb..03c7ba5a87 100644
--- a/actionpack/lib/action_view/helpers/capture_helper.rb
+++ b/actionpack/lib/action_view/helpers/capture_helper.rb
@@ -140,7 +140,7 @@ module ActionView
def with_output_buffer(buf = nil) #:nodoc:
unless buf
buf = ActionView::OutputBuffer.new
- buf.force_encoding(output_buffer.encoding) if buf.respond_to?(:force_encoding)
+ buf.force_encoding(output_buffer.encoding) if output_buffer && buf.respond_to?(:force_encoding)
end
self.output_buffer, old_buffer = buf, output_buffer
yield
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index 4d6ea7dfb2..dc3c6d88f5 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -180,7 +180,6 @@ module ActionView
# #include_helpers_from_context has nothing to overwrite.
class JavaScriptGenerator #:nodoc:
def initialize(context, &block) #:nodoc:
- context._evaluate_assigns_and_ivars
@context, @lines = context, []
@context.update_details(:formats => [:js, :html]) do
include_helpers_from_context
diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb
index 8ae2e5f28f..9b4cacd4d7 100644
--- a/actionpack/lib/action_view/helpers/tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/tag_helper.rb
@@ -109,7 +109,7 @@ module ActionView
def content_tag_string(name, content, options, escape = true)
tag_options = tag_options(options, escape) if options
- ("<#{name}#{tag_options}>".html_safe << content.to_s).safe_concat("</#{name}>")
+ "<#{name}#{tag_options}>#{ERB::Util.h(content)}</#{name}>".html_safe
end
def tag_options(options, escape = true)
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index ae1385f3b7..131e950b18 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -224,7 +224,7 @@ module ActionView
end
href_attr = "href=\"#{url}\"" unless href
- ("<a #{href_attr}#{tag_options}>".html_safe << (name || url)).safe_concat("</a>")
+ "<a #{href_attr}#{tag_options}>#{ERB::Util.h(name || url)}</a>".html_safe
end
end
diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb
index 27ee8b23c9..8eb17bf8f1 100644
--- a/actionpack/lib/action_view/lookup_context.rb
+++ b/actionpack/lib/action_view/lookup_context.rb
@@ -38,17 +38,18 @@ module ActionView
register_detail(:locale) { [I18n.locale] }
class DetailsKey #:nodoc:
- attr_reader :details
alias :eql? :equal?
+ alias :object_hash :hash
+ attr_reader :hash
@details_keys = Hash.new
def self.get(details)
- @details_keys[details] ||= new(details)
+ @details_keys[details] ||= new
end
- def initialize(details)
- @details, @hash = details, details.hash
+ def initialize
+ @hash = object_hash
end
end
@@ -70,6 +71,7 @@ module ActionView
def find(name, prefix = nil, partial = false)
@view_paths.find(name, prefix, partial, details, details_key)
end
+ alias :find_template :find
def find_all(name, prefix = nil, partial = false)
@view_paths.find_all(name, prefix, partial, details, details_key)
@@ -78,6 +80,7 @@ module ActionView
def exists?(name, prefix = nil, partial = false)
@view_paths.exists?(name, prefix, partial, details, details_key)
end
+ alias :template_exists? :exists?
# Add fallbacks to the view paths. Useful in cases you are rendering a :file.
def with_fallbacks
diff --git a/actionpack/lib/action_view/render/layouts.rb b/actionpack/lib/action_view/render/layouts.rb
index e9252dba9e..11ff05ce5b 100644
--- a/actionpack/lib/action_view/render/layouts.rb
+++ b/actionpack/lib/action_view/render/layouts.rb
@@ -1,8 +1,5 @@
-require 'active_support/core_ext/object/try'
-
module ActionView
module Layouts
-
# You can think of a layout as a method that is called with a block. _layout_for
# returns the contents that are yielded to the layout. If the user calls yield
# :some_name, the block, by default, returns content_for(:some_name). If the user
@@ -46,13 +43,13 @@ module ActionView
# This is the method which actually finds the layout using details in the lookup
# context object. If no layout is found, it checkes if at least a layout with
# the given name exists across all details before raising the error.
- def _find_layout(layout) #:nodoc:
+ def find_layout(layout) #:nodoc:
begin
layout =~ /^\// ?
- with_fallbacks { find(layout) } : find(layout)
+ with_fallbacks { find_template(layout) } : find_template(layout)
rescue ActionView::MissingTemplate => e
update_details(:formats => nil) do
- raise unless exists?(layout)
+ raise unless template_exists?(layout)
end
end
end
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb
index d34ab0354c..17d16556b9 100644
--- a/actionpack/lib/action_view/render/partials.rb
+++ b/actionpack/lib/action_view/render/partials.rb
@@ -294,7 +294,7 @@ module ActionView
def find_template(path=@path)
return path unless path.is_a?(String)
prefix = @view.controller_path unless path.include?(?/)
- @view.find(path, prefix, true)
+ @view.find_template(path, prefix, true)
end
def partial_path(object = @object)
diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb
index 47ea70f5ad..310efe40e2 100644
--- a/actionpack/lib/action_view/render/rendering.rb
+++ b/actionpack/lib/action_view/render/rendering.rb
@@ -12,14 +12,18 @@ module ActionView
#
# If no options hash is passed or :update specified, the default is to render a partial and use the second parameter
# as the locals hash.
- def render(options = {}, locals = {}, &block) #:nodoc:
+ def render(options = {}, locals = {}, &block)
case options
when Hash
if block_given?
content = _render_partial(options.merge(:partial => options[:layout]), &block)
safe_concat(content)
+ elsif options.key?(:partial)
+ _render_partial(options)
else
- _render(options)
+ template = _determine_template(options)
+ self.formats = template.formats
+ _render_template(template, options[:layout], options)
end
when :update
update_page(&block)
@@ -28,44 +32,18 @@ module ActionView
end
end
- # This is the API to render a ViewContext's template from a controller.
- def render_template(options, &block)
- _evaluate_assigns_and_ivars
-
- # TODO Layout for partials should be handled here, because inside the
- # partial renderer it looks for the layout as a partial.
- if options.key?(:partial) && options[:layout]
- options[:layout] = _find_layout(options[:layout])
- end
-
- _render(options, &block)
- end
-
- # This method holds the common render logic for both controllers and
- # views rendering stacks.
- def _render(options) #:nodoc:
- if options.key?(:partial)
- _render_partial(options)
- else
- template = _determine_template(options)
- yield template if block_given?
- _render_template(template, options[:layout], options)
- end
- end
-
# Determine the template to be rendered using the given options.
def _determine_template(options) #:nodoc:
if options.key?(:inline)
handler = Template.handler_class_for_extension(options[:type] || "erb")
Template.new(options[:inline], "inline template", handler, {})
elsif options.key?(:text)
- Template::Text.new(options[:text], self.formats.try(:first))
- elsif options.key?(:_template)
- options[:_template]
+ Template::Text.new(options[:text], formats.try(:first))
elsif options.key?(:file)
- with_fallbacks { find(options[:file], options[:prefix]) }
+ with_fallbacks { find_template(options[:file], options[:prefix]) }
elsif options.key?(:template)
- find(options[:template], options[:prefix])
+ options[:template].respond_to?(:render) ?
+ options[:template] : find_template(options[:template], options[:prefix])
end
end
@@ -73,7 +51,7 @@ module ActionView
# supplied as well.
def _render_template(template, layout = nil, options = {}) #:nodoc:
locals = options[:locals] || {}
- layout = _find_layout(layout) if layout
+ layout = find_layout(layout) if layout
ActiveSupport::Notifications.instrument("action_view.render_template",
:identifier => template.identifier, :layout => layout.try(:identifier)) do
@@ -89,6 +67,5 @@ module ActionView
content
end
end
-
end
end
diff --git a/actionpack/lib/action_view/template/handlers/rjs.rb b/actionpack/lib/action_view/template/handlers/rjs.rb
index 63e7dc0902..128be5077c 100644
--- a/actionpack/lib/action_view/template/handlers/rjs.rb
+++ b/actionpack/lib/action_view/template/handlers/rjs.rb
@@ -6,8 +6,7 @@ module ActionView
self.default_format = Mime::JS
def compile(template)
- "controller.response.content_type ||= Mime::JS;" +
- "update_page do |page|;#{template.source}\nend"
+ "update_page do |page|;#{template.source}\nend"
end
def default_format
diff --git a/actionpack/lib/action_view/template/text.rb b/actionpack/lib/action_view/template/text.rb
index df394b0fb0..269340514c 100644
--- a/actionpack/lib/action_view/template/text.rb
+++ b/actionpack/lib/action_view/template/text.rb
@@ -1,10 +1,12 @@
module ActionView #:nodoc:
class Template
class Text < String #:nodoc:
- def initialize(string, content_type = nil)
+ attr_accessor :mime_type
+
+ def initialize(string, mime_type = nil)
super(string.to_s)
- @content_type = Mime[content_type] || content_type if content_type
- @content_type ||= Mime::TEXT
+ @mime_type = Mime[mime_type] || mime_type if mime_type
+ @mime_type ||= Mime::TEXT
end
def identifier
@@ -19,12 +21,8 @@ module ActionView #:nodoc:
to_s
end
- def mime_type
- @content_type
- end
-
def formats
- [@content_type.to_sym]
+ [@mime_type.to_sym]
end
def partial?