Sha256: e5f0ad2b1905abdc1c4c711570a53f1e83a62dad929641a29102ca7cacd84b7b

Contents?: true

Size: 1.1 KB

Versions: 11

Compression:

Stored size: 1.1 KB

Contents

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, &block)
      if File.exists?(file = File.dirname(__FILE__) + "/commands/#{command}")
        command = file
      end

      markups << CommandImplementation.new(regexp, command, &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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
github-markup-1.3.1 lib/github/markup.rb
github-markup-1.3.0 lib/github/markup.rb
github-markup-1.2.1 lib/github/markup.rb
github-markup-1.2.0 lib/github/markup.rb
github-markup-1.1.2 lib/github/markup.rb
github-markup-1.1.1 lib/github/markup.rb
github-markup-1.1.0 lib/github/markup.rb
github-markup-1.0.3 lib/github/markup.rb
github-markup-1.0.2 lib/github/markup.rb
github-markup-1.0.1 lib/github/markup.rb
github-markup-1.0.0 lib/github/markup.rb