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 =
'1.5.0'
- Version =
VERSION
- @@markups =
{}
Instance Method Summary
collapse
-
#can_render?(filename, content) ⇒ Boolean
-
#command(symbol, command, regexp, languages, name, &block) ⇒ Object
-
#language(filename, content) ⇒ Object
-
#markup(symbol, gem_name, regexp, languages, opts = {}, &block) ⇒ Object
-
#markup_impl(symbol, impl) ⇒ Object
-
#markup_impls ⇒ Object
-
#markups ⇒ Object
-
#preload! ⇒ Object
-
#render(filename, content = nil) ⇒ Object
-
#render_s(symbol, content) ⇒ Object
-
#renderer(filename, content) ⇒ Object
Instance Method Details
#can_render?(filename, content) ⇒ Boolean
82
83
84
|
# File 'lib/github/markup.rb', line 82
def can_render?(filename, content)
!!renderer(filename, content)
end
|
#command(symbol, command, regexp, languages, name, &block) ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/github/markup.rb', line 74
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) ⇒ Object
93
94
95
96
97
98
|
# File 'lib/github/markup.rb', line 93
def language(filename, content)
if defined?(::Linguist)
blob = Linguist::Blob.new(filename, content)
return Linguist.detect(blob, allow_empty: true)
end
end
|
#markup(symbol, gem_name, regexp, languages, opts = {}, &block) ⇒ Object
63
64
65
|
# File 'lib/github/markup.rb', line 63
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
67
68
69
70
71
72
|
# File 'lib/github/markup.rb', line 67
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 ⇒ Object
33
34
35
|
# File 'lib/github/markup.rb', line 33
def markup_impls
markups.values
end
|
#markups ⇒ Object
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 = nil) ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/github/markup.rb', line 43
def render(filename, content = nil)
content ||= File.read(filename)
if impl = renderer(filename, content)
impl.render(content)
else
content
end
end
|
#render_s(symbol, content) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/github/markup.rb', line 53
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
|
#renderer(filename, content) ⇒ Object
86
87
88
89
90
91
|
# File 'lib/github/markup.rb', line 86
def renderer(filename, content)
language = language(filename, content)
markup_impls.find { |impl|
impl.match?(filename, language)
}
end
|