all repos — markup @ 5f0d596341c85a9ce8950161805faabcb9a16947

The code we use to render README.your_favorite_markup

lib/github/markup.rb (view raw)

 1module GitHub
 2  module Markup
 3    extend self
 4    @@markups = {}
 5
 6    def markup(file, pattern, &block)
 7      require file.to_s
 8      add_markup(pattern, &block)
 9    rescue LoadError
10      nil
11    end
12
13    def add_markup(regexp, &block)
14      @@markups[regexp] = block
15    end
16
17    def renderer(filename)
18      @@markups.each do |key, value|
19        if Regexp.compile("#{key}$") =~ filename
20          return value
21        end
22      end
23    end
24
25    def render(filename, content)
26      renderer(filename)[content] || content
27    end
28
29    # Define markups
30    instance_eval File.read(File.dirname(__FILE__) + '/markups.rb')
31  end
32end