Sha256: 5311347ebd15880d37c7b45dd4bbfc18258762d9184452d630cc4b5088af99b7

Contents?: true

Size: 928 Bytes

Versions: 10

Compression:

Stored size: 928 Bytes

Contents

module GitHub
  module Markup
    class Implementation
      attr_reader :regexp
      attr_reader :languages

      def initialize(regexp, languages)
        @regexp = regexp

        if defined?(::Linguist)
          @languages = languages.map do |l|
            lang = Linguist::Language[l]
            raise "no match for language #{l.inspect}" if lang.nil?
            lang
          end
        end
      end

      def load
        # no-op by default
      end

      def render(filename, content, options: {})
        raise NotImplementedError, "subclasses of GitHub::Markup::Implementation must define #render"
      end

      def match?(filename, language)
        if defined?(::Linguist)
          languages.include? language
        else
          file_ext_regexp =~ filename
        end
      end

      private

      def file_ext_regexp
        @file_ext_regexp ||= /\.(#{regexp})\z/
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/github-markup-5.0.1/lib/github/markup/implementation.rb
github-markup-5.0.1 lib/github/markup/implementation.rb
github-markup-5.0.0 lib/github/markup/implementation.rb
github-markup-4.0.2 lib/github/markup/implementation.rb
github-markup-4.0.1 lib/github/markup/implementation.rb
github-markup-4.0.0 lib/github/markup/implementation.rb
github-markup-3.0.5 lib/github/markup/implementation.rb
github-markup-3.0.4 lib/github/markup/implementation.rb
github-markup-3.0.3 lib/github/markup/implementation.rb
github-markup-3.0.2 lib/github/markup/implementation.rb