diff options
Diffstat (limited to 'actionpack/lib')
29 files changed, 205 insertions, 284 deletions
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index eba5e9377b..f13fd71050 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -37,12 +37,13 @@ module ActionController autoload :UrlFor end - autoload :Integration, 'action_controller/deprecated/integration_test' - autoload :IntegrationTest, 'action_controller/deprecated/integration_test' - autoload :PerformanceTest, 'action_controller/deprecated/performance_test' - autoload :UrlWriter, 'action_controller/deprecated' - autoload :Routing, 'action_controller/deprecated' - autoload :TestCase, 'action_controller/test_case' + autoload :Integration, 'action_controller/deprecated/integration_test' + autoload :IntegrationTest, 'action_controller/deprecated/integration_test' + autoload :PerformanceTest, 'action_controller/deprecated/performance_test' + autoload :UrlWriter, 'action_controller/deprecated' + autoload :Routing, 'action_controller/deprecated' + autoload :TestCase, 'action_controller/test_case' + autoload :TemplateAssertions, 'action_controller/test_case' eager_autoload do autoload :RecordIdentifier diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 93241fc056..5500f88930 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -37,11 +37,11 @@ module ActionController # {"name" => "Konata", "user" => {"name" => "Konata"}} # # You can also specify the key in which the parameters should be wrapped to, - # and also the list of attributes it should wrap by using either +:only+ or - # +:except+ options like this: + # and also the list of attributes it should wrap by using either +:include+ or + # +:exclude+ options like this: # # class UsersController < ApplicationController - # wrap_parameters :person, :only => [:username, :password] + # wrap_parameters :person, :include => [:username, :password] # end # # If you're going to pass the parameters to an +ActiveModel+ object (such as @@ -53,7 +53,7 @@ module ActionController # wrap_parameters Person # end # - # You still could pass +:only+ and +:except+ to set the list of attributes + # You still could pass +:include+ and +:exclude+ to set the list of attributes # you want to wrap. # # By default, if you don't specify the key in which the parameters would be @@ -73,7 +73,7 @@ module ActionController included do class_attribute :_wrapper_options - self._wrapper_options = {:format => []} + self._wrapper_options = { :format => [] } end module ClassMethods @@ -91,7 +91,7 @@ module ActionController # # wraps parameters by determine the wrapper key from Person class # (+person+, in this case) and the list of attribute names # - # wrap_parameters :only => [:username, :title] + # wrap_parameters :include => [:username, :title] # # wraps only +:username+ and +:title+ attributes from parameters. # # wrap_parameters false @@ -100,9 +100,9 @@ module ActionController # ==== Options # * <tt>:format</tt> - The list of formats in which the parameters wrapper # will be enabled. - # * <tt>:only</tt> - The list of attribute names which parameters wrapper + # * <tt>:include</tt> - The list of attribute names which parameters wrapper # will wrap into a nested hash. - # * <tt>:except</tt> - The list of attribute names which parameters wrapper + # * <tt>:exclude</tt> - The list of attribute names which parameters wrapper # will exclude from a nested hash. def wrap_parameters(name_or_model_or_options, options = {}) model = nil @@ -164,10 +164,10 @@ module ActionController def _set_wrapper_defaults(options, model=nil) options = options.dup - unless options[:only] || options[:except] + unless options[:include] || options[:exclude] model ||= _default_wrap_model if model.respond_to?(:attribute_names) && model.attribute_names.present? - options[:only] = model.attribute_names + options[:include] = model.attribute_names end end @@ -177,9 +177,9 @@ module ActionController controller_name.singularize end - options[:only] = Array.wrap(options[:only]).collect(&:to_s) if options[:only] - options[:except] = Array.wrap(options[:except]).collect(&:to_s) if options[:except] - options[:format] = Array.wrap(options[:format]) + options[:include] = Array.wrap(options[:include]).collect(&:to_s) if options[:include] + options[:exclude] = Array.wrap(options[:exclude]).collect(&:to_s) if options[:exclude] + options[:format] = Array.wrap(options[:format]) self._wrapper_options = options end @@ -216,11 +216,11 @@ module ActionController # Returns the list of parameters which will be selected for wrapped. def _wrap_parameters(parameters) - value = if only = _wrapper_options[:only] - parameters.slice(*only) + value = if include_only = _wrapper_options[:include] + parameters.slice(*include_only) else - except = _wrapper_options[:except] || [] - parameters.except(*(except + EXCLUDE_PARAMETERS)) + exclude = _wrapper_options[:exclude] || [] + parameters.except(*(exclude + EXCLUDE_PARAMETERS)) end { _wrapper_key => value } diff --git a/actionpack/lib/action_controller/metal/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb index b1d1b5cca6..2080e9b5b9 100644 --- a/actionpack/lib/action_controller/metal/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb @@ -96,7 +96,7 @@ module ActionController #:nodoc: # Sets the token value for the current session. def form_authenticity_token - session[:_csrf_token] ||= ActiveSupport::SecureRandom.base64(32) + session[:_csrf_token] ||= SecureRandom.base64(32) end # The form's authenticity parameter. Override to provide your own. diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 89ff5ba174..2ca9bae073 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -130,7 +130,7 @@ module ActionController super self.session = TestSession.new - self.session_options = TestSession::DEFAULT_OPTIONS.merge(:id => ActiveSupport::SecureRandom.hex(16)) + self.session_options = TestSession::DEFAULT_OPTIONS.merge(:id => SecureRandom.hex(16)) end class Result < ::Array #:nodoc: diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 499a272f6e..b22d426c1f 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -2,7 +2,6 @@ require 'tempfile' require 'stringio' require 'strscan' -require 'active_support/core_ext/module/deprecation' require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/string/access' require 'active_support/inflector' @@ -26,7 +25,7 @@ module ActionDispatch HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM HTTP_NEGOTIATE HTTP_PRAGMA ].freeze - + ENV_METHODS.each do |env| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{env.sub(/^HTTP_/n, '').downcase} @@ -134,11 +133,6 @@ module ActionDispatch @fullpath ||= super end - def forgery_whitelisted? - get? - end - deprecate :forgery_whitelisted? => "it is just an alias for 'get?' now, update your code" - def media_type content_mime_type.to_s end diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 3a6b1da4fd..f1e85559a3 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -33,7 +33,8 @@ module ActionDispatch # :nodoc: # end # end class Response - attr_accessor :request, :header, :status + attr_accessor :request, :header + attr_reader :status attr_writer :sending_file alias_method :headers=, :header= @@ -115,32 +116,9 @@ module ActionDispatch # :nodoc: EMPTY = " " - class BodyBuster #:nodoc: - def initialize(response) - @response = response - @body = "" - end - - def bust(body) - body.call(@response, self) - body.close if body.respond_to?(:close) - @body - end - - def write(string) - @body << string.to_s - end - end - def body=(body) @blank = true if body == EMPTY - if body.respond_to?(:call) - ActiveSupport::Deprecation.warn "Setting a Proc or an object that responds to call " \ - "in response_body is no longer supported", caller - body = BodyBuster.new(self).bust(body) - end - # Explicitly check for strings. This is *wrong* theoretically # but if we don't check this, the performance on string bodies # is bad on Ruby 1.8 (because strings responds to each then). diff --git a/actionpack/lib/action_dispatch/middleware/callbacks.rb b/actionpack/lib/action_dispatch/middleware/callbacks.rb index 1bb2ad7f67..8c0f4052ec 100644 --- a/actionpack/lib/action_dispatch/middleware/callbacks.rb +++ b/actionpack/lib/action_dispatch/middleware/callbacks.rb @@ -19,8 +19,7 @@ module ActionDispatch set_callback(:call, :after, *args, &block) end - def initialize(app, unused = nil) - ActiveSupport::Deprecation.warn "Passing a second argument to ActionDispatch::Callbacks.new is deprecated." unless unused.nil? + def initialize(app) @app = app end diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index d04780a230..47c4bad489 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -167,8 +167,8 @@ module ActionDispatch handle_options(options) - @set_cookies[key] = options - @delete_cookies.delete(key) + @set_cookies[key.to_s] = options + @delete_cookies.delete(key.to_s) value end @@ -181,7 +181,7 @@ module ActionDispatch handle_options(options) value = @cookies.delete(key.to_s) - @delete_cookies[key] = options + @delete_cookies[key.to_s] = options value end @@ -305,7 +305,7 @@ module ActionDispatch if secret.length < SECRET_MIN_LENGTH raise ArgumentError, "Secret should be something secure, " + - "like \"#{ActiveSupport::SecureRandom.hex(16)}\". The value you " + + "like \"#{SecureRandom.hex(16)}\". The value you " + "provided, \"#{secret}\", is shorter than the minimum length " + "of #{SECRET_MIN_LENGTH} characters" end diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 1a811ce1b1..a70d814749 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -29,7 +29,7 @@ module ActionDispatch end def generate_sid - sid = ActiveSupport::SecureRandom.hex(16) + sid = SecureRandom.hex(16) sid.encode!('UTF-8') if sid.respond_to?(:encode!) sid end @@ -73,13 +73,7 @@ module ActionDispatch include StaleSessionCheck def destroy_session(env, sid, options) - ActiveSupport::Deprecation.warn "Implementing #destroy in session stores is deprecated. " << - "Please implement destroy_session(env, session_id, options) instead." - destroy(env) - end - - def destroy(env) - raise '#destroy needs to be implemented.' + raise '#destroy_session needs to be implemented.' end end end diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 3fac9a0d0e..3999bd0a5e 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -910,7 +910,7 @@ module ActionDispatch alias :member_name :singular - # Checks for uncountable plurals, and appends "_index" if the plural + # Checks for uncountable plurals, and appends "_index" if the plural # and singular form are the same. def collection_name singular == plural ? "#{plural}_index" : plural @@ -1083,9 +1083,13 @@ module ActionDispatch # Is the same as: # # resources :posts do - # resources :comments + # resources :comments, :except => [:show, :edit, :update, :destroy] # end - # resources :comments + # resources :comments, :only => [:show, :edit, :update, :destroy] + # + # This allows URLs for resources that otherwise would be deeply nested such + # as a comment on a blog post like <tt>/posts/a-long-permalink/comments/1234</tt> + # to be shortened to just <tt>/comments/1234</tt>. # # [:shallow_path] # Prefixes nested shallow routes with the specified path. diff --git a/actionpack/lib/action_dispatch/routing/route.rb b/actionpack/lib/action_dispatch/routing/route.rb index a049510182..10b3d38346 100644 --- a/actionpack/lib/action_dispatch/routing/route.rb +++ b/actionpack/lib/action_dispatch/routing/route.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/module/deprecation' - module ActionDispatch module Routing class Route #:nodoc: @@ -47,11 +45,6 @@ module ActionDispatch @segment_keys ||= conditions[:path_info].names.compact.map { |key| key.to_sym } end - def to_a - [@app, @conditions, @defaults, @name] - end - deprecate :to_a - def to_s @to_s ||= begin "%-6s %-40s %s" % [(verb || :any).to_s.upcase, path, requirements.inspect] diff --git a/actionpack/lib/action_dispatch/testing/assertions.rb b/actionpack/lib/action_dispatch/testing/assertions.rb index 822150b768..226baf9ad0 100644 --- a/actionpack/lib/action_dispatch/testing/assertions.rb +++ b/actionpack/lib/action_dispatch/testing/assertions.rb @@ -8,12 +8,11 @@ module ActionDispatch extend ActiveSupport::Concern - included do - include DomAssertions - include ResponseAssertions - include RoutingAssertions - include SelectorAssertions - include TagAssertions - end + include DomAssertions + include ResponseAssertions + include RoutingAssertions + include SelectorAssertions + include TagAssertions end end + diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 3335742d47..606b01893e 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -6,13 +6,6 @@ module ActionDispatch module ResponseAssertions extend ActiveSupport::Concern - included do - # TODO: Need to pull in AV::Template monkey patches that track which - # templates are rendered. assert_template should probably be part - # of AV instead of AD. - require 'action_view/test_case' - end - # Asserts that the response is one of the following types: # # * <tt>:success</tt> - Status code was 200 diff --git a/actionpack/lib/action_pack/version.rb b/actionpack/lib/action_pack/version.rb index 584e5c3791..fcf0eb9565 100644 --- a/actionpack/lib/action_pack/version.rb +++ b/actionpack/lib/action_pack/version.rb @@ -3,7 +3,7 @@ module ActionPack MAJOR = 3 MINOR = 1 TINY = 0 - PRE = "beta1" + PRE = "rc1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb index 78a68db282..262e0f1010 100644 --- a/actionpack/lib/action_view/helpers.rb +++ b/actionpack/lib/action_view/helpers.rb @@ -22,7 +22,6 @@ module ActionView #:nodoc: autoload :RecordTagHelper autoload :RenderingHelper autoload :SanitizeHelper - autoload :SprocketsHelper autoload :TagHelper autoload :TextHelper autoload :TranslationHelper @@ -53,7 +52,6 @@ module ActionView #:nodoc: include RecordTagHelper include RenderingHelper include SanitizeHelper - include SprocketsHelper include TagHelper include TextHelper include TranslationHelper diff --git a/actionpack/lib/action_view/helpers/asset_paths.rb b/actionpack/lib/action_view/helpers/asset_paths.rb index 958f0e0a10..1bc5c9e003 100644 --- a/actionpack/lib/action_view/helpers/asset_paths.rb +++ b/actionpack/lib/action_view/helpers/asset_paths.rb @@ -1,5 +1,4 @@ require 'active_support/core_ext/file' -require 'action_view/helpers/asset_paths' module ActionView module Helpers @@ -56,11 +55,11 @@ module ActionView # 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. + # or the value returned from invoking call on an object responding to call + # (proc or otherwise). def compute_asset_host(source) if host = config.asset_host - if host.is_a?(Proc) || host.respond_to?(:call) + if host.respond_to?(:call) case host.is_a?(Proc) ? host.arity : host.method(:call).arity when 2 request = controller.respond_to?(:request) && controller.request diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 9bc847a1ab..7970176d37 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -274,11 +274,7 @@ module ActionView # The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and # plugin authors are encouraged to do so. def image_path(source) - if config.use_sprockets - asset_path(source) - else - asset_paths.compute_public_path(source, 'images') - end + asset_paths.compute_public_path(source, 'images') end alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route @@ -293,11 +289,7 @@ module ActionView # video_path("/trailers/hd.avi") # => /trailers/hd.avi # video_path("http://www.example.com/vid/hd.avi") # => http://www.example.com/vid/hd.avi def video_path(source) - if config.use_sprockets - asset_path(source) - else - asset_paths.compute_public_path(source, 'videos') - end + asset_paths.compute_public_path(source, 'videos') end alias_method :path_to_video, :video_path # aliased to avoid conflicts with a video_path named route @@ -312,11 +304,7 @@ module ActionView # audio_path("/sounds/horse.wav") # => /sounds/horse.wav # audio_path("http://www.example.com/sounds/horse.wav") # => http://www.example.com/sounds/horse.wav def audio_path(source) - if config.use_sprockets - asset_path(source) - else - asset_paths.compute_public_path(source, 'audios') - end + asset_paths.compute_public_path(source, 'audios') end alias_method :path_to_audio, :audio_path # aliased to avoid conflicts with an audio_path named route 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 e1ee0d0e1a..0f8a63901e 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 @@ -187,12 +187,8 @@ module ActionView # # javascript_include_tag :all, :cache => true, :recursive => true def javascript_include_tag(*sources) - if config.use_sprockets - sprockets_javascript_include_tag(*sources) - else - @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths) - @javascript_include.include_tag(*sources) - end + @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths) + @javascript_include.include_tag(*sources) end end end diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb index a95eb221be..e4f11c9bc7 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb @@ -137,12 +137,8 @@ module ActionView # stylesheet_link_tag :all, :concat => true # def stylesheet_link_tag(*sources) - if config.use_sprockets - sprockets_stylesheet_link_tag(*sources) - else - @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths) - @stylesheet_include.include_tag(*sources) - end + @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths) + @stylesheet_include.include_tag(*sources) end end diff --git a/actionpack/lib/action_view/helpers/atom_feed_helper.rb b/actionpack/lib/action_view/helpers/atom_feed_helper.rb index 889ea8a763..a087688a2c 100644 --- a/actionpack/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionpack/lib/action_view/helpers/atom_feed_helper.rb @@ -34,7 +34,7 @@ module ActionView # feed.title("My great blog!") # feed.updated(@posts.first.created_at) # - # for post in @posts + # @posts.each do |post| # feed.entry(post) do |entry| # entry.title(post.title) # entry.content(post.body, :type => 'html') @@ -66,7 +66,7 @@ module ActionView # feed.updated((@posts.first.created_at)) # feed.tag!(openSearch:totalResults, 10) # - # for post in @posts + # @posts.each do |post| # feed.entry(post) do |entry| # entry.title(post.title) # entry.content(post.body, :type => 'html') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 07e2c8d341..cb1c13912a 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -555,6 +555,19 @@ module ActionView # ... # <% end %> # + # In addition, you may want to have access to the current iteration index. + # In that case, you can use a similar method called fields_for_with_index + # which receives a block with an extra parameter: + # + # <%= form_for @person do |person_form| %> + # ... + # <%= person_form.fields_for_with_index :projects do |project_fields, index| %> + # Position: <%= index %> + # Name: <%= project_fields.text_field :name %> + # <% end %> + # ... + # <% end %> + # # When projects is already an association on Person you can use # +accepts_nested_attributes_for+ to define the writer method for you: # @@ -1216,6 +1229,13 @@ module ActionView RUBY_EVAL end + # Check +fields_for+ for docs and examples. + def fields_for_with_index(record_name, record_object = nil, fields_options = {}, &block) + index = fields_options[:index] || options[:child_index] || nested_child_index(@object_name) + block_with_index = Proc.new{ |obj| block.call(obj, index) } + fields_for(record_name, record_object, fields_options, &block_with_index) + end + def fields_for(record_name, record_object = nil, fields_options = {}, &block) fields_options, record_object = record_object, nil if record_object.is_a?(Hash) fields_options[:builder] ||= options[:builder] diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb deleted file mode 100644 index ab98da9624..0000000000 --- a/actionpack/lib/action_view/helpers/sprockets_helper.rb +++ /dev/null @@ -1,69 +0,0 @@ -require 'uri' -require 'action_view/helpers/asset_paths' - -module ActionView - module Helpers - module SprocketsHelper - def asset_path(source, default_ext = nil) - sprockets_asset_paths.compute_public_path(source, 'assets', default_ext, true) - end - - def sprockets_javascript_include_tag(source, options = {}) - options = { - 'type' => "text/javascript", - 'src' => asset_path(source, 'js') - }.merge(options.stringify_keys) - - content_tag 'script', "", options - end - - def sprockets_stylesheet_link_tag(source, options = {}) - options = { - 'rel' => "stylesheet", - 'type' => "text/css", - 'media' => "screen", - 'href' => asset_path(source, 'css') - }.merge(options.stringify_keys) - - tag 'link', options - end - - private - - def sprockets_asset_paths - @sprockets_asset_paths ||= begin - config = self.config if respond_to?(:config) - controller = self.controller if respond_to?(:controller) - SprocketsHelper::AssetPaths.new(config, controller) - end - end - - class AssetPaths < ActionView::Helpers::AssetPaths #:nodoc: - def rewrite_asset_path(source, dir) - if source[0] == ?/ - source - else - assets.path(source, performing_caching?, dir) - end - end - - def rewrite_extension(source, dir, ext) - if ext && File.extname(source).empty? - "#{source}.#{ext}" - else - source - end - end - - def assets - Rails.application.assets - end - - # When included in Sprockets::Context, we need to ask the top-level config as the controller is not available - def performing_caching? - @config ? @config.perform_caching : Rails.application.config.action_controller.perform_caching - end - end - end - end -end
\ No newline at end of file diff --git a/actionpack/lib/action_view/template/handler.rb b/actionpack/lib/action_view/template/handler.rb deleted file mode 100644 index 636f3ebbad..0000000000 --- a/actionpack/lib/action_view/template/handler.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'action_dispatch/http/mime_type' -require 'active_support/core_ext/class/attribute' - -# Legacy TemplateHandler stub -module ActionView - class Template - module Handlers #:nodoc: - module Compilable - def self.included(base) - ActiveSupport::Deprecation.warn "Including Compilable in your template handler is deprecated. " << - "Since Rails 3, all the API your template handler needs to implement is to respond to #call." - base.extend(ClassMethods) - end - - module ClassMethods - def call(template) - new.compile(template) - end - end - - def compile(template) - raise "Need to implement #{self.class.name}#compile(template)" - end - end - end - - class Template::Handler - class_attribute :default_format - self.default_format = Mime::HTML - - def self.inherited(base) - ActiveSupport::Deprecation.warn "Inheriting from ActionView::Template::Handler is deprecated. " << - "Since Rails 3, all the API your template handler needs to implement is to respond to #call." - super - end - - def self.call(template) - raise "Need to implement #{self.class.name}#call(template)" - end - - def render(template, local_assigns) - raise "Need to implement #{self.class.name}#render(template, local_assigns)" - end - end - end - - TemplateHandlers = Template::Handlers - TemplateHandler = Template::Handler -end diff --git a/actionpack/lib/action_view/template/handlers.rb b/actionpack/lib/action_view/template/handlers.rb index 959afa734e..aa693335e3 100644 --- a/actionpack/lib/action_view/template/handlers.rb +++ b/actionpack/lib/action_view/template/handlers.rb @@ -41,12 +41,6 @@ module ActionView #:nodoc: @@default_template_handlers = klass end - def handler_class_for_extension(extension) - ActiveSupport::Deprecation.warn "handler_class_for_extension is deprecated. " << - "Please use handler_for_extension instead", caller - handler_for_extension(extension) - end - def handler_for_extension(extension) registered_template_handler(extension) || @@default_template_handlers end diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index 7e9e4e518a..77720e2bc8 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -1,6 +1,5 @@ +require 'action_dispatch/http/mime_type' require 'active_support/core_ext/class/attribute_accessors' -require 'action_view/template' -require 'action_view/template/handler' require 'erubis' module ActionView diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index d0317a148b..2cc85a9f69 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -218,12 +218,6 @@ module ActionView end] end - def _assigns - ActiveSupport::Deprecation.warn "ActionView::TestCase#_assigns is deprecated and will be removed in future versions. " << - "Please use view_assigns instead." - view_assigns - end - def _routes @controller._routes if @controller.respond_to?(:_routes) end diff --git a/actionpack/lib/sprockets/helpers.rb b/actionpack/lib/sprockets/helpers.rb new file mode 100644 index 0000000000..a952a55c5e --- /dev/null +++ b/actionpack/lib/sprockets/helpers.rb @@ -0,0 +1,5 @@ +module Sprockets + module Helpers + autoload :RailsHelper, "sprockets/helpers/rails_helper" + end +end diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb new file mode 100644 index 0000000000..a99dcad81d --- /dev/null +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -0,0 +1,107 @@ +require "action_view/helpers/asset_paths" +require "action_view/helpers/asset_tag_helper" + +module Sprockets + module Helpers + module RailsHelper + extend ActiveSupport::Concern + include ActionView::Helpers::AssetTagHelper + + def asset_paths + @asset_paths ||= begin + config = self.config if respond_to?(:config) + controller = self.controller if respond_to?(:controller) + RailsHelper::AssetPaths.new(config, controller) + end + end + + def javascript_include_tag(source, options = {}) + debug = options.key?(:debug) ? options.delete(:debug) : debug_assets? + body = options.key?(:body) ? options.delete(:body) : false + + if debug && asset = asset_paths.asset_for(source, 'js') + asset.to_a.map { |dep| + javascript_include_tag(dep, :debug => false, :body => true) + }.join("\n").html_safe + else + options = { + 'type' => "text/javascript", + 'src' => asset_path(source, 'js', body) + }.merge(options.stringify_keys) + + content_tag 'script', "", options + end + end + + def stylesheet_link_tag(source, options = {}) + debug = options.key?(:debug) ? options.delete(:debug) : debug_assets? + body = options.key?(:body) ? options.delete(:body) : false + + if debug && asset = asset_paths.asset_for(source, 'css') + asset.to_a.map { |dep| + stylesheet_link_tag(dep, :debug => false, :body => true) + }.join("\n").html_safe + else + options = { + 'rel' => "stylesheet", + 'type' => "text/css", + 'media' => "screen", + 'href' => asset_path(source, 'css', body) + }.merge(options.stringify_keys) + + tag 'link', options + end + end + + private + def debug_assets? + params[:debug_assets] == '1' || + params[:debug_assets] == 'true' + end + + def asset_path(source, default_ext = nil, body = false) + source = source.logical_path if source.respond_to?(:logical_path) + path = asset_paths.compute_public_path(source, 'assets', default_ext, true) + body ? "#{path}?body=1" : path + end + + class AssetPaths < ActionView::Helpers::AssetPaths #:nodoc: + def compute_public_path(source, dir, ext=nil, include_host=true) + super(source, 'assets', ext, include_host) + end + + def asset_for(source, ext) + source = source.to_s + return nil if is_uri?(source) + source = rewrite_extension(source, nil, ext) + assets[source] + end + + def rewrite_asset_path(source, dir) + if source[0] == ?/ + source + else + assets.path(source, performing_caching?, dir) + end + end + + def rewrite_extension(source, dir, ext) + if ext && File.extname(source).empty? + "#{source}.#{ext}" + else + source + end + end + + def assets + Rails.application.assets + end + + # When included in Sprockets::Context, we need to ask the top-level config as the controller is not available + def performing_caching? + @config ? @config.perform_caching : Rails.application.config.action_controller.perform_caching + end + end + end + end +end diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index 8cee3babe2..7b8a7ad3bb 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -1,5 +1,7 @@ module Sprockets - class Railtie < Rails::Railtie + autoload :Helpers, "sprockets/helpers" + + class Railtie < ::Rails::Railtie def self.using_coffee? require 'coffee-script' defined?(CoffeeScript) @@ -7,15 +9,7 @@ module Sprockets false end - def self.using_scss? - require 'sass' - defined?(Sass) - rescue LoadError - false - end - config.app_generators.javascript_engine :coffee if using_coffee? - config.app_generators.stylesheet_engine :scss if using_scss? # Configure ActionController to use sprockets. initializer "sprockets.set_configs", :after => "action_controller.set_configs" do |app| @@ -26,7 +20,8 @@ module Sprockets # We need to configure this after initialization to ensure we collect # paths from all engines. This hook is invoked exactly before routes - # are compiled. + # 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 @@ -34,8 +29,10 @@ module Sprockets app.assets = asset_environment(app) ActiveSupport.on_load(:action_view) do + include ::Sprockets::Helpers::RailsHelper + app.assets.context_class.instance_eval do - include ::ActionView::Helpers::SprocketsHelper + include ::Sprockets::Helpers::RailsHelper end end @@ -57,8 +54,8 @@ module Sprockets env.static_root = File.join(app.root.join("public"), assets.prefix) env.paths.concat assets.paths env.logger = Rails.logger - env.js_compressor = expand_js_compressor(assets.js_compressor) - env.css_compressor = expand_css_compressor(assets.css_compressor) + env.js_compressor = expand_js_compressor(assets.js_compressor) if assets.compress + env.css_compressor = expand_css_compressor(assets.css_compressor) if assets.compress env end @@ -80,15 +77,6 @@ module Sprockets def expand_css_compressor(sym) case sym - when :scss - require 'sass' - compressor = Object.new - def compressor.compress(source) - Sass::Engine.new(source, - :syntax => :scss, :style => :compressed - ).render - end - compressor when :yui require 'yui/compressor' YUI::CssCompressor.new |