Class: GitHub::Markup::Implementation

Inherits:
Object
  • Object
show all
Defined in:
lib/github/markup/implementation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regexp, languages) ⇒ Implementation

Returns a new instance of Implementation.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/github/markup/implementation.rb', line 7

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

Instance Attribute Details

#languagesObject (readonly)

Returns the value of attribute languages.



5
6
7
# File 'lib/github/markup/implementation.rb', line 5

def languages
  @languages
end

#regexpObject (readonly)

Returns the value of attribute regexp.



4
5
6
# File 'lib/github/markup/implementation.rb', line 4

def regexp
  @regexp
end

Instance Method Details

#loadObject



19
20
21
# File 'lib/github/markup/implementation.rb', line 19

def load
  # no-op by default
end

#match?(filename, language) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
# File 'lib/github/markup/implementation.rb', line 27

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

#render(filename, content, options: {}) ⇒ Object

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/github/markup/implementation.rb', line 23

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