Sha256: 2cdf4a275ee86caafe06167a8d4a12a47fbafe16a5cccbf978e019de18cdb09d

Contents?: true

Size: 1012 Bytes

Versions: 5

Compression:

Stored size: 1012 Bytes

Contents

module Rouge
  # A Formatter takes a token stream and formats it for human viewing.
  class Formatter
    # @private
    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={})
      new(opts).format(tokens)
    end

    # Format a token stream.
    def format(tokens)
      enum_for(:stream, tokens).to_a.join
    end

    # @deprecated Use {#format} instead.
    def render(tokens)
      warn 'Formatter#render is deprecated, use #format instead.'
      format(tokens)
    end

    # @abstract
    # yield strings that, when concatenated, form the formatted output
    def stream(tokens, &b)
      raise 'abstract'
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rouge-0.2.8 lib/rouge/formatter.rb
rouge-0.2.7 lib/rouge/formatter.rb
rouge-0.2.6 lib/rouge/formatter.rb
rouge-0.2.5 lib/rouge/formatter.rb
rouge-0.2.4 lib/rouge/formatter.rb