all repos — markup @ 606dfa12397db75c61a4c7f971c91c49380af011

The code we use to render README.your_favorite_markup

lib/github/markup.rb (view raw)

 1require "github/markup/command_implementation"
 2require "github/markup/gem_implementation"
 3
 4module GitHub
 5  module Markup
 6    extend self
 7    @@markups = []
 8
 9    def preload!
10      @@markups.each do |markup|
11        markup.load
12      end
13    end
14
15    def render(filename, content = nil)
16      content ||= File.read(filename)
17
18      if impl = renderer(filename)
19        impl.render(content)
20      else
21        content
22      end
23    end
24
25    def markup(file, pattern, opts = {}, &block)
26      @@markups << GemImplementation.new(pattern, file, &block)
27    end
28
29    def command(command, regexp, &block)
30      if File.exists?(file = File.dirname(__FILE__) + "/commands/#{command}")
31        command = file
32      end
33
34      @@markups << CommandImplementation.new(regexp, command, &block)
35    end
36
37    def can_render?(filename)
38      !!renderer(filename)
39    end
40
41    def renderer(filename)
42      @@markups.find { |impl|
43        impl.match?(filename)
44      }
45    end
46
47    # Define markups
48    markups_rb = File.dirname(__FILE__) + '/markups.rb'
49    instance_eval File.read(markups_rb), markups_rb
50  end
51end