Permalink
Browse files

Merge remote-tracking branch 'rails/3-1-stable' into asset_urls

* rails/3-1-stable: (49 commits)
  Add JavaScript Runtime name to the Rails Info properties (thanks Sam Ruby)
  Merge pull request #1481 from arunagw/lib_assets
  Improve ordering of multiple columns on postgresql
  judgement -> judgment, according to guidelines
  Follow rails convention by using Array.wrap
  Allow to specify mass-assignment roles as array
  Apply the default scope earlier when doing calculations. Fixes #1682.
  updated rspec link
  grammar changes in named routes description and clarity around possibilities for options
  font style changes in perf guide
  grammar changes to log subscriber docs
  move example code to be above reconfiguring discussion; add clarity about silencers and filters; misc grammar changes - for backtrace cleaners
  Fixed typo
  use present tense on examples
  more detail on how the flow between redirect and show works, and minor grammar
  remove extra space and clarify how an exception is made for controller wide layouts
  reorder layout selection examples to occur in the order that the code does, and provide more detail on why each selection is made
  singularize module and be explicit about what is delivered
  grammar (missing "a") and formatting
  elaborate details on why to use _url instead of _path in mailers
  ...

Conflicts:
	actionpack/lib/action_view/helpers/asset_paths.rb
	actionpack/lib/sprockets/helpers/rails_helper.rb
  • Loading branch information...
2 parents 0e5891a + 94c08a6 commit 4b8bd7a54f9c7e892443e06a843892d48e7f4393 @chriseppstein chriseppstein committed Jun 27, 2011
Showing with 601 additions and 303 deletions.
  1. +1 −4 Gemfile
  2. +4 −0 Rakefile
  3. +6 −5 actionmailer/lib/action_mailer/base.rb
  4. +1 −1 actionmailer/lib/action_mailer/delivery_methods.rb
  5. +1 −1 actionpack/actionpack.gemspec
  6. +9 −8 actionpack/lib/abstract_controller/layouts.rb
  7. +9 −7 actionpack/lib/action_controller/base.rb
  8. +1 −0 actionpack/lib/action_controller/caching/sweeping.rb
  9. +1 −0 actionpack/lib/action_view.rb
  10. +147 −0 actionpack/lib/action_view/asset_paths.rb
  11. +2 −143 actionpack/lib/action_view/helpers/asset_paths.rb
  12. +1 −2 actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb
  13. +4 −6 actionpack/lib/action_view/helpers/cache_helper.rb
  14. +10 −10 actionpack/lib/action_view/helpers/url_helper.rb
  15. +3 −4 actionpack/lib/sprockets/helpers/rails_helper.rb
  16. +4 −0 actionpack/lib/sprockets/railtie.rb
  17. +5 −0 actionpack/test/controller/filters_test.rb
  18. +11 −4 activemodel/lib/active_model/mass_assignment_security.rb
  19. +14 −0 activemodel/test/cases/mass_assignment_security_test.rb
  20. +9 −1 activemodel/test/models/mass_assignment_specific.rb
  21. +8 −0 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
  22. +2 −0 activerecord/lib/active_record/connection_adapters/column.rb
  23. +1 −1 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  24. +8 −0 activerecord/lib/active_record/query_cache.rb
  25. +7 −6 activerecord/lib/active_record/railties/databases.rake
  26. +11 −5 activerecord/lib/active_record/relation/calculations.rb
  27. +7 −0 activerecord/test/cases/connection_management_test.rb
  28. +11 −0 activerecord/test/cases/query_cache_test.rb
  29. +7 −0 activerecord/test/cases/relation_scoping_test.rb
  30. +7 −0 activerecord/test/cases/relations_test.rb
  31. +6 −0 activerecord/test/models/developer.rb
  32. +16 −11 activesupport/lib/active_support/backtrace_cleaner.rb
  33. +17 −7 activesupport/lib/active_support/core_ext/class/attribute.rb
  34. +4 −4 activesupport/lib/active_support/log_subscriber.rb
  35. +6 −0 activesupport/test/core_ext/class/attribute_test.rb
  36. +5 −9 railties/CHANGELOG
  37. +27 −0 railties/guides/source/active_record_querying.textile
  38. +15 −3 railties/guides/source/active_support_core_extensions.textile
  39. +1 −3 railties/guides/source/association_basics.textile
  40. +1 −1 railties/guides/source/contributing_to_ruby_on_rails.textile
  41. +1 −1 railties/guides/source/form_helpers.textile
  42. +6 −6 railties/guides/source/getting_started.textile
  43. +2 −2 railties/guides/source/performance_testing.textile
  44. +1 −1 railties/guides/source/testing.textile
  45. +23 −0 railties/lib/rails.rb
  46. +20 −8 railties/lib/rails/generators/app_base.rb
  47. +1 −0 railties/lib/rails/generators/rails/app/app_generator.rb
  48. +11 −7 railties/lib/rails/generators/rails/app/templates/Gemfile
  49. +4 −3 railties/lib/rails/generators/rails/app/templates/config/application.rb
  50. +62 −0 railties/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml
  51. +3 −3 railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml
  52. +3 −12 railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml
  53. +3 −3 railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml
  54. +3 −4 railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
  55. +4 −0 railties/lib/rails/info.rb
  56. +10 −5 railties/lib/rails/tasks/assets.rake
  57. +13 −1 railties/test/application/assets_test.rb
  58. +15 −0 railties/test/application/configuration_test.rb
  59. +2 −1 railties/test/generators/app_generator_test.rb
  60. +4 −0 railties/test/isolation/abstract_unit.rb
View
@@ -10,7 +10,7 @@ end
gem "coffee-script"
gem "sass"
-gem "uglifier", :git => "git://github.com/lautis/uglifier.git"
+gem "uglifier", ">= 1.0.0"
gem "rake", ">= 0.8.7"
gem "mocha", ">= 0.9.8"
@@ -26,9 +26,6 @@ gem "memcache-client", ">= 1.8.5"
platforms :mri_18 do
gem "system_timer"
- # ruby-debug requires linecache which depends on require_relative but doesn't explicitly
- # declare this in its gemspec
- gem "require_relative"
gem "ruby-debug", ">= 0.10.3"
gem "json"
end
View
@@ -61,6 +61,9 @@ RDoc::Task.new do |rdoc|
# The temporary solution is to have a README.rdoc without backslashes for
# GitHub, and gsub it to generate the main page of the API.
#
+ # Also, relative links in GitHub have to point to blobs, whereas in the API
+ # they need to point to files.
+ #
# The idea for the future is to have totally different files, since the
# API is no longer a generic entry point to Rails and deserves a
# dedicated main page specifically thought as an API entry point.
@@ -71,6 +74,7 @@ RDoc::Task.new do |rdoc|
# since no autolinking happens there and RDoc displays the backslash
# otherwise.
rdoc_main.gsub!(/^(?=\S).*?\b(?=Rails)\b/) { "#$&\\" }
+ rdoc_main.gsub!(%r{link:blob/master/(\w+)/README\.rdoc}, "link:files/\\1/README_rdoc.html")
File.open(RDOC_MAIN, 'w') do |f|
f.write(rdoc_main)
@@ -123,8 +123,9 @@ module ActionMailer #:nodoc:
#
# <%= users_url(:host => "example.com") %>
#
- # You want to avoid using the <tt>name_of_route_path</tt> form of named routes because it doesn't
- # make sense to generate relative URLs in email messages.
+ # You should use the <tt>named_route_url</tt> style (which generates absolute URLs) and avoid using the
+ # <tt>named_route_path</tt> style (which generates relative URLs), since clients reading the mail will
+ # have no concept of a current URL from which to determine a relative path.
#
# It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt>
# option as a configuration option in <tt>config/application.rb</tt>:
@@ -152,9 +153,9 @@ module ActionMailer #:nodoc:
#
# = Multipart Emails
#
- # Multipart messages can also be used implicitly because Action Mailer will automatically
- # detect and use multipart templates, where each template is named after the name of the action, followed
- # by the content type. Each such detected template will be added as separate part to the message.
+ # Multipart messages can also be used implicitly because Action Mailer will automatically detect and use
+ # multipart templates, where each template is named after the name of the action, followed by the content
+ # type. Each such detected template will be added as a separate part to the message.
#
# For example, if the following templates exist:
# * signup_notification.text.erb
@@ -1,7 +1,7 @@
require 'tmpdir'
module ActionMailer
- # This modules handles everything related to the delivery, from registering new
+ # This module handles everything related to mail delivery, from registering new
# delivery methods to configuring the mail object to be sent.
module DeliveryMethods
extend ActiveSupport::Concern
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
s.add_dependency('rack', '~> 1.3.0')
s.add_dependency('rack-test', '~> 0.6.0')
s.add_dependency('rack-mount', '~> 0.8.1')
- s.add_dependency('sprockets', '~> 2.0.0.beta.10')
+ s.add_dependency('sprockets', '= 2.0.0.beta.10')
s.add_dependency('tzinfo', '~> 0.3.27')
s.add_dependency('erubis', '~> 2.7.0')
end
@@ -81,11 +81,12 @@ module AbstractController
# class EmployeeController < BankController
# layout nil
#
- # The InformationController uses "bank_standard" inherited from the BankController, the VaultController overwrites
- # and picks the layout dynamically, and the EmployeeController doesn't want to use a layout at all.
- #
- # The TellerController uses +teller.html.erb+, and TillController inherits that layout and
- # uses it as well.
+ # In these examples:
+ # * The InformationController uses the "bank_standard" layout, inherited from BankController.
+ # * The TellerController follows convention and uses +app/views/layouts/teller.html.erb+.
+ # * The TillController inherits the layout from TellerController and uses +teller.html.erb+ as well.
+ # * The VaultController chooses a layout dynamically by calling the <tt>access_level_layout</tt> method.
+ # * The EmployeeController does not use a layout at all.
#
# == Types of layouts
#
@@ -138,8 +139,8 @@ module AbstractController
#
# end
#
- # This will assign "weblog_standard" as the WeblogController's layout except for the +rss+ action, which will not wrap a layout
- # around the rendered view.
+ # This will assign "weblog_standard" as the WeblogController's layout for all actions except for the +rss+ action, which will
+ # be rendered directly, without wrapping a layout around the rendered view.
#
# Both the <tt>:only</tt> and <tt>:except</tt> condition can accept an arbitrary number of method references, so
# #<tt>:except => [ :rss, :text_only ]</tt> is valid, as is <tt>:except => :rss</tt>.
@@ -158,7 +159,7 @@ module AbstractController
# end
# end
#
- # This will render the help action with the "help" layout instead of the controller-wide "weblog_standard" layout.
+ # This will override the controller-wide "weblog_standard" layout, and will render the help action with the "help" layout instead.
module Layouts
extend ActiveSupport::Concern
@@ -31,7 +31,7 @@ module ActionController
# "302 Moved" HTTP response that takes the user to the index action.
#
# These two methods represent the two basic action archetypes used in Action Controllers. Get-and-show and do-and-redirect.
- # Most actions are variations of these themes.
+ # Most actions are variations on these themes.
#
# == Requests
#
@@ -116,8 +116,8 @@ module ActionController
#
# Title: <%= @post.title %>
#
- # You don't have to rely on the automated rendering. Especially actions that could result in the rendering of different templates will use
- # the manual rendering methods:
+ # You don't have to rely on the automated rendering. For example, actions that could result in the rendering of different templates
+ # will use the manual rendering methods:
#
# def search
# @results = Search.find(params[:query])
@@ -132,9 +132,9 @@ module ActionController
#
# == Redirects
#
- # Redirects are used to move from one action to another. For example, after a <tt>create</tt> action, which stores a blog entry to a database,
- # we might like to show the user the new entry. Because we're following good DRY principles (Don't Repeat Yourself), we're going to reuse (and redirect to)
- # a <tt>show</tt> action that we'll assume has already been created. The code might look like this:
+ # Redirects are used to move from one action to another. For example, after a <tt>create</tt> action, which stores a blog entry to the
+ # database, we might like to show the user the new entry. Because we're following good DRY principles (Don't Repeat Yourself), we're
+ # going to reuse (and redirect to) a <tt>show</tt> action that we'll assume has already been created. The code might look like this:
#
# def create
# @entry = Entry.new(params[:entry])
@@ -146,7 +146,9 @@ module ActionController
# end
# end
#
- # In this case, after saving our new entry to the database, the user is redirected to the <tt>show</tt> method which is then executed.
+ # In this case, after saving our new entry to the database, the user is redirected to the <tt>show</tt> method, which is then executed.
+ # Note that this is an external HTTP-level redirection which will cause the browser to make a second request (a GET to the show action),
+ # and not some internal re-routing which calls both "create" and then "show" within one request.
#
# Learn more about <tt>redirect_to</tt> and what options you have in ActionController::Redirecting.
#
@@ -61,6 +61,7 @@ def before(controller)
end
def after(controller)
+ self.controller = controller
callback(:after) if controller.perform_caching
# Clean up, so that the controller can be collected after this request
self.controller = nil
@@ -30,6 +30,7 @@ module ActionView
extend ActiveSupport::Autoload
eager_autoload do
+ autoload :AssetPaths
autoload :Base
autoload :Context
autoload :Helpers
@@ -0,0 +1,147 @@
+require 'active_support/core_ext/file'
+
+module ActionView
+
+ class AssetPaths #:nodoc:
+ attr_reader :config, :controller
+
+ def initialize(config, controller = nil)
+ @config = config
+ @controller = controller
+ end
+
+ # Add the extension +ext+ if not present. Return full or scheme-relative URLs otherwise untouched.
+ # Prefix with <tt>/dir/</tt> if lacking a leading +/+. Account for relative URL
+ # roots. Rewrite the asset path for cache-busting asset ids. Include
+ # asset host, if configured, with the correct request protocol.
+ #
+ # When include_host is true and the asset host does not specify the protocol
+ # the protocol parameter specifies how the protocol will be added.
+ # When :relative (default), the protocol will be determined by the client using current protocol
+ # When :request, the protocol will be the request protocol
+ # Otherwise, the protocol is used (E.g. :http, :https, etc)
+ def compute_public_path(source, dir, ext = nil, include_host = true, protocol = nil)
+ source = source.to_s
+ return source if is_uri?(source)
+
+ source = rewrite_extension(source, dir, ext) if ext
+ source = rewrite_asset_path(source, dir)
+ source = rewrite_relative_url_root(source, relative_url_root) if has_request?
+ source = rewrite_host_and_protocol(source, protocol) if include_host
+ source
+ end
+
+ # Return the filesystem path for the source
+ def compute_source_path(source, dir, ext)
+ source = rewrite_extension(source, dir, ext) if ext
+ File.join(config.assets_dir, dir, source)
+ end
+
+ def is_uri?(path)
+ path =~ %r{^[-a-z]+://|^cid:|^//}
+ end
+
+ private
+
+ def rewrite_extension(source, dir, ext)
+ raise NotImplementedError
+ end
+
+ def rewrite_asset_path(source, path = nil)
+ raise NotImplementedError
+ end
+
+ def rewrite_relative_url_root(source, relative_url_root)
+ relative_url_root && !source.starts_with?("#{relative_url_root}/") ? "#{relative_url_root}#{source}" : source
+ end
+
+ def has_request?
+ controller.respond_to?(:request)
+ end
+
+ def rewrite_host_and_protocol(source, protocol = nil)
+ host = compute_asset_host(source)
+ if host && !is_uri?(host)
+ if (protocol || default_protocol) == :request && !has_request?
+ host = nil
+ else
+ host = "#{compute_protocol(protocol)}#{host}"
+ end
+ end
+ host.nil? ? source : "#{host}#{source}"
+ end
+
+ def compute_protocol(protocol)
+ protocol ||= default_protocol
+ case protocol
+ when :relative
+ "//"
+ when :request
+ unless @controller
+ invalid_asset_host!("The protocol requested was :request. Consider using :relative instead.")
+ end
+ @controller.request.protocol
+ else
+ "#{protocol}://"
+ end
+ end
+
+ def default_protocol
+ protocol = @config.action_controller.default_asset_host_protocol if @config.action_controller.present?
+ protocol ||= @config.default_asset_host_protocol
+ protocol || (has_request? ? :request : :relative)
+ end
+
+ def invalid_asset_host!(help_message)
+ raise ActionController::RoutingError, "This asset host cannot be computed without a request in scope. #{help_message}"
+ end
+
+ # Pick an asset host for this source. Returns +nil+ if no host is set,
+ # the host if no wildcard is set, the host interpolated with the
+ # numbers 0-3 if it contains <tt>%d</tt> (the number is the source hash mod 4),
+ # or the value returned from invoking the proc if it's a proc or the value from
+ # invoking call if it's an object responding to call.
+ def compute_asset_host(source)
+ if host = asset_host_config
+ if host.respond_to?(:call)
+ args = [source]
+ arity = arity_of(host)
+ if arity > 1 && !has_request?
+ invalid_asset_host!("Remove the second argument to your asset_host Proc if you do not need the request.")
+ end
+ args << current_request if (arity > 1 || arity < 0) && has_request?
+ host.call(*args)
+ else
+ (host =~ /%d/) ? host % (source.hash % 4) : host
+ end
+ end
+ end
+
+ def relative_url_root
+ config = controller.config if controller.respond_to?(:config)
+ config ||= config.action_controller if config.action_controller.present?
+ config ||= config
+ config.relative_url_root
+ end
+
+ def asset_host_config
+ if config.action_controller.present?
+ config.action_controller.asset_host
+ else
+ config.asset_host
+ end
+ end
+
+ # Returns the current request if one exists.
+ def current_request
+ controller.request if has_request?
+ end
+
+ # Returns the arity of a callable
+ def arity_of(callable)
+ callable.respond_to?(:arity) ? callable.arity : callable.method(:call).arity
+ end
+
+ end
+
+end
Oops, something went wrong.

0 comments on commit 4b8bd7a

Please sign in to comment.