Parent

Class/Module Index [+]

Quicksearch

Rouge::Formatter

A Formatter takes a token stream and formats it for human viewing.

Constants

REGISTRY

@private

Public Class Methods

find(tag) click to toggle source

Find a formatter class given a unique tag.

# File lib/rouge/formatter.rb, line 17
def self.find(tag)
  REGISTRY[tag]
end
format(tokens, opts={}, &b) click to toggle source

Format a token stream. Delegates to {format}.

# File lib/rouge/formatter.rb, line 22
def self.format(tokens, opts={}, &b)
  new(opts).format(tokens, &b)
end
tag(tag=nil) click to toggle source

Specify or get the unique tag for this formatter. This is used for specifying a formatter in `rougify`.

# File lib/rouge/formatter.rb, line 9
def self.tag(tag=nil)
  return @tag unless tag
  REGISTRY[tag] = self

  @tag = tag
end

Public Instance Methods

format(tokens, &b) click to toggle source

Format a token stream.

# File lib/rouge/formatter.rb, line 27
def format(tokens, &b)
  return stream(tokens, &b) if block_given?

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

  out
end
render(tokens) click to toggle source

@deprecated Use {format} instead.

# File lib/rouge/formatter.rb, line 37
def render(tokens)
  warn 'Formatter#render is deprecated, use #format instead.'
  format(tokens)
end
stream(tokens, &b) click to toggle source

@abstract yield strings that, when concatenated, form the formatted output

# File lib/rouge/formatter.rb, line 44
def stream(tokens, &b)
  raise 'abstract'
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.