File: markup.rb

package info (click to toggle)
ruby-github-markup 1.5.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 336 kB
  • ctags: 118
  • sloc: ruby: 373; python: 113; sh: 21; makefile: 15
file content (55 lines) | stat: -rw-r--r-- 1,142 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require "github/markup/command_implementation"
require "github/markup/gem_implementation"

module GitHub
  module Markup
    extend self
    @@markups = []

    def markups
      @@markups
    end

    def preload!
      markups.each do |markup|
        markup.load
      end
    end

    def render(filename, content = nil)
      content ||= File.read(filename)

      if impl = renderer(filename)
        impl.render(content)
      else
        content
      end
    end

    def markup(file, pattern, opts = {}, &block)
      markups << GemImplementation.new(pattern, file, &block)
    end

    def command(command, regexp, name, &block)
      if File.exist?(file = File.dirname(__FILE__) + "/commands/#{command}")
        command = file
      end

      markups << CommandImplementation.new(regexp, command, name, &block)
    end

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

    def renderer(filename)
      markups.find { |impl|
        impl.match?(filename)
      }
    end

    # Define markups
    markups_rb = File.dirname(__FILE__) + '/markups.rb'
    instance_eval File.read(markups_rb), markups_rb
  end
end