Module: GitHub::Markup

Extended by:
Markup
Included in:
Markup
Defined in:
lib/github-markup.rb,
lib/github/markup.rb,
lib/github/markup/rdoc.rb,
lib/github/markup/markdown.rb,
lib/github/markup/implementation.rb,
lib/github/markup/gem_implementation.rb,
lib/github/markup/command_implementation.rb

Defined Under Namespace

Classes: CommandError, CommandImplementation, GemImplementation, Implementation, Markdown, RDoc

Constant Summary collapse

VERSION =
'5.0.1'
Version =
VERSION
@@markups =
{}

Instance Method Summary collapse

Instance Method Details

#can_render?(filename, content, symlink: false) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/github/markup.rb', line 81

def can_render?(filename, content, symlink: false)
  renderer(filename, content, symlink: symlink) != nil
end

#command(symbol, command, regexp, languages, name, &block) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/github/markup.rb', line 72

def command(symbol, command, regexp, languages, name, &block)
  if File.exist?(file = File.dirname(__FILE__) + "/commands/#{command}")
    command = file
  end

  impl = CommandImplementation.new(regexp, languages, command, name, &block)
  markup_impl(symbol, impl)
end

#language(filename, content, symlink: false) ⇒ Object



92
93
94
95
96
97
# File 'lib/github/markup.rb', line 92

def language(filename, content, symlink: false)
  return unless defined?(::Linguist)

  blob = Linguist::Blob.new(filename, content, symlink: symlink)
  Linguist.detect(blob, allow_empty: true)
end

#markup(symbol, gem_name, regexp, languages, opts = {}, &block) ⇒ Object



60
61
62
63
# File 'lib/github/markup.rb', line 60

def markup(symbol, gem_name, regexp, languages, opts = {}, &block)
  impl = GemImplementation.new(regexp, languages, gem_name, &block)
  markup_impl(symbol, impl)
end

#markup_impl(symbol, impl) ⇒ Object



65
66
67
68
69
70
# File 'lib/github/markup.rb', line 65

def markup_impl(symbol, impl)
  if markups.key?(symbol)
    raise ArgumentError, "The '#{symbol}' symbol is already defined."
  end
  markups[symbol] = impl
end

#markup_implsObject



34
35
36
# File 'lib/github/markup.rb', line 34

def markup_impls
  markups.values
end

#markupsObject



30
31
32
# File 'lib/github/markup.rb', line 30

def markups
  @@markups
end

#preload!Object



38
39
40
# File 'lib/github/markup.rb', line 38

def preload!
  markup_impls.each(&:load)
end

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



42
43
44
45
46
47
48
# File 'lib/github/markup.rb', line 42

def render(filename, content, symlink: false, options: {})
  if (impl = renderer(filename, content, symlink: symlink))
    impl.render(filename, content, options: options)
  else
    content
  end
end

#render_s(symbol, content, options: {}) ⇒ Object

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
# File 'lib/github/markup.rb', line 50

def render_s(symbol, content, options: {})
  raise ArgumentError, 'Can not render a nil.' if content.nil?

  if markups.key?(symbol)
    markups[symbol].render(nil, content, options: options)
  else
    content
  end
end

#renderer(filename, content, symlink: false) ⇒ Object



85
86
87
88
89
90
# File 'lib/github/markup.rb', line 85

def renderer(filename, content, symlink: false)
  language = language(filename, content, symlink: symlink)
  markup_impls.find do |impl|
    impl.match?(filename, language)
  end
end