mime_fallback 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d85a44df5ffc15a5d5990f90b5453b56154d5bea
4
- data.tar.gz: 389e258195c55cf6cf0a0274304f4c4789dd8c40
3
+ metadata.gz: 6becf0be23c41284570b5062bc354122a8ed3c52
4
+ data.tar.gz: a8373245f4f0d32a4b5fadbab3b335ec4a0e6008
5
5
  SHA512:
6
- metadata.gz: 980868568bf78534930d879dfd0bef68c195db86cfec94d6c831bf2c2bed7141ec5832cd51acd5de40195ef8631cf4886d11a65f7abfa1ec96ee033043adff24
7
- data.tar.gz: b28d9e033f917a6d9b64176d330fd251f21526a551f9af7b11265e2c7a2127734653677b3e88d740dd7d5eb62044034f7c838094e3b31b01f76e922572b2033a
6
+ metadata.gz: 67b05bcd555d94bcbb017883223f776fc639393bfbb13f9fffb9695d3af1a297ef1d3e292d5ccea2695629da3b7edbb2a2421be364c648a1bae6febb2f1ba06f
7
+ data.tar.gz: 2376454189c823d9a2cf2e85aaee0c76e70714cc1a9fdeec0c5581c33a17ccef4a4a9150eecaed9b375d3050c7031c73fbb9f55a8482b8a6de353c63b0e2dea7
@@ -0,0 +1,30 @@
1
+ # This overrides the behavior of negotiating mime. Doing this because we
2
+ # aren't able to hook into ActionDispatch::Request
3
+ # This allows the fallbacks to work when you call respond_to {|format| format.something_with_a_fallback }
4
+ module ActionDispatch
5
+ module Http
6
+ module MimeNegotiation
7
+
8
+ # Override to support mime type fallbacks
9
+ def negotiate_mime(order)
10
+ formats.each do |priority|
11
+ if priority == Mime::ALL
12
+ return order.first
13
+ else
14
+ # Try to find an exact match to what we're responding to
15
+ types = Array(priority) + MimeFallback::Type.fallbacks(priority.to_sym)
16
+ types.each do |fallback|
17
+ return fallback if order.map(&:to_sym).include?(fallback.to_sym)
18
+ end
19
+
20
+ if order.include?(priority)
21
+ return priority
22
+ end
23
+ end
24
+ end
25
+
26
+ order.include?(Mime::ALL) ? formats.first : nil
27
+ end
28
+ end
29
+ end
30
+ end
@@ -5,7 +5,6 @@ module MimeFallback
5
5
 
6
6
  initializer "mime_fallback" do |app|
7
7
  ActiveSupport.on_load(:action_controller) do
8
- ActionDispatch::Http::MimeNegotiation.send(:include, MimeFallback::NegotiationExtensions)
9
8
  append_view_path MimeFallback::Resolver.new(File.join(app.root, app.config.mime_fallback.view_path))
10
9
  end
11
10
  end
@@ -8,7 +8,7 @@ module MimeFallback
8
8
  fallbacks ||= MimeFallback::Type.fallbacks(format).dup
9
9
  if fallbacks.present?
10
10
  fallback_details = details.dup
11
- fallback_details[:formats] = Array(format.to_s) + fallbacks.map(&:to_sym)
11
+ fallback_details[:formats] = Array(format.to_sym) + fallbacks.map(&:to_sym)
12
12
  path = build_path(name, prefix, partial)
13
13
  query(path, fallback_details.select {|key| EXTENSIONS.include?(key)}, fallback_details[:formats])
14
14
  else
@@ -1,3 +1,3 @@
1
1
  module MimeFallback
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/mime_fallback.rb CHANGED
@@ -1,9 +1,9 @@
1
- require 'rails'
1
+ require "rails"
2
2
 
3
3
  module MimeFallback
4
- autoload :NegotiationExtensions, "mime_fallback/negotiation_extensions"
5
4
  autoload :Resolver, "mime_fallback/resolver"
6
5
  autoload :Type, "mime_fallback/type"
7
6
  end
8
7
 
9
- require 'mime_fallback/railtie'
8
+ require "mime_fallback/railtie"
9
+ require "mime_fallback/mime_negotiation"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mime_fallback
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-20 00:00:00.000000000 Z
11
+ date: 2013-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -45,7 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - lib/mime_fallback/negotiation_extensions.rb
48
+ - lib/mime_fallback/mime_negotiation.rb
49
49
  - lib/mime_fallback/railtie.rb
50
50
  - lib/mime_fallback/resolver.rb
51
51
  - lib/mime_fallback/type.rb
@@ -1,31 +0,0 @@
1
- module MimeFallback
2
- module NegotiationExtensions
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- alias_method_chain :negotiate_mime, :mime_fallback
7
- end
8
-
9
- # Override to support mime type fallbacks
10
- def negotiate_mime_with_fallback(order)
11
- formats.each do |priority|
12
- if priority == Mime::ALL
13
- return order.first
14
- else
15
- # Try to find an exact match to what we're responding to
16
- types = Array(priority) + MimeFallback::Type.fallbacks(priority.to_sym)
17
- types.each do |fallback|
18
- return fallback if order.map(&:to_sym).include?(fallback.to_sym)
19
- end
20
-
21
- if order.include?(priority)
22
- return priority
23
- end
24
- end
25
- end
26
-
27
- order.include?(Mime::ALL) ? formats.first : nil
28
- end
29
-
30
- end
31
- end