Permalink
Browse files

Merge branch 'actionview-decoupling'

This branch contains set of changes that will allow to extract Action
View out of Action Pack in the future. This work will be probably done
after Rails 4.0 release, because of a few deprecations that were done
to make decoupling possible.
  • Loading branch information...
drogus committed Aug 28, 2012
2 parents 1ec1eb2 + daa0ed3 commit 4f093d81aca814b7433c4a1366985327b4ad0708
Showing with 487 additions and 232 deletions.
  1. +14 −0 actionpack/CHANGELOG.md
  2. +6 −1 actionpack/lib/action_controller.rb
  3. +1 −1 actionpack/lib/action_controller/base.rb
  4. +13 −0 actionpack/lib/action_controller/metal/asset_paths.rb
  5. +10 −73 actionpack/lib/action_controller/record_identifier.rb
  6. +4 −19 actionpack/lib/action_controller/vendor/html-scanner.rb
  7. +5 −0 actionpack/lib/action_dispatch.rb
  8. +2 −0 actionpack/lib/action_dispatch/routing/url_for.rb
  9. +1 −1 actionpack/lib/action_dispatch/testing/assertions/dom.rb
  10. +2 −1 actionpack/lib/action_dispatch/testing/assertions/selector.rb
  11. +1 −1 actionpack/lib/action_dispatch/testing/assertions/tag.rb
  12. +2 −0 actionpack/lib/action_view.rb
  13. +3 −5 actionpack/lib/action_view/asset_paths.rb
  14. +3 −2 actionpack/lib/action_view/base.rb
  15. +8 −0 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  16. +3 −3 actionpack/lib/action_view/helpers/form_helper.rb
  17. +1 −3 actionpack/lib/action_view/helpers/record_tag_helper.rb
  18. +1 −1 actionpack/lib/action_view/helpers/sanitize_helper.rb
  19. +16 −98 actionpack/lib/action_view/helpers/url_helper.rb
  20. +1 −1 actionpack/lib/action_view/lookup_context.rb
  21. +12 −0 actionpack/lib/action_view/model_naming.rb
  22. +84 −0 actionpack/lib/action_view/record_identifier.rb
  23. +1 −1 actionpack/lib/action_view/renderer/streaming_template_renderer.rb
  24. +107 −0 actionpack/lib/action_view/routing_url_for.rb
  25. +8 −1 actionpack/lib/action_view/template.rb
  26. +1 −1 actionpack/lib/action_view/template/handlers/builder.rb
  27. +1 −1 actionpack/lib/action_view/template/resolver.rb
  28. +6 −6 actionpack/lib/action_view/template/text.rb
  29. +58 −0 actionpack/lib/action_view/template/types.rb
  30. +2 −1 actionpack/lib/action_view/test_case.rb
  31. +20 −0 actionpack/lib/action_view/vendor/html-scanner.rb
  32. 0 actionpack/lib/{action_controller → action_view}/vendor/html-scanner/html/document.rb
  33. 0 actionpack/lib/{action_controller → action_view}/vendor/html-scanner/html/node.rb
  34. 0 actionpack/lib/{action_controller → action_view}/vendor/html-scanner/html/sanitizer.rb
  35. 0 actionpack/lib/{action_controller → action_view}/vendor/html-scanner/html/selector.rb
  36. 0 actionpack/lib/{action_controller → action_view}/vendor/html-scanner/html/tokenizer.rb
  37. 0 actionpack/lib/{action_controller → action_view}/vendor/html-scanner/html/version.rb
  38. +1 −1 actionpack/test/controller/action_pack_assertions_test.rb
  39. +41 −0 actionpack/test/controller/base_test.rb
  40. +1 −1 actionpack/test/controller/integration_test.rb
  41. +1 −1 actionpack/test/controller/new_base/render_streaming_test.rb
  42. +1 −1 actionpack/test/controller/selector_test.rb
  43. +10 −1 actionpack/test/template/asset_tag_helper_test.rb
  44. +2 −1 actionpack/test/template/erb/helper.rb
  45. +4 −3 actionpack/test/template/log_subscriber_test.rb
  46. +11 −0 actionpack/test/template/lookup_context_test.rb
  47. +10 −1 actionpack/test/{controller → template}/record_identifier_test.rb
  48. +7 −0 actionpack/test/template/template_test.rb
  49. +1 −1 actionpack/test/template/url_helper_test.rb
View
@@ -1,5 +1,19 @@
## Rails 4.0.0 (unreleased) ##
+* Deprecate availbility of ActionView::RecordIdentifier in controllers by default.
+ It's view specific and can be easily included in controller manually if someone
+ really needs it. RecordIdentifier will be removed from ActionController::Base
+ in Rails 4.1 *Piotr Sarnacki*
+
+* Fix ActionView::RecordIdentifier to work as a singleton *Piotr Sarnacki*
+
+* Deprecate Template#mime_type, it will be removed in Rails 4.1 in favor of #type.
+ *Piotr Sarnacki*
+
+* Move vendored html-scanner from action_controller to action_view directory. If you
+ require it directly, please use 'action_view/vendor/html-scanner', reference to
+ 'action_controller/vendor/html-scanner' will be removed in Rails 4.1 *Piot Sarnacki*
+
* Fix handling of date selects when using both disabled and discard options.
Fixes #7431.
@@ -12,6 +12,7 @@ module ActionController
autoload :Middleware
autoload_under "metal" do
+ autoload :AssetPaths
autoload :Compatibility
autoload :ConditionalGet
autoload :Cookies
@@ -58,7 +59,11 @@ def self.eager_load!
# All of these simply register additional autoloads
require 'action_view'
-require 'action_controller/vendor/html-scanner'
+require 'action_view/vendor/html-scanner'
+
+ActiveSupport.on_load(:action_view) do
+ ActionView::RoutingUrlFor.send(:include, ActionDispatch::Routing::UrlFor)
+end
# Common Active Support usage in Action Controller
require 'active_support/core_ext/class/attribute_accessors'
@@ -183,8 +183,8 @@ def self.without_modules(*modules)
MODULES = [
AbstractController::Layouts,
AbstractController::Translation,
- AbstractController::AssetPaths,
+ AssetPaths,
Helpers,
HideActions,
UrlFor,
@@ -0,0 +1,13 @@
+require 'action_controller/metal/exceptions'
+
+module ActionController
+ module AssetPaths
+ extend ActiveSupport::Concern
+
+ include AbstractController::AssetPaths
+
+ def invalid_asset_host!(help_message)
+ raise ActionController::RoutingError, "This asset host cannot be computed without a request in scope. #{help_message}"
+ end
+ end
+end
@@ -1,83 +1,20 @@
-require 'active_support/core_ext/module'
-require 'action_controller/model_naming'
+require 'active_support/deprecation'
+require 'action_view/record_identifier'
module ActionController
- # The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or
- # pretty much any other model type that has an id. These patterns are then used to try elevate the view actions to
- # a higher logical level.
- #
- # # routes
- # resources :posts
- #
- # # view
- # <%= div_for(post) do %> <div id="post_45" class="post">
- # <%= post.body %> What a wonderful world!
- # <% end %> </div>
- #
- # # controller
- # def update
- # post = Post.find(params[:id])
- # post.update_attributes(params[:post])
- #
- # redirect_to(post) # Calls polymorphic_url(post) which in turn calls post_url(post)
- # end
- #
- # As the example above shows, you can stop caring to a large extent what the actual id of the post is.
- # You just know that one is being assigned and that the subsequent calls in redirect_to expect that
- # same naming convention and allows you to write less code if you follow it.
module RecordIdentifier
- extend self
+ MESSAGE = 'method will no longer be included by default in controllers since Rails 4.1. ' +
+ 'If you would like to use it in controllers, please include ' +
+ 'ActionView::RecodIdentifier module.'
- include ModelNaming
-
- JOIN = '_'.freeze
- NEW = 'new'.freeze
-
- # The DOM class convention is to use the singular form of an object or class.
- #
- # dom_class(post) # => "post"
- # dom_class(Person) # => "person"
- #
- # If you need to address multiple instances of the same class in the same view, you can prefix the dom_class:
- #
- # dom_class(post, :edit) # => "edit_post"
- # dom_class(Person, :edit) # => "edit_person"
- def dom_class(record_or_class, prefix = nil)
- singular = model_name_from_record_or_class(record_or_class).param_key
- prefix ? "#{prefix}#{JOIN}#{singular}" : singular
- end
-
- # The DOM id convention is to use the singular form of an object or class with the id following an underscore.
- # If no id is found, prefix with "new_" instead.
- #
- # dom_id(Post.find(45)) # => "post_45"
- # dom_id(Post.new) # => "new_post"
- #
- # If you need to address multiple instances of the same class in the same view, you can prefix the dom_id:
- #
- # dom_id(Post.find(45), :edit) # => "edit_post_45"
- # dom_id(Post.new, :custom) # => "custom_post"
def dom_id(record, prefix = nil)
- if record_id = record_key_for_dom_id(record)
- "#{dom_class(record, prefix)}#{JOIN}#{record_id}"
- else
- dom_class(record, prefix || NEW)
- end
+ ActiveSupport::Deprecation.warn 'dom_id ' + MESSAGE
+ ActionView::RecordIdentifier.dom_id(record, prefix)
end
- protected
-
- # Returns a string representation of the key attribute(s) that is suitable for use in an HTML DOM id.
- # This can be overwritten to customize the default generated string representation if desired.
- # If you need to read back a key from a dom_id in order to query for the underlying database record,
- # you should write a helper like 'person_record_from_dom_id' that will extract the key either based
- # on the default implementation (which just joins all key attributes with '_') or on your own
- # overwritten version of the method. By default, this implementation passes the key string through a
- # method that replaces all characters that are invalid inside DOM ids, with valid ones. You need to
- # make sure yourself that your dom ids are valid, in case you overwrite this method.
- def record_key_for_dom_id(record)
- key = convert_to_model(record).to_key
- key ? key.join('_') : key
+ def dom_class(record, prefix = nil)
+ ActiveSupport::Deprecation.warn 'dom_class ' + MESSAGE
+ ActionView::RecordIdentifier.dom_class(record, prefix)
end
end
end
@@ -1,20 +1,5 @@
-$LOAD_PATH << "#{File.dirname(__FILE__)}/html-scanner"
+require 'action_view/vendor/html-scanner'
+require 'active_support/deprecation'
-module HTML
- extend ActiveSupport::Autoload
-
- eager_autoload do
- autoload :CDATA, 'html/node'
- autoload :Document, 'html/document'
- autoload :FullSanitizer, 'html/sanitizer'
- autoload :LinkSanitizer, 'html/sanitizer'
- autoload :Node, 'html/node'
- autoload :Sanitizer, 'html/sanitizer'
- autoload :Selector, 'html/selector'
- autoload :Tag, 'html/node'
- autoload :Text, 'html/node'
- autoload :Tokenizer, 'html/tokenizer'
- autoload :Version, 'html/version'
- autoload :WhiteListSanitizer, 'html/sanitizer'
- end
-end
+ActiveSupport::Deprecation.warn 'Vendored html-scanner was moved to action_view, please require "action_view/vendor/html-scanner" instead. ' +
+ 'This file will be removed in Rails 4.1'
@@ -101,3 +101,8 @@ module Session
end
autoload :Mime, 'action_dispatch/http/mime_type'
+
+ActiveSupport.on_load(:action_view) do
+ ActionView::Base.default_formats ||= Mime::SET.symbols
+ ActionView::Template::Types.delegate_to Mime
+end
@@ -95,6 +95,8 @@ module UrlFor
self.default_url_options = {}
end
+
+ include *_url_for_modules if respond_to?(:_url_for_modules)
end
def initialize(*)
@@ -1,4 +1,4 @@
-require 'action_controller/vendor/html-scanner'
+require 'action_view/vendor/html-scanner'
module ActionDispatch
module Assertions
@@ -1,4 +1,5 @@
-require 'action_controller/vendor/html-scanner'
+require 'action_view/vendor/html-scanner'
+require 'active_support/core_ext/object/inclusion'
#--
# Copyright (c) 2006 Assaf Arkin (http://labnotes.org)
@@ -1,4 +1,4 @@
-require 'action_controller/vendor/html-scanner'
+require 'action_view/vendor/html-scanner'
module ActionDispatch
module Assertions
@@ -36,6 +36,8 @@ module ActionView
autoload :Helpers
autoload :LookupContext
autoload :PathSet
+ autoload :RecordIdentifier
+ autoload :RoutingUrlFor
autoload :Template
autoload_under "renderer" do
@@ -1,13 +1,15 @@
require 'zlib'
require 'active_support/core_ext/file'
-require 'action_controller/metal/exceptions'
+require 'active_support/core_ext/module/delegation'
module ActionView
class AssetPaths #:nodoc:
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}
attr_reader :config, :controller
+ delegate :invalid_asset_host!, :to => :controller, :prefix => false
+
def initialize(config, controller = nil)
@config = config
@controller = controller
@@ -97,10 +99,6 @@ def default_protocol
@config.default_asset_host_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),
@@ -146,6 +146,9 @@ class Base
cattr_accessor :prefix_partial_path_with_controller_namespace
@@prefix_partial_path_with_controller_namespace = true
+ # Specify default_formats that can be rendered.
+ cattr_accessor :default_formats
+
class_attribute :_routes
class_attribute :logger
@@ -178,8 +181,6 @@ def assign(new_assigns) # :nodoc:
def initialize(context = nil, assigns = {}, controller = nil, formats = nil) #:nodoc:
@_config = ActiveSupport::InheritableOptions.new
- # Handle all these for backwards compatibility.
- # TODO Provide a new API for AV::Base and deprecate this one.
if context.is_a?(ActionView::Renderer)
@view_renderer = context
else
@@ -222,6 +222,14 @@ module AssetTagHelper
# auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {:title => "Example RSS"})
# # => <link rel="alternate" type="application/rss+xml" title="Example RSS" href="http://www.example.com/feed" />
def auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})
+ if !(type == :rss || type == :atom) && tag_options[:type].blank?
+ message = "You have passed type other than :rss or :atom to auto_discovery_link_tag and haven't supplied " +
+ "the :type option key. This behavior is deprecated and will be remove in Rails 4.1. You should pass " +
+ ":type option explicitly if you want to use other types, for example: " +
+ "auto_discovery_link_tag(:xml, '/feed.xml', :type => 'application/xml')"
+ ActiveSupport::Deprecation.warn message
+ end
+
tag(
"link",
"rel" => tag_options[:rel] || "alternate",
@@ -4,12 +4,12 @@
require 'action_view/helpers/form_tag_helper'
require 'action_view/helpers/active_model_helper'
require 'action_view/helpers/tags'
+require 'action_view/model_naming'
require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/string/output_safety'
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/string/inflections'
-require 'action_controller/model_naming'
module ActionView
# = Action View Form Helpers
@@ -115,7 +115,7 @@ module FormHelper
include FormTagHelper
include UrlHelper
- include ActionController::ModelNaming
+ include ModelNaming
# Creates a form that allows the user to create or update the attributes
# of a specific model object.
@@ -1156,7 +1156,7 @@ def default_form_builder
end
class FormBuilder
- include ActionController::ModelNaming
+ include ModelNaming
# The methods which wrap a form helper call.
class_attribute :field_helpers
@@ -1,10 +1,8 @@
-require 'action_controller/record_identifier'
-
module ActionView
# = Action View Record Tag Helpers
module Helpers
module RecordTagHelper
- include ActionController::RecordIdentifier
+ include ActionView::RecordIdentifier
# Produces a wrapper DIV element with id and class parameters that
# relate to the specified Active Record object. Usage example:
@@ -1,5 +1,5 @@
require 'active_support/core_ext/object/try'
-require 'action_controller/vendor/html-scanner'
+require 'action_view/vendor/html-scanner'
module ActionView
# = Action View Sanitize Helpers
Oops, something went wrong.

0 comments on commit 4f093d8

Please sign in to comment.