Skip to content

Commit

Permalink
Remove Mime::Type translations from Action View
Browse files Browse the repository at this point in the history
Action View should not be responsible for translating mime types. Any
translation that's needed should be handled at controller level.
  • Loading branch information
drogus committed Aug 28, 2012
1 parent 7abc0c7 commit f21a528
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions actionpack/lib/action_view/template.rb
Expand Up @@ -121,7 +121,7 @@ def initialize(source, identifier, handler, details)
@locals = details[:locals] || []
@virtual_path = details[:virtual_path]
@updated_at = details[:updated_at] || Time.now
@formats = Array(format).map { |f| f.is_a?(Mime::Type) ? f.ref : f }
@formats = Array(format).map { |f| f.to_sym }
@compile_mutex = Mutex.new
end

Expand All @@ -146,8 +146,8 @@ def render(view, locals, buffer=nil, &block)
handle_render_error(view, e)
end

def mime_type
@mime_type ||= Mime::Type.lookup_by_extension(@formats.first.to_s) if @formats.first
def type
@type ||= @formats.first.to_sym if @formats.first
end

# Receives a view object and return a template similar to self by using @virtual_path.
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/template/handlers/builder.rb
Expand Up @@ -3,7 +3,7 @@ module Template::Handlers
class Builder
# Default format used by Builder.
class_attribute :default_format
self.default_format = Mime::XML
self.default_format = :xml

def call(template)
require_engine
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/template/resolver.rb
Expand Up @@ -235,7 +235,7 @@ def extract_handler_and_format(path, default_formats)
extension = pieces.pop
ActiveSupport::Deprecation.warn "The file #{path} did not specify a template handler. The default is currently ERB, but will change to RAW in the future." unless extension
handler = Template.handler_for_extension(extension)
format = pieces.last && Mime[pieces.last]
format = pieces.last && pieces.last.to_sym
[handler, format]
end
end
Expand Down
11 changes: 5 additions & 6 deletions actionpack/lib/action_view/template/text.rb
Expand Up @@ -2,12 +2,11 @@ module ActionView #:nodoc:
# = Action View Text Template
class Template
class Text #:nodoc:
attr_accessor :mime_type
attr_accessor :type

def initialize(string, mime_type = nil)
@string = string.to_s
@mime_type = Mime[mime_type] || mime_type if mime_type
@mime_type ||= Mime::TEXT
def initialize(string, type = nil)
@string = string.to_s
@type = type || :text
end

def identifier
Expand All @@ -27,7 +26,7 @@ def render(*args)
end

def formats
[@mime_type.to_sym]
[@type.to_sym]
end
end
end
Expand Down

0 comments on commit f21a528

Please sign in to comment.