Parent

Heel::MimeMap

MimeMap is a Heel specific mime mapping utility. It is based upon MIME::Type and adds some additional mime types. It can also say what the icon name for a particular mime type is.

Public Class Methods

additional_mime_types() click to toggle source

if any other mime types are needed, add them directly via the mime-types calls.

    # File lib/heel/mime_map.rb, line 39
39:       def additional_mime_types
40:         @additional_mime_types ||= [
41:           # [ content-type , [ array, of, filename, extentions] ]
42:           ["images/svg+xml", ["svg"]],
43:           ["video/x-flv", ["flv"]],
44:           ["application/x-shockwave-flash", ["swf"]],
45:           ["text/plain", ["rb", "rhtml"]],
46:         ]
47:       end
icons_by_mime_type() click to toggle source
    # File lib/heel/mime_map.rb, line 16
16:       def icons_by_mime_type
17:         @icons_by_mime_type ||= {
18:             "text/plain"                => "page_white_text.png",
19:             "image"                     => "picture.png",
20:             "pdf"                       => "page_white_acrobat.png",
21:             "xml"                       => "page_white_code.png",
22:             "compress"                  => "compress.png",
23:             "gzip"                      => "compress.png",
24:             "zip"                       => "compress.png",
25:             "application/xhtml+xml"     => "xhtml.png",
26:             "application/word"          => "page_word.png",
27:             "application/excel"         => "page_excel.png",
28:             "application/powerpoint"    => "page_white_powerpoint.png",
29:             "text/html"                 => "html.png",
30:             "application"               => "application.png",
31:             "text"                      => "page_white_text.png",
32:             :directory                  => "folder.png",
33:             :default                    => "page_white.png",
34:         }
35:       end
new() click to toggle source
    # File lib/heel/mime_map.rb, line 50
50:     def initialize
51:       MimeMap.additional_mime_types.each do |mt|
52:         if MIME::Types[mt.first].size == 0 then
53:           type = MIME::Type.from_array(mt)
54:           MIME::Types.add(type)
55:         else
56:           type = MIME::Types[mt.first].first
57:           mt[1].each do |ext|
58:             type.extensions << ext unless type.extensions.include?(ext)
59:           end
60:           # have to reindex if new extensions added
61:           MIME::Types.index_extensions(type)
62:         end
63:       end
64:     end

Public Instance Methods

default_mime_type() click to toggle source
    # File lib/heel/mime_map.rb, line 66
66:     def default_mime_type
67:       @default_mime_type ||= MIME::Types["application/octet-stream"].first
68:     end
icon_for(mime_type) click to toggle source

return the icon name for a particular mime type

    # File lib/heel/mime_map.rb, line 78
78:     def icon_for(mime_type)
79:       icon = nil
80:       [:content_type, :sub_type, :media_type].each do |t| 
81:         icon = MimeMap.icons_by_mime_type[mime_type.send(t)]
82:         return icon if icon
83:       end
84:       icon = MimeMap.icons_by_mime_type[:default]
85:     end
mime_type_of(f) click to toggle source

returns the mime type of the file at a given pathname

    # File lib/heel/mime_map.rb, line 72
72:     def mime_type_of(f)
73:       MIME::Types.of(f).first || default_mime_type
74:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.