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

Instance Method Summary collapse

Instance Method Details

#can_render?(filename) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/github/markup.rb', line 76

def can_render?(filename)
  !!renderer(filename)
end

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



68
69
70
71
72
73
74
# File 'lib/github/markup.rb', line 68

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

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

#markup(symbol, file, pattern, opts = {}, &block) ⇒ Object



57
58
59
# File 'lib/github/markup.rb', line 57

def markup(symbol, file, pattern, opts = {}, &block)
  markup_impl(symbol, GemImplementation.new(pattern, file, &block))
end

#markup_impl(symbol, impl) ⇒ Object



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

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



27
28
29
# File 'lib/github/markup.rb', line 27

def markup_impls
  markups.values
end

#markupsObject



23
24
25
# File 'lib/github/markup.rb', line 23

def markups
  @@markups
end

#preload!Object



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

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

#render(filename, content = nil) ⇒ Object



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

def render(filename, content = nil)
  content ||= File.read(filename)

  if impl = renderer(filename)
    impl.render(content)
  else
    content
  end
end

#render_s(symbol, content) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/github/markup.rb', line 47

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



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

def renderer(filename)
  markup_impls.find { |impl|
    impl.match?(filename)
  }
end