From b57773c738e2e8f75e92739cf93e402f2a151d5d Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 29 Jul 2011 01:13:58 +0530 Subject: document meta method --- actionpack/lib/action_dispatch/http/request.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index b80574f497..37d0a3e0b8 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -29,9 +29,9 @@ module ActionDispatch ENV_METHODS.each do |env| class_eval <<-METHOD, __FILE__, __LINE__ + 1 - def #{env.sub(/^HTTP_/n, '').downcase} - @env["#{env}"] - end + def #{env.sub(/^HTTP_/n, '').downcase} # def accept_charset + @env["#{env}"] # @env["HTTP_ACCEPT_CHARSET"] + end # end METHOD end -- cgit v1.2.3 From 5b5b22acb5b652a802f2ce36979d452cd1bf52a4 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 25 Jul 2011 19:06:30 -0300 Subject: Remove unused use_sprockets config --- actionpack/lib/abstract_controller/asset_paths.rb | 2 +- actionpack/lib/sprockets/railtie.rb | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/asset_paths.rb b/actionpack/lib/abstract_controller/asset_paths.rb index ad14cd6d87..b104d34fb5 100644 --- a/actionpack/lib/abstract_controller/asset_paths.rb +++ b/actionpack/lib/abstract_controller/asset_paths.rb @@ -3,7 +3,7 @@ module AbstractController extend ActiveSupport::Concern included do - config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, :stylesheets_dir, :use_sprockets + config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, :stylesheets_dir end end end diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index c8d6af942d..83799d2b4d 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -11,13 +11,6 @@ module Sprockets load "sprockets/assets.rake" end - # Configure ActionController to use sprockets. - initializer "sprockets.set_configs", :after => "action_controller.set_configs" do |app| - ActiveSupport.on_load(:action_controller) do - self.use_sprockets = app.config.assets.enabled - end - end - # We need to configure this after initialization to ensure we collect # paths from all engines. This hook is invoked exactly before routes # are compiled, and so that other Railties have an opportunity to -- cgit v1.2.3 From 710c5eaf2f7766885d7c8f448de8b3b3ff8929f6 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Mon, 25 Jul 2011 11:37:25 -0700 Subject: Allow a route to have :format => true When format is true, it is mandatory (as opposed to :format => false). This is currently not possible with resource routes, which automatically make format optional by default. --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 1331f67a78..003bc1dc2c 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -119,6 +119,8 @@ module ActionDispatch path elsif path.include?(":format") || path.end_with?('/') path + elsif @options[:format] == true + "#{path}.:format" else "#{path}(.:format)" end -- cgit v1.2.3 From 16e3c40426c470458764dfd62841d647c725ff35 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 26 Jul 2011 01:00:00 -0300 Subject: use_sprockets is not used anymore --- .../action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb index 0f8a63901e..25cc561608 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb @@ -83,11 +83,7 @@ module ActionView # javascript_path "http://www.example.com/js/xmlhr" # => http://www.example.com/js/xmlhr # javascript_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js def javascript_path(source) - if config.use_sprockets - asset_path(source, 'js') - else - asset_paths.compute_public_path(source, 'javascripts', 'js') - end + asset_paths.compute_public_path(source, 'javascripts', 'js') end alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route -- cgit v1.2.3 From f87b33daaf0f0a93825a3f022d52fcb5aa4c8320 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Fri, 15 Jul 2011 18:22:31 -0400 Subject: fixed problem in which options[:html][:remote] would be overridden in form_for() - fixes #2094 --- actionpack/lib/action_view/helpers/form_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 974c963d44..52a640abf3 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -365,7 +365,7 @@ module ActionView apply_form_for_options!(record, options) end - options[:html][:remote] = options.delete(:remote) + options[:html][:remote] = options.delete(:remote) if options.has_key?(:remote) options[:html][:method] = options.delete(:method) if options.has_key?(:method) options[:html][:authenticity_token] = options.delete(:authenticity_token) -- cgit v1.2.3 From 39183f4ede48db822044abd8e15e6c7f7e93cdd8 Mon Sep 17 00:00:00 2001 From: thoefer Date: Tue, 26 Jul 2011 11:42:53 +0200 Subject: refactored 'assert_redirected_to': local call to validate_request! will be called in assert_response already. changed names of local variables in order to recognize the semantics a bit easier. --- actionpack/lib/action_dispatch/testing/assertions/response.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index a2d639cd56..33c6cd5221 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -55,16 +55,15 @@ module ActionDispatch # assert_redirected_to @customer # def assert_redirected_to(options = {}, message=nil) - validate_request! assert_response(:redirect, message) return true if options == @response.location - redirected_to_after_normalization = normalize_argument_to_redirection(@response.location) - options_after_normalization = normalize_argument_to_redirection(options) + redirect_is = normalize_argument_to_redirection(@response.location) + redirect_expected = normalize_argument_to_redirection(options) - if redirected_to_after_normalization != options_after_normalization - flunk "Expected response to be a redirect to <#{options_after_normalization}> but was a redirect to <#{redirected_to_after_normalization}>" + if redirect_is != redirect_expected + flunk "Expected response to be a redirect to <#{redirect_expected}> but was a redirect to <#{redirect_is}>" end end -- cgit v1.2.3 From 1d64041d59443ace8840748ec72017442cda4ca2 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 26 Jul 2011 19:20:45 -0300 Subject: Remove blank line --- actionpack/lib/action_dispatch/testing/assertions/response.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 33c6cd5221..7381617dd7 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -55,7 +55,6 @@ module ActionDispatch # assert_redirected_to @customer # def assert_redirected_to(options = {}, message=nil) - assert_response(:redirect, message) return true if options == @response.location -- cgit v1.2.3 From f445bb26715406a5718bbf4652bbfa4d8be0b60d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 26 Jul 2011 17:33:22 -0700 Subject: fixing wildcard path matching when wildcard is inside parenthesis --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 003bc1dc2c..ee4d405ce7 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -51,7 +51,7 @@ module ActionDispatch IGNORE_OPTIONS = [:to, :as, :via, :on, :constraints, :defaults, :only, :except, :anchor, :shallow, :shallow_path, :shallow_prefix] ANCHOR_CHARACTERS_REGEX = %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z} SHORTHAND_REGEX = %r{^/[\w/]+$} - WILDCARD_PATH = %r{\*([^/]+)$} + WILDCARD_PATH = %r{\*([^/\)]+)\)?$} def initialize(set, scope, path, options) @set, @scope = set, scope -- cgit v1.2.3 From a704fd4ea9b8ac86f57d357bd8e2a555b69edca9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 26 Jul 2011 17:45:34 -0700 Subject: use regular ruby rather than clever ruby --- actionpack/lib/action_dispatch/routing/mapper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index ee4d405ce7..187e2a8a74 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -105,13 +105,13 @@ module ActionDispatch # controllers with default routes like :controller/:action/:id(.:format), e.g: # GET /admin/products/show/1 # => { :controller => 'admin/products', :action => 'show', :id => '1' } - @options.reverse_merge!(:controller => /.+?/) + @options[:controller] ||= /.+?/ end # Add a constraint for wildcard route to make it non-greedy and match the # optional format part of the route by default if path.match(WILDCARD_PATH) && @options[:format] != false - @options.reverse_merge!(:"#{$1}" => /.+?/) + @options[$1.to_sym] ||= /.+?/ end if @options[:format] == false @@ -264,7 +264,7 @@ module ActionDispatch # because this means it will be matched first. As this is the most popular route # of most Rails applications, this is beneficial. def root(options = {}) - match '/', options.reverse_merge(:as => :root) + match '/', { :as => :root }.merge(options) end # Matches a url pattern to one or more routes. Any symbols in a pattern -- cgit v1.2.3 From ed09aef1a3566ac987f883d743ad1ef773a87ac2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 26 Jul 2011 17:49:19 -0700 Subject: simplify conditionals by assuming hash values will never be `false` --- actionpack/lib/action_dispatch/routing/mapper.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 187e2a8a74..53374949ae 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -224,19 +224,11 @@ module ActionDispatch end def default_controller - if @options[:controller] - @options[:controller] - elsif @scope[:controller] - @scope[:controller] - end + @options[:controller] || @scope[:controller] end def default_action - if @options[:action] - @options[:action] - elsif @scope[:action] - @scope[:action] - end + @options[:action] || @scope[:action] end end -- cgit v1.2.3 From 035d31bd93d68724912d656e03cba7c6b503d25a Mon Sep 17 00:00:00 2001 From: Christos Zisopoulos Date: Wed, 27 Jul 2011 16:12:22 +0200 Subject: Improve performance and memory usage for options_for_select with Ruby 1.8.7 --- actionpack/lib/action_view/helpers/form_options_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 7c43dc04e0..c677257d60 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -323,12 +323,12 @@ module ActionView return container if String === container selected, disabled = extract_selected_and_disabled(selected).map do | r | - Array.wrap(r).map(&:to_s) + Array.wrap(r).map { |item| item.to_s } end container.map do |element| html_attributes = option_html_attributes(element) - text, value = option_text_and_value(element).map(&:to_s) + text, value = option_text_and_value(element).map { |item| item.to_s } selected_attribute = ' selected="selected"' if option_value_selected?(value, selected) disabled_attribute = ' disabled="disabled"' if disabled && option_value_selected?(value, disabled) %() -- cgit v1.2.3 From a636a9358e184bd1a3e2d2522584247be7045cdf Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 27 Jul 2011 15:09:42 -0500 Subject: Make Rails.application.assets available in initializers --- actionpack/lib/sprockets/railtie.rb | 80 +++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 44 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index 83799d2b4d..c8438e6043 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -11,15 +11,20 @@ module Sprockets load "sprockets/assets.rake" end - # We need to configure this after initialization to ensure we collect - # paths from all engines. This hook is invoked exactly before routes - # are compiled, and so that other Railties have an opportunity to - # register compressors. - config.after_initialize do |app| - assets = app.config.assets - next unless assets.enabled + initializer "sprockets.environment" do |app| + config = app.config + next unless config.assets.enabled - app.assets = asset_environment(app) + require 'sprockets' + + app.assets = Sprockets::Environment.new(app.root.to_s) do |env| + env.static_root = File.join(app.root.join('public'), config.assets.prefix) + env.logger = ::Rails.logger + + if config.assets.cache_store != false + env.cache = ActiveSupport::Cache.lookup_store(config.assets.cache_store) || ::Rails.cache + end + end ActiveSupport.on_load(:action_view) do include ::Sprockets::Helpers::RailsHelper @@ -28,53 +33,40 @@ module Sprockets include ::Sprockets::Helpers::RailsHelper end end - - app.routes.prepend do - mount app.assets => assets.prefix - end - - if config.action_controller.perform_caching - app.assets = app.assets.index - end end - protected - def asset_environment(app) - require "sprockets" - - assets = app.config.assets - - env = Sprockets::Environment.new(app.root.to_s) + # We need to configure this after initialization to ensure we collect + # paths from all engines. This hook is invoked exactly before routes + # are compiled, and so that other Railties have an opportunity to + # register compressors. + config.after_initialize do |app| + next unless app.assets + config = app.config - env.static_root = File.join(app.root.join("public"), assets.prefix) + config.assets.paths.each { |path| app.assets.append_path(path) } - if env.respond_to?(:append_path) - assets.paths.each { |path| env.append_path(path) } - else - env.paths.concat assets.paths + if config.assets.compress + # temporarily hardcode default JS compressor to uglify. Soon, it will work + # the same as SCSS, where a default plugin sets the default. + unless config.assets.js_compressor == false + app.assets.js_compressor = LazyCompressor.new { expand_js_compressor(config.assets.js_compressor || :uglifier) } end - env.logger = ::Rails.logger - - if env.respond_to?(:cache) && assets.cache_store != false - env.cache = ActiveSupport::Cache.lookup_store(assets.cache_store) || ::Rails.cache + unless config.assets.css_compressor == false + app.assets.css_compressor = LazyCompressor.new { expand_css_compressor(config.assets.css_compressor) } end + end - if assets.compress - # temporarily hardcode default JS compressor to uglify. Soon, it will work - # the same as SCSS, where a default plugin sets the default. - unless assets.js_compressor == false - env.js_compressor = LazyCompressor.new { expand_js_compressor(assets.js_compressor || :uglifier) } - end - - unless assets.css_compressor == false - env.css_compressor = LazyCompressor.new { expand_css_compressor(assets.css_compressor) } - end - end + app.routes.prepend do + mount app.assets => config.assets.prefix + end - env + if config.action_controller.perform_caching + app.assets = app.assets.index end + end + protected def expand_js_compressor(sym) case sym when :closure -- cgit v1.2.3 From 6e671a8536f17b6f23b5251652015ce8c1557f1f Mon Sep 17 00:00:00 2001 From: Grant Hutchins & Peter Jaros Date: Fri, 8 Jul 2011 17:54:15 -0400 Subject: Let ActiveModel instances define partial paths. Deprecate ActiveModel::Name#partial_path. Now you should call #to_path directly on ActiveModel instances. --- actionpack/lib/action_view/helpers/form_helper.rb | 8 +++- .../lib/action_view/renderer/partial_renderer.rb | 43 +++++++++++----------- 2 files changed, 28 insertions(+), 23 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 52a640abf3..7ea2ea2d5a 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1227,8 +1227,12 @@ module ActionView parent_builder.multipart = multipart if parent_builder end - def self.model_name - @model_name ||= Struct.new(:partial_path).new(name.demodulize.underscore.sub!(/_builder$/, '')) + def self.to_path + @_to_path ||= name.demodulize.underscore.sub!(/_builder$/, '') + end + + def to_path + self.class.to_path end def to_model diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index c0ac332c4e..fc8a6b3107 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -206,13 +206,6 @@ module ActionView # <%- end -%> # <% end %> class PartialRenderer < AbstractRenderer #:nodoc: - PARTIAL_NAMES = Hash.new {|h,k| h[k] = {} } - - def initialize(*) - super - @partial_names = PARTIAL_NAMES[@lookup_context.prefixes.first] - end - def render(context, options, block) setup(context, options, block) @@ -359,28 +352,36 @@ module ActionView segments end + PARTIAL_PATHS = {} + def partial_path(object = @object) - @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| - path = @lookup_context.prefixes.first - merge_path_into_partial(path, partial) - end + object = object.to_model if object.respond_to?(:to_model) + + path = if object.respond_to?(:to_path) + object.to_path + else + ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_path directly instead." + object.class.model_name.partial_path + end + + prefix = @lookup_context.prefixes.first + PARTIAL_PATHS[ [path, prefix] ] ||= path.dup.tap do |object_path| + merge_prefix_into_object_path(prefix, object_path) end end - def merge_path_into_partial(path, partial) - if path.include?(?/) && partial.include?(?/) + def merge_prefix_into_object_path(prefix, object_path) + if prefix.include?(?/) && object_path.include?(?/) overlap = [] - path_array = File.dirname(path).split('/') - partial_array = partial.split('/')[0..-3] # skip model dir & partial + prefix_array = File.dirname(prefix).split('/') + object_path_array = object_path.split('/')[0..-3] # skip model dir & partial - path_array.each_with_index do |dir, index| - overlap << dir if dir == partial_array[index] + prefix_array.each_with_index do |dir, index| + overlap << dir if dir == object_path_array[index] end - partial.gsub!(/^#{overlap.join('/')}\//,'') - partial.insert(0, "#{File.dirname(path)}/") + object_path.gsub!(/^#{overlap.join('/')}\//,'') + object_path.insert(0, "#{File.dirname(prefix)}/") end end -- cgit v1.2.3 From 91ca214ca0aa431f3cbe90d660c22129b3584bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 28 Jul 2011 09:56:42 +0200 Subject: Rename class method to_path to _to_path and make it explicit that it is an internal method. --- actionpack/lib/action_view/helpers/form_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 7ea2ea2d5a..85dea96bbb 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1227,12 +1227,12 @@ module ActionView parent_builder.multipart = multipart if parent_builder end - def self.to_path + def self._to_path @_to_path ||= name.demodulize.underscore.sub!(/_builder$/, '') end def to_path - self.class.to_path + self.class._to_path end def to_model -- cgit v1.2.3 From 554ea3c37b21be56f7f82c1179f2553dc445dc37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 28 Jul 2011 10:01:55 +0200 Subject: Move the cache to a nested hash which performs better than a hash with array as keys. --- .../lib/action_view/renderer/partial_renderer.rb | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index fc8a6b3107..f67388b8cf 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -206,6 +206,14 @@ module ActionView # <%- end -%> # <% end %> class PartialRenderer < AbstractRenderer #:nodoc: + PARTIAL_NAMES = Hash.new { |h,k| h[k] = {} } + + def initialize(*) + super + @context_prefix = @lookup_context.prefixes.first + @partial_names = PARTIAL_NAMES[@context_prefix] + end + def render(context, options, block) setup(context, options, block) @@ -284,6 +292,7 @@ module ActionView else paths.map! { |path| retrieve_variable(path).unshift(path) } end + if String === partial && @variable.to_s !~ /^[a-z_][a-zA-Z_0-9]*$/ raise ArgumentError.new("The partial name (#{partial}) is not a valid Ruby identifier; " + "make sure your partial name starts with a letter or underscore, " + @@ -352,21 +361,18 @@ module ActionView segments end - PARTIAL_PATHS = {} - def partial_path(object = @object) object = object.to_model if object.respond_to?(:to_model) path = if object.respond_to?(:to_path) - object.to_path - else - ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_path directly instead." - object.class.model_name.partial_path - end - - prefix = @lookup_context.prefixes.first - PARTIAL_PATHS[ [path, prefix] ] ||= path.dup.tap do |object_path| - merge_prefix_into_object_path(prefix, object_path) + object.to_path + else + ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_path directly instead." + object.class.model_name.partial_path + end + + @partial_names[path] ||= path.dup.tap do |object_path| + merge_prefix_into_object_path(@context_prefix, object_path) end end -- cgit v1.2.3 From 37b30d4b4eb983579f083627b3faa065be527a61 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Thu, 28 Jul 2011 20:00:48 +0200 Subject: There is no need to be destructive with the passed-in options. This fixes a bug that is caused by Resource/SingletonResource mangling resource options when using inline "multi"-resource declarations. --- actionpack/lib/action_dispatch/routing/mapper.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 53374949ae..a53a2d98d3 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -872,9 +872,9 @@ module ActionDispatch def initialize(entities, options = {}) @name = entities.to_s - @path = (options.delete(:path) || @name).to_s - @controller = (options.delete(:controller) || @name).to_s - @as = options.delete(:as) + @path = (options[:path] || @name).to_s + @controller = (options[:controller] || @name).to_s + @as = options[:as] @options = options end @@ -938,9 +938,9 @@ module ActionDispatch def initialize(entities, options) @as = nil @name = entities.to_s - @path = (options.delete(:path) || @name).to_s - @controller = (options.delete(:controller) || plural).to_s - @as = options.delete(:as) + @path = (options[:path] || @name).to_s + @controller = (options[:controller] || plural).to_s + @as = options[:as] @options = options end -- cgit v1.2.3 From a53ef972066503e601e023748949b6668fce51e3 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Thu, 28 Jul 2011 20:02:21 +0200 Subject: Make use of the inherited initializer. --- actionpack/lib/action_dispatch/routing/mapper.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index a53a2d98d3..bd04f48c00 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -936,12 +936,11 @@ module ActionDispatch DEFAULT_ACTIONS = [:show, :create, :update, :destroy, :new, :edit] def initialize(entities, options) + super + @as = nil - @name = entities.to_s - @path = (options[:path] || @name).to_s @controller = (options[:controller] || plural).to_s @as = options[:as] - @options = options end def plural -- cgit v1.2.3 From 018b1315b561d9c2e6c95151f8145f21cac6eb91 Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Thu, 28 Jul 2011 18:45:43 +0300 Subject: We don't need to require erb here. --- actionpack/lib/action_dispatch/routing/mapper.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index bd04f48c00..a5c1501f61 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1,4 +1,3 @@ -require 'erb' require 'active_support/core_ext/hash/except' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/inclusion' -- cgit v1.2.3 From 759815547bf85167e97b3cdbff2f1e8d33e218e4 Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Fri, 29 Jul 2011 17:07:27 -0700 Subject: remove redundant calls to stringify_keys --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 822686b09d..79f07400b2 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -417,7 +417,7 @@ module ActionView options["data-confirm"] = confirm end - tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys) + tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options) end # Creates a button element that defines a submit button, @@ -503,7 +503,7 @@ module ActionView options["data-confirm"] = confirm end - tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options.stringify_keys) + tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options) end # Creates a field set for grouping HTML form elements. -- cgit v1.2.3 From b6b6e81a5c29d4adb3007659ca30e02444ad0c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 1 Aug 2011 11:42:00 +0200 Subject: Rename new method to_path to to_partial_path to avoid conflicts with File#to_path and similar. --- actionpack/lib/action_view/helpers/form_helper.rb | 8 ++++---- actionpack/lib/action_view/renderer/partial_renderer.rb | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 85dea96bbb..f22c466666 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1227,12 +1227,12 @@ module ActionView parent_builder.multipart = multipart if parent_builder end - def self._to_path - @_to_path ||= name.demodulize.underscore.sub!(/_builder$/, '') + def self._to_partial_path + @_to_partial_path ||= name.demodulize.underscore.sub!(/_builder$/, '') end - def to_path - self.class._to_path + def to_partial_path + self.class._to_partial_path end def to_model diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index f67388b8cf..cd0f7054a9 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -364,10 +364,10 @@ module ActionView def partial_path(object = @object) object = object.to_model if object.respond_to?(:to_model) - path = if object.respond_to?(:to_path) - object.to_path + path = if object.respond_to?(:to_partial_path) + object.to_partial_path else - ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_path directly instead." + ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_partial_path directly instead." object.class.model_name.partial_path end -- cgit v1.2.3 From 5f3265c4714efd697cb71015489a9c59d1129440 Mon Sep 17 00:00:00 2001 From: thoefer Date: Mon, 1 Aug 2011 11:28:31 +0200 Subject: Fix the issue where default_url_options is being cached on test cases. Closes #1872. Closes #2031. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_controller/metal/testing.rb | 5 +++++ actionpack/lib/action_controller/test_case.rb | 1 + 2 files changed, 6 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/testing.rb b/actionpack/lib/action_controller/metal/testing.rb index f4efeb33ba..d1813ee745 100644 --- a/actionpack/lib/action_controller/metal/testing.rb +++ b/actionpack/lib/action_controller/metal/testing.rb @@ -4,6 +4,11 @@ module ActionController include RackDelegation + def recycle! + @_url_options = nil + end + + # TODO: Clean this up def process_with_new_base_test(request, response) @_request = request diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 45bb641aee..c8cf04bb69 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -450,6 +450,7 @@ module ActionController @controller.params.merge!(parameters) build_request_uri(action, parameters) @controller.class.class_eval { include Testing } + @controller.recycle! @controller.process_with_new_base_test(@request, @response) @assigns = @controller.respond_to?(:view_assigns) ? @controller.view_assigns : {} @request.session.delete('flash') if @request.session['flash'].blank? -- cgit v1.2.3 From 68c4b66015dd17e1a91a8ddc90b634d5cfc0f9ff Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Fri, 29 Jul 2011 17:43:05 -0700 Subject: fix stringify_keys destructive behavior for most FormTagHelper functions add four new tests to verify that the other three methods that called stringify_keys! are fixed. verified that the tests break in master without the code patch. Closes #2355 --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 79f07400b2..2bbe0c175f 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -304,7 +304,7 @@ module ActionView # text_area_tag 'comment', nil, :class => 'comment_input' # # => def text_area_tag(name, content = nil, options = {}) - options.stringify_keys! + options = options.stringify_keys if size = options.delete("size") options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split) @@ -407,7 +407,7 @@ module ActionView # data-confirm="Are you sure?" /> # def submit_tag(value = "Save changes", options = {}) - options.stringify_keys! + options = options.stringify_keys if disable_with = options.delete("disable_with") options["data-disable-with"] = disable_with @@ -458,7 +458,7 @@ module ActionView def button_tag(content_or_options = nil, options = nil, &block) options = content_or_options if block_given? && content_or_options.is_a?(Hash) options ||= {} - options.stringify_keys! + options = options.stringify_keys if disable_with = options.delete("disable_with") options["data-disable-with"] = disable_with @@ -497,7 +497,7 @@ module ActionView # image_submit_tag("agree.png", :disabled => true, :class => "agree_disagree_button") # # => def image_submit_tag(source, options = {}) - options.stringify_keys! + options = options.stringify_keys if confirm = options.delete("confirm") options["data-confirm"] = confirm -- cgit v1.2.3 From ebfca248f9084f8176f6b5b993d9c3c99d06737b Mon Sep 17 00:00:00 2001 From: Casebook Developer Date: Thu, 4 Aug 2011 13:34:47 -0400 Subject: ActionView::Helpers::TextHelper#simple_format should not change the text in place. Now it duplicates it. --- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index ae71ade588..21074efe86 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -256,7 +256,7 @@ module ActionView # # => "

I'm allowed! It's true.

" def simple_format(text, html_options={}, options={}) text = '' if text.nil? - text = text.dup if text.frozen? + text = text.dup start_tag = tag('p', html_options, true) text = sanitize(text) unless options[:sanitize] == false text = text.to_str -- cgit v1.2.3 From 53e1a9d411b2a8720de6958662e9f8f2dd7af2be Mon Sep 17 00:00:00 2001 From: geemus Date: Thu, 11 Aug 2011 14:43:48 -0500 Subject: update abstract_controller callbacks to document meta-programmed filters --- actionpack/lib/abstract_controller/callbacks.rb | 120 ++++++++++++++++++++---- 1 file changed, 102 insertions(+), 18 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb index e8426bc52b..14c984e41f 100644 --- a/actionpack/lib/abstract_controller/callbacks.rb +++ b/actionpack/lib/abstract_controller/callbacks.rb @@ -75,38 +75,122 @@ module AbstractController end end + ## + # :method: before_filter + # + # :call-seq: before_filter(names, block) + # + # Append a before filter. See _insert_callbacks for parameter details. + + ## + # :method: prepend_before_filter + # + # :call-seq: prepend_before_filter(names, block) + # + # Prepend a before filter. See _insert_callbacks for parameter details. + + ## + # :method: skip_before_filter + # + # :call-seq: skip_before_filter(names, block) + # + # Skip a before filter. See _insert_callbacks for parameter details. + + ## + # :method: append_before_filter + # + # :call-seq: append_before_filter(names, block) + # + # Append a before filter. See _insert_callbacks for parameter details. + + ## + # :method: after_filter + # + # :call-seq: after_filter(names, block) + # + # Append an after filter. See _insert_callbacks for parameter details. + + ## + # :method: prepend_after_filter + # + # :call-seq: prepend_after_filter(names, block) + # + # Prepend an after filter. See _insert_callbacks for parameter details. + + ## + # :method: skip_after_filter + # + # :call-seq: skip_after_filter(names, block) + # + # Skip an after filter. See _insert_callbacks for parameter details. + + ## + # :method: append_after_filter + # + # :call-seq: append_after_filter(names, block) + # + # Append an after filter. See _insert_callbacks for parameter details. + + ## + # :method: around_filter + # + # :call-seq: around_filter(names, block) + # + # Append an around filter. See _insert_callbacks for parameter details. + + ## + # :method: prepend_around_filter + # + # :call-seq: prepend_around_filter(names, block) + # + # Prepend an around filter. See _insert_callbacks for parameter details. + + ## + # :method: skip_around_filter + # + # :call-seq: skip_around_filter(names, block) + # + # Skip an around filter. See _insert_callbacks for parameter details. + + ## + # :method: append_around_filter + # + # :call-seq: append_around_filter(names, block) + # + # Append an around filter. See _insert_callbacks for parameter details. + # set up before_filter, prepend_before_filter, skip_before_filter, etc. # for each of before, after, and around. [:before, :after, :around].each do |filter| class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 # Append a before, after or around filter. See _insert_callbacks # for details on the allowed parameters. - def #{filter}_filter(*names, &blk) - _insert_callbacks(names, blk) do |name, options| - options[:if] = (Array.wrap(options[:if]) << "!halted") if #{filter == :after} - set_callback(:process_action, :#{filter}, name, options) - end - end + def #{filter}_filter(*names, &blk) # def before_filter(*names, &blk) + _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options| + options[:if] = (Array.wrap(options[:if]) << "!halted") if #{filter == :after} # options[:if] = (Array.wrap(options[:if]) << "!halted") if false + set_callback(:process_action, :#{filter}, name, options) # set_callback(:process_action, :before, name, options) + end # end + end # end # Prepend a before, after or around filter. See _insert_callbacks # for details on the allowed parameters. - def prepend_#{filter}_filter(*names, &blk) - _insert_callbacks(names, blk) do |name, options| - options[:if] = (Array.wrap(options[:if]) << "!halted") if #{filter == :after} - set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) - end - end + def prepend_#{filter}_filter(*names, &blk) # def prepend_before_filter(*names, &blk) + _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options| + options[:if] = (Array.wrap(options[:if]) << "!halted") if #{filter == :after} # options[:if] = (Array.wrap(options[:if]) << "!halted") if false + set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) # set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) + end # end + end # end # Skip a before, after or around filter. See _insert_callbacks # for details on the allowed parameters. - def skip_#{filter}_filter(*names, &blk) - _insert_callbacks(names, blk) do |name, options| - skip_callback(:process_action, :#{filter}, name, options) - end - end + def skip_#{filter}_filter(*names, &blk) # def skip_before_filter(*names, &blk) + _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options| + skip_callback(:process_action, :#{filter}, name, options) # skip_callback(:process_action, :#{filter}, name, options) + end # end + end # end # *_filter is the same as append_*_filter - alias_method :append_#{filter}_filter, :#{filter}_filter + alias_method :append_#{filter}_filter, :#{filter}_filter # alias_method :append_before_filter, :before_filter RUBY_EVAL end end -- cgit v1.2.3 From aa0d3cece80f6181bbd664596c46fc0f65b4abbe Mon Sep 17 00:00:00 2001 From: Oge Nnadi Date: Fri, 12 Aug 2011 12:00:32 -0300 Subject: Typo fix --- actionpack/lib/action_controller/caching/actions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index 667ba15cc9..0031d2701f 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -38,7 +38,7 @@ module ActionController #:nodoc: # :action => 'lists' is not the same as # :action => 'list', :format => :xml. # - # You can set modify the default action cache path by passing a + # You can modify the default action cache path by passing a # :cache_path option. This will be passed directly to # ActionCachePath.path_for. This is handy for actions with # multiple possible routes that should be cached differently. If a -- cgit v1.2.3