File: formatter.rb

package info (click to toggle)
ruby-rugments 1.0.0~beta8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 820 kB
  • sloc: ruby: 10,293; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 716 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
module Rugments
  # A Formatter takes a token stream and formats it for human viewing.
  class Formatter
    REGISTRY = {}

    # Specify or get the unique tag for this formatter.  This is used
    # for specifying a formatter in `rougify`.
    def self.tag(tag = nil)
      return @tag unless tag
      REGISTRY[tag] = self

      @tag = tag
    end

    # Find a formatter class given a unique tag.
    def self.find(tag)
      REGISTRY[tag]
    end

    # Format a token stream.  Delegates to {#format}.
    def self.format(tokens, opts = {}, &b)
      new(opts).format(tokens, &b)
    end
  end
end

require_relative 'formatters/html'
require_relative 'formatters/terminal256'
require_relative 'formatters/null'