all repos — markup @ d65bb7ee9be795ae607d0d666e34fd4b33be0926

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      # TODO
11    end
12
13    def render(filename, content = nil)
14      content ||= File.read(filename)
15
16      if impl = renderer(filename)
17        impl.render(content)
18      else
19        content
20      end
21    end
22
23    def markup(file, pattern, opts = {}, &block)
24      @@markups << GemImplementation.new(pattern, file, &block)
25    end
26
27    def command(command, regexp, &block)
28      if File.exists?(file = File.dirname(__FILE__) + "/commands/#{command}")
29        command = file
30      end
31
32      @@markups << CommandImplementation.new(regexp, command, &block)
33    end
34
35    def can_render?(filename)
36      !!renderer(filename)
37    end
38
39    def renderer(filename)
40      @@markups.find { |impl|
41        impl.match?(filename)
42      }
43    end
44
45    # Define markups
46    markups_rb = File.dirname(__FILE__) + '/markups.rb'
47    instance_eval File.read(markups_rb), markups_rb
48  end
49end