BigW Consortium Gitlab

markup_helper.rb 1.28 KB
Newer Older
1
module Gitlab
2
  module MarkupHelper
3 4 5 6 7 8 9 10
    module_function

    # Public: Determines if a given filename is compatible with GitHub::Markup.
    #
    # filename - Filename string to check
    #
    # Returns boolean
    def markup?(filename)
11 12 13 14
      gitlab_markdown?(filename) ||
        asciidoc?(filename) ||
        filename.downcase.end_with?(*%w(.textile .rdoc .org .creole .wiki
                                        .mediawiki .rst))
15 16 17 18 19 20 21 22 23
    end

    # Public: Determines if a given filename is compatible with
    # GitLab-flavored Markdown.
    #
    # filename - Filename string to check
    #
    # Returns boolean
    def gitlab_markdown?(filename)
24
      filename.downcase.end_with?(*%w(.mdown .mkd .mkdn .md .markdown))
25
    end
26

27 28 29 30 31 32 33 34 35
    # Public: Determines if the given filename has AsciiDoc extension.
    #
    # filename - Filename string to check
    #
    # Returns boolean
    def asciidoc?(filename)
      filename.downcase.end_with?(*%w(.adoc .ad .asciidoc))
    end

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

46
    def previewable?(filename)
47
      markup?(filename)
48
    end
49 50
  end
end