Permalink
Browse files

Revert "Merge pull request #13235 from strzalek/variants-inline" -- n…

…eeds a little more work!

This reverts commit 1861611, reversing
changes made to cad9eb1.
  • Loading branch information...
1 parent 1861611 commit 4aae538d9ffff3a00a81f3da52fa70f7fd79ac74 @dhh dhh committed Dec 8, 2013
@@ -215,7 +215,7 @@ def respond_to(*mimes, &block)
raise ArgumentError, "respond_to takes either types or a block, never both" if mimes.any? && block_given?
if collector = retrieve_collector_from_mimes(mimes, &block)
- response = collector.response
+ response = collector.response(request.variant)
response ? response.call : render({})
end
end
@@ -357,7 +357,7 @@ def respond_with(*resources, &block)
if collector = retrieve_collector_from_mimes(&block)
options = resources.size == 1 ? {} : resources.extract_options!
options = options.clone
- options[:default_response] = collector.response
+ options[:default_response] = collector.response(request.variant)
(options.delete(:responder) || self.class.responder).call(self, resources, options)
end
end
@@ -390,7 +390,7 @@ def collect_mimes_from_class_level #:nodoc:
# is available.
def retrieve_collector_from_mimes(mimes=nil, &block) #:nodoc:
mimes ||= collect_mimes_from_class_level
- collector = Collector.new(mimes, request.variant)
+ collector = Collector.new(mimes)
block.call(collector) if block_given?
format = collector.negotiate_format(request)
@@ -428,11 +428,9 @@ class Collector
include AbstractController::Collector
attr_accessor :format
- def initialize(mimes, variant = nil)
+ def initialize(mimes)
@responses = {}
- @variant = variant
-
- mimes.each { |mime| @responses["Mime::#{mime.upcase}".constantize] = nil }
+ mimes.each { |mime| send(mime) }
end
def any(*args, &block)
@@ -446,19 +444,15 @@ def any(*args, &block)
def custom(mime_type, &block)
mime_type = Mime::Type.lookup(mime_type.to_s) unless mime_type.is_a?(Mime::Type)
- @responses[mime_type] ||= if block_given?
- block
- else
- VariantFilter.new(@variant)
- end
+ @responses[mime_type] ||= block
end
- def response
+ def response(variant)
response = @responses.fetch(format, @responses[Mime::ALL])
- if response.is_a?(VariantFilter) || response.nil? || response.arity == 0
+ if response.nil? || response.arity == 0
response
else
- lambda { response.call VariantFilter.new(@variant) }
+ lambda { response.call VariantFilter.new(variant) }
end
end
@@ -175,12 +175,6 @@ def variant_plus_none_for_format
end
end
- def variant_inline_syntax
- respond_to do |format|
- format.html.phone { render text: "phone" }
- end
- end
-
protected
def set_layout
case action_name
@@ -560,16 +554,10 @@ def test_multiple_variants_for_format
assert_equal "tablet", @response.body
end
+
def test_no_variant_in_variant_setup
get :variant_plus_none_for_format
assert_equal "text/html", @response.content_type
assert_equal "none", @response.body
end
-
- def test_variant_inline_syntax
- @request.variant = :phone
- get :variant_inline_syntax
- assert_equal "text/html", @response.content_type
- assert_equal "phone", @response.body
- end
end

0 comments on commit 4aae538

Please sign in to comment.