BigW Consortium Gitlab

markup_helper.rb 1.46 KB
Newer Older
1
module Gitlab
2
  module MarkupHelper
3 4 5 6 7 8
    extend self

    MARKDOWN_EXTENSIONS = %w(mdown mkd mkdn md markdown).freeze
    ASCIIDOC_EXTENSIONS = %w(adoc ad asciidoc).freeze
    OTHER_EXTENSIONS = %w(textile rdoc org creole wiki mediawiki rst).freeze
    EXTENSIONS = MARKDOWN_EXTENSIONS + ASCIIDOC_EXTENSIONS + OTHER_EXTENSIONS
9 10 11 12 13 14 15

    # Public: Determines if a given filename is compatible with GitHub::Markup.
    #
    # filename - Filename string to check
    #
    # Returns boolean
    def markup?(filename)
16
      EXTENSIONS.include?(extension(filename))
17 18 19 20 21 22 23 24 25
    end

    # Public: Determines if a given filename is compatible with
    # GitLab-flavored Markdown.
    #
    # filename - Filename string to check
    #
    # Returns boolean
    def gitlab_markdown?(filename)
26
      MARKDOWN_EXTENSIONS.include?(extension(filename))
27
    end
28

29 30 31 32 33 34
    # Public: Determines if the given filename has AsciiDoc extension.
    #
    # filename - Filename string to check
    #
    # Returns boolean
    def asciidoc?(filename)
35
      ASCIIDOC_EXTENSIONS.include?(extension(filename))
36 37
    end

38 39 40 41 42 43
    # Public: Determines if the given filename is plain text.
    #
    # filename - Filename string to check
    #
    # Returns boolean
    def plain?(filename)
44
      extension(filename) == 'txt' || filename.casecmp('readme').zero?
45 46
    end

47
    def previewable?(filename)
48
      markup?(filename)
49
    end
50 51 52 53 54 55

    private

    def extension(filename)
      File.extname(filename).downcase.delete('.')
    end
56 57
  end
end