module GitHub::Markup

Constants

VERSION
Version

Public Instance Methods

can_render?(filename, content, symlink = false) click to toggle source
# File lib/github/markup.rb, line 83
def can_render?(filename, content, symlink = false)
  !!renderer(filename, content, symlink)
end
command(symbol, command, regexp, languages, name, &block) click to toggle source
# File lib/github/markup.rb, line 75
def command(symbol, command, regexp, languages, name, &block)
  if File.exist?(file = File.dirname(__FILE__) + "/commands/#{command}")
    command = file
  end

  markup_impl(symbol, CommandImplementation.new(regexp, languages, command, name, &block))
end
language(filename, content, symlink = false) click to toggle source
# File lib/github/markup.rb, line 94
def language(filename, content, symlink = false)
  if defined?(::Linguist)
    blob = Linguist::Blob.new(filename, content, symlink: symlink)
    return Linguist.detect(blob, allow_empty: true)
  end
end
markup(symbol, gem_name, regexp, languages, opts = {}, &block) click to toggle source
# File lib/github/markup.rb, line 64
def markup(symbol, gem_name, regexp, languages, opts = {}, &block)
  markup_impl(symbol, GemImplementation.new(regexp, languages, gem_name, &block))
end
markup_impl(symbol, impl) click to toggle source
# File lib/github/markup.rb, line 68
def markup_impl(symbol, impl)
  if markups.has_key?(symbol)
    raise ArgumentError, "The '#{symbol}' symbol is already defined."
  end
  markups[symbol] = impl
end
markup_impls() click to toggle source
# File lib/github/markup.rb, line 33
def markup_impls
  markups.values
end
markups() click to toggle source
# File lib/github/markup.rb, line 29
def markups
  @@markups
end
preload!() click to toggle source
# File lib/github/markup.rb, line 37
def preload!
  markup_impls.each do |markup|
    markup.load
  end
end
render(filename, content = nil, symlink = nil) click to toggle source
# File lib/github/markup.rb, line 43
def render(filename, content = nil, symlink = nil)
  content ||= File.read(filename)
  symlink = (File.symlink?(filename) rescue false) if symlink.nil?

  if impl = renderer(filename, content, symlink)
    impl.render(filename, content)
  else
    content
  end
end
render_s(symbol, content) click to toggle source
# File lib/github/markup.rb, line 54
def render_s(symbol, content)
  if content.nil?
    raise ArgumentError, 'Can not render a nil.'
  elsif markups.has_key?(symbol)
    markups[symbol].render(nil, content)
  else
    content
  end
end
renderer(filename, content, symlink = false) click to toggle source
# File lib/github/markup.rb, line 87
def renderer(filename, content, symlink = false)
  language = language(filename, content, symlink)
  markup_impls.find { |impl|
    impl.match?(filename, language)
  }
end