all repos — markup @ b7cabb1c81ea30035dd63a508a67a949c1846f4c

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