module GitHub::Markup
def can_render?(filename, content)
def can_render?(filename, content) !!renderer(filename, content) end
def command(symbol, command, languages, name, &block)
def command(symbol, command, languages, name, &block) if File.exist?(file = File.dirname(__FILE__) + "/commands/#{command}") command = file end markup_impl(symbol, CommandImplementation.new(languages, command, name, &block)) end
def language(filename, content)
def language(filename, content) blob = Linguist::Blob.new(filename, content) return Linguist.detect(blob, allow_empty: true) end
def markup(symbol, gem_name, pattern, opts = {}, &block)
def markup(symbol, gem_name, pattern, opts = {}, &block) markup_impl(symbol, GemImplementation.new(pattern, gem_name, &block)) end
def markup_impl(symbol, impl)
def markup_impl(symbol, impl) if markups.has_key?(symbol) raise ArgumentError, "The '#{symbol}' symbol is already defined." end markups[symbol] = impl end
def markup_impls
def markup_impls markups.values end
def markups
def markups @@markups end
def preload!
def preload! markup_impls.each do |markup| markup.load end end
def render(filename, content = nil)
def render(filename, content = nil) content ||= File.read(filename) if impl = renderer(filename, content) impl.render(content) else content end end
def render_s(symbol, content)
def render_s(symbol, content) if content.nil? raise ArgumentError, 'Can not render a nil.' elsif markups.has_key?(symbol) markups[symbol].render(content) else content end end
def renderer(filename, content)
def renderer(filename, content) language = language(filename, content) markup_impls.find { |impl| impl.match?(language) } end