summaryrefslogtreecommitdiff
path: root/app/helpers/tree_helper.rb
blob: a5d5c7422302e2e50f9127305f9d9f1f3d323415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module TreeHelper
  def tree_icon(content)
    if content.is_a?(Grit::Blob)
      if content.text?
        image_tag "file_txt.png"
      elsif content.image?
        image_tag "file_img.png"
      else
        image_tag "file_bin.png"
      end
    else
      image_tag "file_dir.png"
    end
  end

  def tree_hex_class(content)
    "file_#{hexdigest(content.name)}"
  end

  def tree_full_path(content)
    content.name.force_encoding('utf-8')
    if params[:path]
      File.join(params[:path], content.name)
    else
      content.name
    end
  end

  # Public: Determines if a given filename is compatible with GitHub::Markup.
  #
  # filename - Filename string to check
  #
  # Returns boolean
  def markup?(filename)
    filename.end_with?(*%w(.mdown .md .markdown .textile .rdoc .org .creole
                          .mediawiki .rst .asciidoc .pod))
  end
end