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 =
'2.0.0'
Version =
VERSION
@@markups =
{}

Instance Method Summary collapse

Instance Method Details

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

Returns:

  • (Boolean)


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

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

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



72
73
74
75
76
77
78
# 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

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

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



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

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) ⇒ Object



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

def markup(symbol, gem_name, regexp, languages, opts = {}, &block)
  markup_impl(symbol, GemImplementation.new(regexp, languages, gem_name, &block))
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.has_key?(symbol)
    raise ArgumentError, "The '#{symbol}' symbol is already defined."
  end
  markups[symbol] = impl
end

#markup_implsObject



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

def markup_impls
  markups.values
end

#markupsObject



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

def markups
  @@markups
end

#preload!Object



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

def preload!
  markup_impls.each do |markup|
    markup.load
  end
end

#render(filename, content, symlink = false) ⇒ Object



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

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

#render_s(symbol, content) ⇒ Object



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

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) ⇒ Object



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

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