Skip to content

Commit 4aae538

Browse files
author
David Heinemeier Hansson
committed
Revert "Merge pull request rails#13235 from strzalek/variants-inline" -- needs a little more work!
This reverts commit 1861611, reversing changes made to cad9eb1.
1 parent 1861611 commit 4aae538

File tree

2 files changed

+10
-28
lines changed

2 files changed

+10
-28
lines changed

actionpack/lib/action_controller/metal/mime_responds.rb

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def respond_to(*mimes, &block)
215215
raise ArgumentError, "respond_to takes either types or a block, never both" if mimes.any? && block_given?
216216

217217
if collector = retrieve_collector_from_mimes(mimes, &block)
218-
response = collector.response
218+
response = collector.response(request.variant)
219219
response ? response.call : render({})
220220
end
221221
end
@@ -357,7 +357,7 @@ def respond_with(*resources, &block)
357357
if collector = retrieve_collector_from_mimes(&block)
358358
options = resources.size == 1 ? {} : resources.extract_options!
359359
options = options.clone
360-
options[:default_response] = collector.response
360+
options[:default_response] = collector.response(request.variant)
361361
(options.delete(:responder) || self.class.responder).call(self, resources, options)
362362
end
363363
end
@@ -390,7 +390,7 @@ def collect_mimes_from_class_level #:nodoc:
390390
# is available.
391391
def retrieve_collector_from_mimes(mimes=nil, &block) #:nodoc:
392392
mimes ||= collect_mimes_from_class_level
393-
collector = Collector.new(mimes, request.variant)
393+
collector = Collector.new(mimes)
394394
block.call(collector) if block_given?
395395
format = collector.negotiate_format(request)
396396

@@ -428,11 +428,9 @@ class Collector
428428
include AbstractController::Collector
429429
attr_accessor :format
430430

431-
def initialize(mimes, variant = nil)
431+
def initialize(mimes)
432432
@responses = {}
433-
@variant = variant
434-
435-
mimes.each { |mime| @responses["Mime::#{mime.upcase}".constantize] = nil }
433+
mimes.each { |mime| send(mime) }
436434
end
437435

438436
def any(*args, &block)
@@ -446,19 +444,15 @@ def any(*args, &block)
446444

447445
def custom(mime_type, &block)
448446
mime_type = Mime::Type.lookup(mime_type.to_s) unless mime_type.is_a?(Mime::Type)
449-
@responses[mime_type] ||= if block_given?
450-
block
451-
else
452-
VariantFilter.new(@variant)
453-
end
447+
@responses[mime_type] ||= block
454448
end
455449

456-
def response
450+
def response(variant)
457451
response = @responses.fetch(format, @responses[Mime::ALL])
458-
if response.is_a?(VariantFilter) || response.nil? || response.arity == 0
452+
if response.nil? || response.arity == 0
459453
response
460454
else
461-
lambda { response.call VariantFilter.new(@variant) }
455+
lambda { response.call VariantFilter.new(variant) }
462456
end
463457
end
464458

actionpack/test/controller/mime/respond_to_test.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ def variant_plus_none_for_format
175175
end
176176
end
177177

178-
def variant_inline_syntax
179-
respond_to do |format|
180-
format.html.phone { render text: "phone" }
181-
end
182-
end
183-
184178
protected
185179
def set_layout
186180
case action_name
@@ -560,16 +554,10 @@ def test_multiple_variants_for_format
560554
assert_equal "tablet", @response.body
561555
end
562556

557+
563558
def test_no_variant_in_variant_setup
564559
get :variant_plus_none_for_format
565560
assert_equal "text/html", @response.content_type
566561
assert_equal "none", @response.body
567562
end
568-
569-
def test_variant_inline_syntax
570-
@request.variant = :phone
571-
get :variant_inline_syntax
572-
assert_equal "text/html", @response.content_type
573-
assert_equal "phone", @response.body
574-
end
575563
end

0 commit comments

Comments
 (0)