Class: Rouge::Formatter
- Inherits:
-
Object
- Object
- Rouge::Formatter
- Defined in:
- lib/rouge/formatter.rb
Overview
A Formatter takes a token stream and formats it for human viewing.
Direct Known Subclasses
Rouge::Formatters::HTML, Rouge::Formatters::HTMLLegacy, Rouge::Formatters::HTMLLinewise, Rouge::Formatters::HTMLPygments, Rouge::Formatters::HTMLTable, Rouge::Formatters::Null, Rouge::Formatters::Terminal256
Constant Summary collapse
- REGISTRY =
{}
Class Method Summary collapse
-
.find(tag) ⇒ Object
Find a formatter class given a unique tag.
-
.format(tokens, *a, &b) ⇒ Object
Format a token stream.
-
.tag(tag = nil) ⇒ Object
Specify or get the unique tag for this formatter.
Instance Method Summary collapse
-
#format(tokens, &b) ⇒ Object
Format a token stream.
-
#initialize(opts = {}) ⇒ Formatter
constructor
A new instance of Formatter.
-
#render(tokens) ⇒ Object
deprecated
Deprecated.
Use #format instead.
-
#stream(tokens, &b) ⇒ Object
abstract
yield strings that, when concatenated, form the formatted output.
Constructor Details
#initialize(opts = {}) ⇒ Formatter
Returns a new instance of Formatter.
28 29 30 |
# File 'lib/rouge/formatter.rb', line 28 def initialize(opts={}) # pass end |
Class Method Details
.find(tag) ⇒ Object
Find a formatter class given a unique tag.
19 20 21 |
# File 'lib/rouge/formatter.rb', line 19 def self.find(tag) REGISTRY[tag] end |
.format(tokens, *a, &b) ⇒ Object
Format a token stream. Delegates to #format.
24 25 26 |
# File 'lib/rouge/formatter.rb', line 24 def self.format(tokens, *a, &b) new(*a).format(tokens, &b) end |
.tag(tag = nil) ⇒ Object
Specify or get the unique tag for this formatter. This is used for specifying a formatter in ‘rougify`.
11 12 13 14 15 16 |
# File 'lib/rouge/formatter.rb', line 11 def self.tag(tag=nil) return @tag unless tag REGISTRY[tag] = self @tag = tag end |
Instance Method Details
#format(tokens, &b) ⇒ Object
Format a token stream.
33 34 35 36 37 38 39 40 |
# File 'lib/rouge/formatter.rb', line 33 def format(tokens, &b) return stream(tokens, &b) if block_given? out = '' stream(tokens) { |piece| out << piece } out end |
#render(tokens) ⇒ Object
Use #format instead.
43 44 45 46 |
# File 'lib/rouge/formatter.rb', line 43 def render(tokens) warn 'Formatter#render is deprecated, use #format instead.' format(tokens) end |
#stream(tokens, &b) ⇒ Object
yield strings that, when concatenated, form the formatted output
50 51 52 |
# File 'lib/rouge/formatter.rb', line 50 def stream(tokens, &b) raise 'abstract' end |