Module: GitHub::Markup

Extended by:
Markup
Included in:
Markup
Defined in:
lib/github/markup.rb,
lib/github/markup/rdoc.rb,
lib/github/markup/version.rb

Defined Under Namespace

Classes: RDoc

Constant Summary collapse

Version =
'0.1.1'
@@markups =
{}

Instance Method Summary collapse

Instance Method Details

#add_markup(regexp, &block) ⇒ Object



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

def add_markup(regexp, &block)
  @@markups[regexp] = block
end

#can_render?(filename) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/github/markup.rb', line 43

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

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



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/github/markup.rb', line 27

def command(command, regexp, &block)
  command = command.to_s
  if !File.exists?(command) && !command.include?('/')
    command = File.dirname(__FILE__) + '/commands/' + command.to_s
  end

  add_markup(regexp) do |content|
    rendered = execute(command, content)
    block ? block.call(rendered) : rendered
  end
end

#execute(command, target) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/github/markup.rb', line 56

def execute(command, target)
  out = ''
  Open3.popen3(command) do |stdin, stdout, _|
    stdin.puts target
    stdin.close
    out = stdout.read
  end
  out.gsub("\r", '')
end

#markup(file, pattern, &block) ⇒ Object



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

def markup(file, pattern, &block)
  require file.to_s
  add_markup(pattern, &block)
rescue LoadError
  nil
end

#render(filename, content) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/github/markup.rb', line 12

def render(filename, content)
  if proc = renderer(filename)
    proc[content]
  else
    content
  end
end

#renderer(filename) ⇒ Object



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

def renderer(filename)
  @@markups.each do |key, value|
    if Regexp.compile("\\.(#{key})$") =~ filename
      return value
    end
  end
  nil
end