Permalink
Browse files

Merge branch 'master' of github.com:rails/rails

  • Loading branch information...
2 parents 1fc7954 + badc39f commit affd05d28b3fbd0f6cbbf6e6823e352405f4fd34 @dhh dhh committed Oct 10, 2012
Showing with 266 additions and 1,349 deletions.
  1. +4 −0 actionmailer/CHANGELOG.md
  2. +1 −1 actionmailer/lib/rails/generators/mailer/USAGE
  3. +0 −145 actionpack/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb
  4. +7 −132 actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
  5. +9 −89 actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb
  6. +0 −14 actionpack/lib/action_view/railtie.rb
  7. +0 −752 actionpack/test/template/asset_tag_helper_test.rb
  8. +1 −1 activerecord/lib/active_record/associations/collection_association.rb
  9. +0 −17 activerecord/lib/active_record/sanitization.rb
  10. +8 −0 activerecord/test/cases/associations/join_model_test.rb
  11. +2 −0 activesupport/lib/active_support/core_ext/array/conversions.rb
  12. +1 −1 activesupport/lib/active_support/core_ext/date/calculations.rb
  13. +3 −1 activesupport/lib/active_support/core_ext/hash/conversions.rb
  14. +2 −5 activesupport/lib/active_support/core_ext/object.rb
  15. +0 −4 activesupport/lib/active_support/core_ext/object/conversions.rb
  16. +0 −1 activesupport/test/core_ext/array_ext_test.rb
  17. +0 −1 activesupport/test/core_ext/hash_ext_test.rb
  18. +2 −0 guides/CHANGELOG.md
  19. +1 −1 guides/code/getting_started/app/assets/javascripts/application.js
  20. +2 −0 guides/source/4_0_release_notes.md
  21. +1 −1 guides/source/action_mailer_basics.md
  22. +15 −4 guides/source/active_support_core_extensions.md
  23. +11 −11 guides/source/command_line.md
  24. +9 −9 guides/source/engines.md
  25. +6 −6 guides/source/generators.md
  26. +12 −12 guides/source/getting_started.md
  27. +1 −1 guides/source/initialization.md
  28. +17 −13 guides/source/testing.md
  29. +10 −2 railties/CHANGELOG.md
  30. +4 −2 railties/lib/rails/generators/rails/app/app_generator.rb
  31. +1 −1 railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt
  32. +0 −8 railties/lib/rails/generators/rails/app/templates/config/application.rb
  33. +7 −0 railties/lib/rails/generators/rails/app/templates/config/initializers/locale.rb
  34. +4 −4 railties/lib/rails/generators/rails/controller/USAGE
  35. +1 −1 railties/lib/rails/generators/rails/helper/USAGE
  36. +2 −2 railties/lib/rails/generators/rails/model/USAGE
  37. +1 −1 railties/lib/rails/generators/rails/observer/USAGE
  38. +4 −4 railties/lib/rails/generators/rails/scaffold_controller/USAGE
  39. +1 −1 railties/lib/rails/generators/test_unit/controller/controller_generator.rb
  40. +1 −1 railties/lib/rails/generators/test_unit/helper/helper_generator.rb
  41. +1 −1 railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb
  42. +1 −1 railties/lib/rails/generators/test_unit/model/model_generator.rb
  43. +1 −1 railties/lib/rails/generators/test_unit/observer/observer_generator.rb
  44. +1 −1 railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
  45. +6 −2 railties/lib/rails/tasks/statistics.rake
  46. +30 −6 railties/lib/rails/test_unit/testing.rake
  47. +1 −1 railties/test/application/asset_debugging_test.rb
  48. +0 −15 railties/test/application/assets_test.rb
  49. +6 −6 railties/test/application/rake_test.rb
  50. +7 −7 railties/test/commands/console_test.rb
  51. +4 −2 railties/test/generators/app_generator_test.rb
  52. +4 −4 railties/test/generators/controller_generator_test.rb
  53. +1 −1 railties/test/generators/helper_generator_test.rb
  54. +1 −1 railties/test/generators/mailer_generator_test.rb
  55. +3 −3 railties/test/generators/model_generator_test.rb
  56. +25 −25 railties/test/generators/namespaced_generators_test.rb
  57. +1 −1 railties/test/generators/observer_generator_test.rb
  58. +5 −5 railties/test/generators/resource_generator_test.rb
  59. +4 −4 railties/test/generators/scaffold_controller_generator_test.rb
  60. +13 −13 railties/test/generators/scaffold_generator_test.rb
@@ -27,4 +27,8 @@
* Asynchronously send messages via the Rails Queue *Brian Cardarella*
+* Allow callbacks to be defined in mailers similar to `ActionController::Base`. You can configure default
+ settings, headers, attachments, delivery settings or change delivery using
+ `before_filter`, `after_filter` etc. *Justin S. Leitgeb*
+
Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/actionmailer/CHANGELOG.md) for previous changes.
@@ -13,6 +13,6 @@ Example:
creates a Notifications mailer class, views, test, and fixtures:
Mailer: app/mailers/notifications.rb
Views: app/views/notifications/signup.erb [...]
- Test: test/functional/notifications_test.rb
+ Test: test/mailers/notifications_test.rb
Fixtures: test/fixtures/notifications/signup [...]
@@ -1,145 +0,0 @@
-require 'active_support/core_ext/string/inflections'
-require 'active_support/core_ext/file'
-require 'action_view/helpers/tag_helper'
-
-module ActionView
- module Helpers
- module AssetTagHelper
-
- class AssetIncludeTag #:nodoc:
- include TagHelper
-
- attr_reader :config, :asset_paths
- class_attribute :expansions
-
- def self.inherited(base)
- base.expansions = { }
- end
-
- def initialize(config, asset_paths)
- @config = config
- @asset_paths = asset_paths
- end
-
- def asset_name
- raise NotImplementedError
- end
-
- def extension
- raise NotImplementedError
- end
-
- def custom_dir
- raise NotImplementedError
- end
-
- def asset_tag(source, options)
- raise NotImplementedError
- end
-
- def include_tag(*sources)
- options = sources.extract_options!.stringify_keys
- concat = options.delete("concat")
- cache = concat || options.delete("cache")
- recursive = options.delete("recursive")
-
- if concat || (config.perform_caching && cache)
- joined_name = (cache == true ? "all" : cache) + ".#{extension}"
- joined_path = File.join((joined_name[/^#{File::SEPARATOR}/] ? config.assets_dir : custom_dir), joined_name)
- unless config.perform_caching && File.exists?(joined_path)
- write_asset_file_contents(joined_path, compute_paths(sources, recursive))
- end
- asset_tag(joined_name, options)
- else
- sources = expand_sources(sources, recursive)
- ensure_sources!(sources) if cache
- sources.collect { |source| asset_tag(source, options) }.join("\n").html_safe
- end
- end
-
- private
-
- def path_to_asset(source, options = {})
- asset_paths.compute_public_path(source, asset_name.to_s.pluralize, options.merge(:ext => extension))
- end
-
- def path_to_asset_source(source)
- asset_paths.compute_source_path(source, asset_name.to_s.pluralize, extension)
- end
-
- def compute_paths(*args)
- expand_sources(*args).collect { |source| path_to_asset_source(source) }
- end
-
- def expand_sources(sources, recursive)
- if sources.first == :all
- collect_asset_files(custom_dir, ('**' if recursive), "*.#{extension}")
- else
- sources.inject([]) do |list, source|
- determined_source = determine_source(source, expansions)
- update_source_list(list, determined_source)
- end
- end
- end
-
- def update_source_list(list, source)
- case source
- when String
- list.delete(source)
- list << source
- when Array
- updated_sources = source - list
- list.concat(updated_sources)
- end
- end
-
- def ensure_sources!(sources)
- sources.each do |source|
- asset_file_path!(path_to_asset_source(source))
- end
- end
-
- def collect_asset_files(*path)
- dir = path.first
-
- Dir[File.join(*path.compact)].collect do |file|
- file[-(file.size - dir.size - 1)..-1].sub(/\.\w+$/, '')
- end.sort
- end
-
- def determine_source(source, collection)
- case source
- when Symbol
- collection[source] || raise(ArgumentError, "No expansion found for #{source.inspect}")
- else
- source
- end
- end
-
- def join_asset_file_contents(paths)
- paths.collect { |path| File.read(asset_file_path!(path, true)) }.join("\n\n")
- end
-
- def write_asset_file_contents(joined_asset_path, asset_paths)
- FileUtils.mkdir_p(File.dirname(joined_asset_path))
- File.atomic_write(joined_asset_path) { |cache| cache.write(join_asset_file_contents(asset_paths)) }
-
- # Set mtime to the latest of the combined files to allow for
- # consistent ETag without a shared filesystem.
- mt = asset_paths.map { |p| File.mtime(asset_file_path!(p)) }.max
- File.utime(mt, mt, joined_asset_path)
- end
-
- def asset_file_path!(absolute_path, error_if_file_is_uri = false)
- if asset_paths.is_uri?(absolute_path)
- raise(Errno::ENOENT, "Asset file #{path} is uri and cannot be merged into single file") if error_if_file_is_uri
- else
- raise(Errno::ENOENT, "Asset file not found at '#{absolute_path}'" ) unless File.exist?(absolute_path)
- return absolute_path
- end
- end
- end
-
- end
- end
-end
@@ -1,76 +1,11 @@
require 'active_support/core_ext/file'
-require 'action_view/helpers/asset_tag_helpers/asset_include_tag'
module ActionView
module Helpers
module AssetTagHelper
-
- class JavascriptIncludeTag < AssetIncludeTag #:nodoc:
- def asset_name
- 'javascript'
- end
-
- def extension
- 'js'
- end
-
- def asset_tag(source, options)
- content_tag("script", "", { "src" => path_to_asset(source) }.merge(options))
- end
-
- def custom_dir
- config.javascripts_dir
- end
-
- private
-
- def expand_sources(sources, recursive = false)
- if sources.include?(:all)
- all_asset_files = (collect_asset_files(custom_dir, ('**' if recursive), "*.#{extension}") - ['application'])
- add_application_js(all_asset_files, sources)
- ((determine_source(:defaults, expansions).dup & all_asset_files) + all_asset_files).uniq
- else
- expanded_sources = sources.inject([]) do |list, source|
- determined_source = determine_source(source, expansions)
- update_source_list(list, determined_source)
- end
- add_application_js(expanded_sources, sources)
- expanded_sources
- end
- end
-
- def add_application_js(expanded_sources, sources)
- if (sources.include?(:defaults) || sources.include?(:all)) && File.exist?(File.join(custom_dir, "application.#{extension}"))
- expanded_sources.delete('application')
- expanded_sources << "application"
- end
- end
- end
-
-
module JavascriptTagHelpers
extend ActiveSupport::Concern
- module ClassMethods
- # Register one or more javascript files to be included when <tt>symbol</tt>
- # is passed to <tt>javascript_include_tag</tt>. This method is typically intended
- # to be called from plugin initialization to register javascript files
- # that the plugin installed in <tt>public/javascripts</tt>.
- #
- # ActionView::Helpers::AssetTagHelper.register_javascript_expansion :monkey => ["head", "body", "tail"]
- #
- # javascript_include_tag :monkey # =>
- # <script src="/javascripts/head.js"></script>
- # <script src="/javascripts/body.js"></script>
- # <script src="/javascripts/tail.js"></script>
- def register_javascript_expansion(expansions)
- js_expansions = JavascriptIncludeTag.expansions
- expansions.each do |key, values|
- js_expansions[key] = (js_expansions[key] || []) | Array(values)
- end
- end
- end
-
# Computes the path to a javascript asset in the public javascripts directory.
# If the +source+ filename has no extension, .js will be appended (except for explicit URIs)
# Full paths from the document root will be passed through.
@@ -101,15 +36,6 @@ def javascript_url(source)
#
# When passing paths, the ".js" extension is optional.
#
- # If the application is not using the asset pipeline, to include the default JavaScript
- # expansion pass <tt>:defaults</tt> as source. By default, <tt>:defaults</tt> loads jQuery,
- # and that can be overridden in <tt>config/application.rb</tt>:
- #
- # config.action_view.javascript_expansions[:defaults] = %w(foo.js bar.js)
- #
- # When using <tt>:defaults</tt> or <tt>:all</tt>, if an <tt>application.js</tt> file exists
- # in <tt>public/javascripts</tt> it will be included as well at the end.
- #
# You can modify the HTML attributes of the script tag by passing a hash as the
# last argument.
#
@@ -129,65 +55,14 @@ def javascript_url(source)
# javascript_include_tag "http://www.example.com/xmlhr.js"
# # => <script src="http://www.example.com/xmlhr.js"></script>
#
- # javascript_include_tag :defaults
- # # => <script src="/javascripts/jquery.js?1284139606"></script>
- # # <script src="/javascripts/rails.js?1284139606"></script>
- # # <script src="/javascripts/application.js?1284139606"></script>
- #
- # Note: The application.js file is only referenced if it exists
- #
- # You can also include all JavaScripts in the +javascripts+ directory using <tt>:all</tt> as the source:
- #
- # javascript_include_tag :all
- # # => <script src="/javascripts/jquery.js?1284139606"></script>
- # # <script src="/javascripts/rails.js?1284139606"></script>
- # # <script src="/javascripts/shop.js?1284139606"></script>
- # # <script src="/javascripts/checkout.js?1284139606"></script>
- # # <script src="/javascripts/application.js?1284139606"></script>
- #
- # Note that your defaults of choice will be included first, so they will be available to all subsequently
- # included files.
- #
- # If you want Rails to search in all the subdirectories under <tt>public/javascripts</tt>, you should
- # explicitly set <tt>:recursive</tt>:
- #
- # javascript_include_tag :all, :recursive => true
- #
- # == 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
- # <tt>config.perform_caching</tt> is set to true (which is the case by default for the Rails
- # production environment, but not for the development environment).
- #
- # # assuming config.perform_caching is false
- # javascript_include_tag :all, :cache => true
- # # => <script src="/javascripts/jquery.js?1284139606"></script>
- # # <script src="/javascripts/rails.js?1284139606"></script>
- # # <script src="/javascripts/shop.js?1284139606"></script>
- # # <script src="/javascripts/checkout.js?1284139606"></script>
- # # <script src="/javascripts/application.js?1284139606"></script>
- #
- # # assuming config.perform_caching is true
- # javascript_include_tag :all, :cache => true
- # # => <script src="/javascripts/all.js?1344139789"></script>
- #
- # # assuming config.perform_caching is false
- # javascript_include_tag "jquery", "cart", "checkout", :cache => "shop"
- # # => <script src="/javascripts/jquery.js?1284139606"></script>
- # # <script src="/javascripts/cart.js?1289139157"></script>
- # # <script src="/javascripts/checkout.js?1299139816"></script>
- #
- # # assuming config.perform_caching is true
- # javascript_include_tag "jquery", "cart", "checkout", :cache => "shop"
- # # => <script src="/javascripts/shop.js?1299139816"></script>
- #
- # The <tt>:recursive</tt> option is also available for caching:
- #
- # javascript_include_tag :all, :cache => true, :recursive => true
def javascript_include_tag(*sources)
- @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths)
- @javascript_include.include_tag(*sources)
+ options = sources.extract_options!.stringify_keys
+ sources.dup.map { |source|
+ tag_options = {
+ "src" => path_to_javascript(source)
+ }.merge(options)
+ content_tag(:script, "", tag_options)
+ }.join("\n").html_safe
end
end
end
Oops, something went wrong.

0 comments on commit affd05d

Please sign in to comment.