aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/abstract_controller/asset_paths.rb2
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb22
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/response.rb10
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb6
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/form_options_helper.rb4
-rw-r--r--actionpack/lib/sprockets/railtie.rb81
7 files changed, 50 insertions, 77 deletions
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/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 1331f67a78..53374949ae 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
@@ -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
@@ -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
@@ -222,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
@@ -262,7 +256,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
diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb
index a2d639cd56..7381617dd7 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/response.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb
@@ -55,16 +55,14 @@ 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
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
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index c835aa6f15..7ea2ea2d5a 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)
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)
%(<option value="#{ERB::Util.html_escape(value)}"#{selected_attribute}#{disabled_attribute}#{html_attributes}>#{ERB::Util.html_escape(text)}</option>)
diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb
index c8d6af942d..c8438e6043 100644
--- a/actionpack/lib/sprockets/railtie.rb
+++ b/actionpack/lib/sprockets/railtie.rb
@@ -11,10 +11,27 @@ 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
+ initializer "sprockets.environment" do |app|
+ config = app.config
+ next unless config.assets.enabled
+
+ 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
+
+ app.assets.context_class.instance_eval do
+ include ::Sprockets::Helpers::RailsHelper
+ end
end
end
@@ -23,21 +40,25 @@ module Sprockets
# 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
+ next unless app.assets
+ config = app.config
- app.assets = asset_environment(app)
+ config.assets.paths.each { |path| app.assets.append_path(path) }
- ActiveSupport.on_load(:action_view) do
- include ::Sprockets::Helpers::RailsHelper
+ 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
- app.assets.context_class.instance_eval do
- include ::Sprockets::Helpers::RailsHelper
+ unless config.assets.css_compressor == false
+ app.assets.css_compressor = LazyCompressor.new { expand_css_compressor(config.assets.css_compressor) }
end
end
app.routes.prepend do
- mount app.assets => assets.prefix
+ mount app.assets => config.assets.prefix
end
if config.action_controller.perform_caching
@@ -46,42 +67,6 @@ module Sprockets
end
protected
- def asset_environment(app)
- require "sprockets"
-
- assets = app.config.assets
-
- env = Sprockets::Environment.new(app.root.to_s)
-
- env.static_root = File.join(app.root.join("public"), assets.prefix)
-
- if env.respond_to?(:append_path)
- assets.paths.each { |path| env.append_path(path) }
- else
- env.paths.concat assets.paths
- 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
- 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
-
- env
- end
-
def expand_js_compressor(sym)
case sym
when :closure