Module: DocumentsHelper

Defined in:
app/helpers/documents_helper.rb

Instance Method Summary collapse

Instance Method Details

#document_details_tab_class(document, tab) ⇒ Object



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

def document_details_tab_class(document, tab)
  editing = document && document.errors.present?

  case tab
  when :edit
    editing ? 'active' : ''
  when :info
    editing ? '' : 'active'
  else
    ''
  end
end

#icon(document, size = 50) ⇒ Object

Return the right icon based on #document‘s mime type



16
17
18
# File 'app/helpers/documents_helper.rb', line 16

def icon document, size = 50
  "<i class=\"icon_file_#{ size }-#{ icon_mime_type document }\"></i>".html_safe
end

#icon_mime_type(document) ⇒ Object

Find the right class for the icon of this document, based on its format



21
22
23
24
25
26
27
28
29
# File 'app/helpers/documents_helper.rb', line 21

def icon_mime_type document
  if SocialStream::Documents.icon_mime_types[:subtypes].include?(document.format)
    document.format
  elsif SocialStream::Documents.icon_mime_types[:types].include?(document.mime_type_type_sym)
    document.mime_type_type_sym
  else
    SocialStream::Documents.icon_mime_types[:default]
  end
end

#thumb_file_for(document, size) ⇒ Object



7
8
9
10
11
12
13
# File 'app/helpers/documents_helper.rb', line 7

def thumb_file_for(document, size)
  style = document.class.attachment_definitions[:file][:styles]

  format = style.respond_to?('[]') && style[:format] || document.format

  polymorphic_path(document, format: format, style: size)
end

#thumb_for(document, size) ⇒ Object

size can be any of the names that the document has size for



3
4
5
# File 'app/helpers/documents_helper.rb', line 3

def thumb_for(document, size)
  image_tag thumb_file_for(document, size)
end