Sha256: 72189dde373646d4147459e761cacd4d57d7ca4fb917db0a1f29643fc3210705

Contents?: true

Size: 1.08 KB

Versions: 33

Compression:

Stored size: 1.08 KB

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={}, &b)
      new(opts).format(tokens, &b)
    end

    # Format a token stream.
    def format(tokens, &b)
      return stream(tokens, &b) if block_given?

      out = ''
      stream(tokens) { |piece| out << piece }

      out
    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

33 entries across 33 versions & 1 rubygems

Version Path
rouge-1.5.0 lib/rouge/formatter.rb
rouge-1.4.0 lib/rouge/formatter.rb
rouge-1.3.4 lib/rouge/formatter.rb
rouge-1.3.3 lib/rouge/formatter.rb
rouge-1.3.2 lib/rouge/formatter.rb
rouge-1.3.1 lib/rouge/formatter.rb
rouge-1.3.0 lib/rouge/formatter.rb
rouge-1.2.0 lib/rouge/formatter.rb
rouge-1.1.0 lib/rouge/formatter.rb
rouge-0.5.4 lib/rouge/formatter.rb
rouge-0.5.3 lib/rouge/formatter.rb
rouge-0.5.2 lib/rouge/formatter.rb
rouge-0.5.1 lib/rouge/formatter.rb
rouge-0.5.0 lib/rouge/formatter.rb
rouge-0.4.0 lib/rouge/formatter.rb
rouge-0.3.10 lib/rouge/formatter.rb
rouge-0.3.9 lib/rouge/formatter.rb
rouge-0.3.8 lib/rouge/formatter.rb
rouge-0.3.7 lib/rouge/formatter.rb
rouge-0.3.6 lib/rouge/formatter.rb