diff options
author | Xavier Noria <fxn@hashref.com> | 2010-04-03 10:56:15 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-04-03 10:56:15 -0700 |
commit | 11161e6c96fb6686a33e05ead106b96089ff9790 (patch) | |
tree | 35d5618f1a866ce8ba11efd8e6851d2fd7bbf5fc /actionpack/lib/action_view | |
parent | 4996d1a445acd965d0064500ad00d692a742f669 (diff) | |
parent | 467d251c3dcbd3e4dd1e785a21d63535b795a64c (diff) | |
download | rails-11161e6c96fb6686a33e05ead106b96089ff9790.tar.gz rails-11161e6c96fb6686a33e05ead106b96089ff9790.tar.bz2 rails-11161e6c96fb6686a33e05ead106b96089ff9790.zip |
Merge commit 'rails/master'
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 7 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/url_helper.rb | 52 | ||||
-rw-r--r-- | actionpack/lib/action_view/render/partials.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_view/template.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_view/test_case.rb | 7 |
7 files changed, 64 insertions, 25 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index a9b0715b2e..fde61e9df9 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -168,6 +168,8 @@ module ActionView #:nodoc: remove_method :helpers attr_reader :helpers + class_attribute :_router + class << self delegate :erb_trim_mode=, :to => 'ActionView::Template::Handlers::ERB' delegate :logger, :to => 'ActionController::Base', :allow_nil => true @@ -204,7 +206,10 @@ module ActionView #:nodoc: @assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) } @helpers = self.class.helpers || Module.new - @_controller = controller + if @_controller = controller + @_request = controller.request if controller.respond_to?(:request) + end + @_config = ActiveSupport::InheritableOptions.new(controller.config) if controller && controller.respond_to?(:config) @_content_for = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new } @_virtual_path = nil diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb index a50c180f63..ba3bdd0d18 100644 --- a/actionpack/lib/action_view/helpers.rb +++ b/actionpack/lib/action_view/helpers.rb @@ -29,16 +29,13 @@ module ActionView #:nodoc: autoload :TranslationHelper autoload :UrlHelper - def self.included(base) - base.extend(ClassMethods) - end + extend ActiveSupport::Concern - module ClassMethods - include SanitizeHelper::ClassMethods + included do + extend SanitizeHelper::ClassMethods end include ActiveSupport::Benchmarkable - include ActiveModelHelper include AssetTagHelper include AtomFeedHelper diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 89560d0b49..6a14f0be9c 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -96,6 +96,7 @@ module ActionView extend ActiveSupport::Concern include FormTagHelper + include UrlHelper # Creates a form and a scope around a specific model object that is used # as a base for questioning about values for the fields. diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index b23d5fcb68..1415966869 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -13,14 +13,15 @@ module ActionView extend ActiveSupport::Concern include ActionDispatch::Routing::UrlFor - include JavaScriptHelper + include TagHelper # Need to map default url options to controller one. - def default_url_options(*args) #:nodoc: - controller.send(:default_url_options, *args) - end - + # def default_url_options(*args) #:nodoc: + # controller.send(:default_url_options, *args) + # end + # def url_options + return super unless controller.respond_to?(:url_options) controller.url_options end @@ -97,7 +98,7 @@ module ActionView when Hash options = { :only_path => options[:host].nil? }.update(options.symbolize_keys) escape = options.key?(:escape) ? options.delete(:escape) : false - controller.send(:url_for, options) + super when :back escape = false controller.request.env["HTTP_REFERER"] || 'javascript:history.back()' @@ -119,13 +120,24 @@ module ActionView # # ==== Signatures # - # link_to(name, options = {}, html_options = nil) - # link_to(options = {}, html_options = nil) do + # link_to(body, url, html_options = {}) + # # url is a String; you can use URL helpers like + # # posts_path + # + # link_to(body, url_options = {}, html_options = {}) + # # url_options, except :confirm or :method, + # # is passed to url_for + # + # link_to(options = {}, html_options = {}) do + # # name + # end + # + # link_to(url, html_options = {}) do # # name # end # # ==== Options - # * <tt>:confirm => 'question?'</tt> - This will allow the unobtrusive JavaScript + # * <tt>:confirm => 'question?'</tt> - This will allow the unobtrusive JavaScript # driver to prompt with the question specified. If the user accepts, the link is # processed normally, otherwise no action is taken. # * <tt>:method => symbol of HTTP verb</tt> - This modifier will dynamically @@ -138,7 +150,11 @@ module ActionView # disabled clicking the link will have no effect. If you are relying on the # POST behavior, you should check for it in your controller's action by using # the request object's methods for <tt>post?</tt>, <tt>delete?</tt> or <tt>put?</tt>. - # * The +html_options+ will accept a hash of html attributes for the link tag. + # * <tt>:remote => true</tt> - This will allow the unobtrusive JavaScript + # driver to make an Ajax request to the URL in question instead of following + # the link. The drivers each provide mechanisms for listening for the + # completion of the Ajax request and performing JavaScript operations once + # they're complete # # ==== Examples # Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments @@ -220,8 +236,8 @@ module ActionView options = args[1] || {} html_options = args[2] - url = url_for(options) html_options = convert_options_to_data_attributes(options, html_options) + url = url_for(options) if html_options html_options = html_options.stringify_keys @@ -259,10 +275,10 @@ module ActionView # There are a few special +html_options+: # * <tt>:method</tt> - Specifies the anchor name to be appended to the path. # * <tt>:disabled</tt> - Specifies the anchor name to be appended to the path. - # * <tt>:confirm</tt> - This will use the unobtrusive JavaScript driver to + # * <tt>:confirm</tt> - This will use the unobtrusive JavaScript driver to # prompt with the question specified. If the user accepts, the link is # processed normally, otherwise no action is taken. - # * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the + # * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the # submit behaviour. By default this behaviour is an ajax submit. # # ==== Examples @@ -282,7 +298,7 @@ module ActionView # # </form>" # # - # <%= button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', + # <%= button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', # :method => "delete", :remote => true, :disable_with => 'loading...') %> # # => "<form class='button-to' method='post' action='http://www.example.com' data-remote='true'> # # <div> @@ -546,8 +562,14 @@ module ActionView # current_page?(:controller => 'library', :action => 'checkout') # # => false def current_page?(options) + unless request + raise "You cannot use helpers that need to determine the current " \ + "page unless your view context provides a Request object " \ + "in a #request method" + end + url_string = CGI.unescapeHTML(url_for(options)) - request = controller.request + # We ignore any extra parameters in the request_uri if the # submitted url doesn't have any either. This lets the function # work with things like ?order=asc diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index f04a89c1ac..4d23d55687 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -179,7 +179,7 @@ module ActionView def initialize(view_context, options, block) @view = view_context - @partial_names = PARTIAL_NAMES[@view.controller.class] + @partial_names = PARTIAL_NAMES[@view.controller.class.name] setup(options, block) end @@ -300,7 +300,7 @@ module ActionView end def partial_path(object = @object) - @partial_names[object.class] ||= begin + @partial_names[object.class.name] ||= begin object = object.to_model if object.respond_to?(:to_model) object.class.model_name.partial_path.dup.tap do |partial| diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 8abc1633ff..3df2bd8eed 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -18,6 +18,14 @@ module ActionView attr_reader :source, :identifier, :handler, :virtual_path, :formats + def self.finalizer_for(method_name) + proc do + ActionView::CompiledTemplates.module_eval do + remove_possible_method method_name + end + end + end + def initialize(source, identifier, handler, details) @source = source @identifier = identifier @@ -98,6 +106,7 @@ module ActionView begin ActionView::CompiledTemplates.module_eval(source, identifier, line) + ObjectSpace.define_finalizer(self, self.class.finalizer_for(method_name)) method_name rescue Exception => e # errors from template code if logger = (view && view.logger) diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 23b0c6e121..ddea9cfd92 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -142,8 +142,13 @@ module ActionView end end + def _router + @controller._router if @controller.respond_to?(:_router) + end + def method_missing(selector, *args) - if @controller._router.named_routes.helpers.include?(selector) + if @controller.respond_to?(:_router) && + @controller._router.named_routes.helpers.include?(selector) @controller.__send__(selector, *args) else super |