Class: CodeRay::Encoders::Encoder
- Inherits:
-
Object
- Object
- CodeRay::Encoders::Encoder
- Extends:
- CodeRay::Plugin
- Defined in:
- vendor/plugins/coderay-0.9.2/lib/coderay/encoder.rb
Overview
Encoder
The Encoder base class. Together with Scanner and Tokens, it forms the highlighting triad.
Encoder instances take a Tokens object and do something with it.
The most common Encoder is surely the HTML encoder (CodeRay::Encoders::HTML). It highlights the code in a colorful html page. If you want the highlighted code in a div or a span instead, use its subclasses Div and Span.
Direct Known Subclasses
Count, Debug, Filter, HTML, JSON, LinesOfCode, Null, Statistic, Term, Text, XML, YAML
Constant Summary
- DEFAULT_OPTIONS =
Subclasses are to store their default options in this constant.
{ :stream => false }
Instance Attribute Summary
-
- (Object) options
The options you gave the Encoder at creating.
-
- (Object) token_stream
readonly
Returns the value of attribute token_stream.
Class Method Summary
-
+ (Object) const_missing(sym)
If FILE_EXTENSION isn’t defined, this method returns the downcase class name instead.
-
+ (Boolean) streamable?
Returns if the Encoder can be used in streaming mode.
Instance Method Summary
-
- (Object) encode(code, lang, options = {})
(also: #highlight)
Encode the given code after tokenizing it using the Scanner for lang.
-
- (Object) encode_stream(code, lang, options = {})
Encode the given code using the Scanner for lang in streaming mode.
-
- (Object) encode_tokens(tokens, options = {})
Encode a Tokens object.
-
- (Object) file_extension
Return the default file extension for outputs of this encoder.
-
- (Encoder) initialize(options = {})
constructor
Creates a new Encoder.
-
- (Object) to_proc
Behave like a proc.
Methods included from CodeRay::Plugin
helper, included, plugin_host, plugin_id, register_for, title
Constructor Details
- (Encoder) initialize(options = {})
Creates a new Encoder. options is saved and used for all encode operations, as long as you don’t overwrite it there by passing additional options.
Encoder objects provide three encode methods:
- encode simply takes a code string and a lang
- encode_tokens expects a tokens object instead
- encode_stream is like encode, but uses streaming mode.
Each method has an optional options parameter. These are added to the options you passed at creation.
68 |
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoder.rb', line 68 def initialize = {} |
Instance Attribute Details
- (Object) options
The options you gave the Encoder at creating.
55 56 57 |
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoder.rb', line 55 def end |
- (Object) token_stream (readonly)
Returns the value of attribute token_stream
30 31 32 |
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoder.rb', line 30 def token_stream @token_stream end |
Class Method Details
+ (Object) const_missing(sym)
If FILE_EXTENSION isn’t defined, this method returns the downcase class name instead.
41 42 43 44 45 46 47 |
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoder.rb', line 41 def const_missing sym if sym == :FILE_EXTENSION plugin_id else super end end |
+ (Boolean) streamable?
Returns if the Encoder can be used in streaming mode.
35 36 37 |
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoder.rb', line 35 def streamable? is_a? Streamable end |
Instance Method Details
- (Object) encode(code, lang, options = {}) Also known as: highlight
Encode the given code after tokenizing it using the Scanner for lang.
84 |
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoder.rb', line 84 def encode code, lang, = {} |
- (Object) encode_stream(code, lang, options = {})
Encode the given code using the Scanner for lang in streaming mode.
97 |
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoder.rb', line 97 def encode_stream code, lang, = {} |
- (Object) encode_tokens(tokens, options = {})
Encode a Tokens object.
75 |
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoder.rb', line 75 def encode_tokens tokens, = {} |
- (Object) file_extension
Return the default file extension for outputs of this encoder.
113 114 115 |
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoder.rb', line 113 def file_extension self.class::FILE_EXTENSION end |
- (Object) to_proc
Behave like a proc. The token method is converted to a proc.
108 109 110 |
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoder.rb', line 108 def to_proc method(:token).to_proc end |