Module: Refinery::IconHelper

Defined in:
app/helpers/refinery/icon_helper.rb

Instance Method Summary collapse

Instance Method Details

#application_iconsObject



32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/refinery/icon_helper.rb', line 32

def application_icons = {
  document: "word",
  ms_excel: "excel",
  ms_powerpoint: "powerpoint",
  msword: "word",
  pdf: "pdf",
  presentation: "powerpoint",
  x_rar: "archive",
  sheet: "excel",
  zip: "zip",
}

#application_type(type) ⇒ Object

handle mime-types like ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’ and

'application/vnd.ms-excel'


23
24
25
26
27
28
# File 'app/helpers/refinery/icon_helper.rb', line 23

def application_type(type)
  last_word = type.split('.').last # remove intermediate paths
                  .gsub('-', '_') # convert dashes to underscore
                  .to_sym
  application_icons[last_word]
end

#available_iconsObject

these are the fontawesome-4 icons matching a document type



45
46
47
48
49
# File 'app/helpers/refinery/icon_helper.rb', line 45

def available_icons = Set[
  'archive', 'audio', 'code', 'excel', 'image',
  'movie', 'pdf', 'photo', 'picture', 'plain',
  'powerpoint', 'sound', 'text', 'video', 'word', 'zip',
]

#icon_class(icon) ⇒ Object



30
# File 'app/helpers/refinery/icon_helper.rb', line 30

def icon_class(icon) = "#{icon}_icon"

#mime_type_icon(mime_type) ⇒ Object

finds icons for documents such as resources and images split mime_type, handle special case of ‘application’, match type or subtype to icons we support



9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/refinery/icon_helper.rb', line 9

def mime_type_icon(mime_type)
  default_icon = 'file-o'

  type, sub_type = mime_type.split('/')
  sub_type = application_type(sub_type) if type == 'application'

  icons = available_icons & Set[type, sub_type]  # intersection
  icon = icons.empty? ? default_icon : icons.first

  tag.span class: icon_class(icon)
end