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
Constant Summary collapse
- REGISTRY =
{}
Class Method Summary collapse
-
.find(tag) ⇒ Object
Find a formatter class given a unique tag.
-
.format(tokens, opts = {}) ⇒ Object
Format a token stream.
-
.tag(tag = nil) ⇒ Object
Specify or get the unique tag for this formatter.
Instance Method Summary collapse
-
#format(tokens) ⇒ Object
Format a token stream.
-
#render(tokens) ⇒ Object
deprecated
Deprecated.
Use #format instead.
-
#stream(tokens, &b) ⇒ Object
abstract
yield strings that, when concatenated, form the formatted output.
Class Method Details
.find(tag) ⇒ Object
Find a formatter class given a unique tag.
17 18 19 |
# File 'lib/rouge/formatter.rb', line 17 def self.find(tag) REGISTRY[tag] end |
.format(tokens, opts = {}) ⇒ Object
Format a token stream. Delegates to #format.
22 23 24 |
# File 'lib/rouge/formatter.rb', line 22 def self.format(tokens, opts={}) new(opts).format(tokens) end |
.tag(tag = nil) ⇒ Object
Specify or get the unique tag for this formatter. This is used for specifying a formatter in ‘rougify`.
9 10 11 12 13 14 |
# File 'lib/rouge/formatter.rb', line 9 def self.tag(tag=nil) return @tag unless tag REGISTRY[tag] = self @tag = tag end |
Instance Method Details
#format(tokens) ⇒ Object
Format a token stream.
27 28 29 |
# File 'lib/rouge/formatter.rb', line 27 def format(tokens) enum_for(:stream, tokens).to_a.join end |
#render(tokens) ⇒ Object
Deprecated.
Use #format instead.
32 33 34 35 |
# File 'lib/rouge/formatter.rb', line 32 def render(tokens) warn 'Formatter#render is deprecated, use #format instead.' format(tokens) end |
#stream(tokens, &b) ⇒ Object
This method is abstract.
yield strings that, when concatenated, form the formatted output
39 40 41 |
# File 'lib/rouge/formatter.rb', line 39 def stream(tokens, &b) raise 'abstract' end |