Module CodeRay
In: lib/coderay.rb
lib/coderay/duo.rb
lib/coderay/encoder.rb
lib/coderay/encoders/_map.rb
lib/coderay/encoders/comment_filter.rb
lib/coderay/encoders/count.rb
lib/coderay/encoders/debug.rb
lib/coderay/encoders/div.rb
lib/coderay/encoders/filter.rb
lib/coderay/encoders/html.rb
lib/coderay/encoders/html/css.rb
lib/coderay/encoders/html/numbering.rb
lib/coderay/encoders/html/output.rb
lib/coderay/encoders/json.rb
lib/coderay/encoders/lines_of_code.rb
lib/coderay/encoders/null.rb
lib/coderay/encoders/page.rb
lib/coderay/encoders/span.rb
lib/coderay/encoders/statistic.rb
lib/coderay/encoders/terminal.rb
lib/coderay/encoders/text.rb
lib/coderay/encoders/token_kind_filter.rb
lib/coderay/encoders/xml.rb
lib/coderay/encoders/yaml.rb
lib/coderay/for_redcloth.rb
lib/coderay/helpers/file_type.rb
lib/coderay/helpers/gzip.rb
lib/coderay/helpers/plugin.rb
lib/coderay/helpers/word_list.rb
lib/coderay/scanner.rb
lib/coderay/scanners/_map.rb
lib/coderay/scanners/c.rb
lib/coderay/scanners/clojure.rb
lib/coderay/scanners/cpp.rb
lib/coderay/scanners/css.rb
lib/coderay/scanners/debug.rb
lib/coderay/scanners/delphi.rb
lib/coderay/scanners/diff.rb
lib/coderay/scanners/erb.rb
lib/coderay/scanners/groovy.rb
lib/coderay/scanners/haml.rb
lib/coderay/scanners/html.rb
lib/coderay/scanners/java.rb
lib/coderay/scanners/java/builtin_types.rb
lib/coderay/scanners/java_script.rb
lib/coderay/scanners/json.rb
lib/coderay/scanners/php.rb
lib/coderay/scanners/python.rb
lib/coderay/scanners/raydebug.rb
lib/coderay/scanners/ruby.rb
lib/coderay/scanners/ruby/patterns.rb
lib/coderay/scanners/ruby/string_state.rb
lib/coderay/scanners/sql.rb
lib/coderay/scanners/text.rb
lib/coderay/scanners/xml.rb
lib/coderay/scanners/yaml.rb
lib/coderay/style.rb
lib/coderay/styles/_map.rb
lib/coderay/styles/alpha.rb
lib/coderay/token_kinds.rb
lib/coderay/tokens.rb
lib/coderay/tokens_proxy.rb
lib/coderay/version.rb

encoding: utf-8

Methods

Classes and Modules

Module CodeRay::Encoders
Module CodeRay::FileType
Module CodeRay::ForRedCloth
Module CodeRay::GZip
Module CodeRay::Plugin
Module CodeRay::PluginHost
Module CodeRay::Scanners
Module CodeRay::Styles
Class CodeRay::Duo
Class CodeRay::Tokens
Class CodeRay::TokensProxy
Class CodeRay::WordList

Constants

CODERAY_PATH = File.join File.dirname(__FILE__), 'coderay'
TokenKinds = Hash.new do |h, k| warn 'Undefined Token kind: %p' % [k] if $CODERAY_DEBUG   A Hash of all known token kinds and their associated CSS classes.
VERSION = '1.0.6'

Public Class methods

Assuming the path is a subpath of lib/coderay/

[Source]

     # File lib/coderay.rb, line 133
133:   def self.coderay_path *path
134:     File.join CODERAY_PATH, *path
135:   end

Encode a string.

This scans code with the the Scanner for lang and then encodes it with the Encoder for format. options will be passed to the Encoder.

See CodeRay::Encoder.encode.

[Source]

     # File lib/coderay.rb, line 197
197:     def encode code, lang, format, options = {}
198:       encoder(format, options).encode code, lang, options
199:     end

Encodes filename (a path to a code file) with the Scanner for lang.

See CodeRay.scan_file. Notice that the second argument is the output format, not the input language.

Example:

 require 'coderay'
 page = CodeRay.encode_file 'some_c_code.c', :html

[Source]

     # File lib/coderay.rb, line 222
222:     def encode_file filename, format, options = {}
223:       tokens = scan_file filename, :auto, get_scanner_options(options)
224:       encode_tokens tokens, format, options
225:     end

Encode pre-scanned Tokens. Use this together with CodeRay.scan:

 require 'coderay'

 # Highlight a short Ruby code example in a HTML span
 tokens = CodeRay.scan '1 + 2', :ruby
 puts CodeRay.encode_tokens(tokens, :span)

[Source]

     # File lib/coderay.rb, line 210
210:     def encode_tokens tokens, format, options = {}
211:       encoder(format, options).encode_tokens tokens, options
212:     end

Finds the Encoder class for format and creates an instance, passing options to it.

Example:

 require 'coderay'

 stats = CodeRay.encoder(:statistic)
 stats.encode("puts 17 + 4\n", :ruby)

 puts '%d out of %d tokens have the kind :integer.' % [
   stats.type_stats[:integer].count,
   stats.real_token_count
 ]
 #-> 2 out of 4 tokens have the kind :integer.

[Source]

     # File lib/coderay.rb, line 261
261:     def encoder format, options = {}
262:       Encoders[format].new options
263:     end

Extract the options for the scanner from the options hash.

Returns an empty Hash if :scanner_options is not set.

This is used if a method like CodeRay.encode has to provide options for Encoder and scanner.

[Source]

     # File lib/coderay.rb, line 279
279:     def get_scanner_options options
280:       options.fetch :scanner_options, {}
281:     end

Highlight a string into a HTML <div>.

CSS styles use classes, so you have to include a stylesheet in your output.

See encode.

[Source]

     # File lib/coderay.rb, line 233
233:     def highlight code, lang, options = { :css => :class }, format = :div
234:       encode code, lang, format, options
235:     end

Highlight a file into a HTML <div>.

CSS styles use classes, so you have to include a stylesheet in your output.

See encode.

[Source]

     # File lib/coderay.rb, line 243
243:     def highlight_file filename, options = { :css => :class }, format = :div
244:       encode_file filename, format, options
245:     end

Scans the given code (a String) with the Scanner for lang.

This is a simple way to use CodeRay. Example:

 require 'coderay'
 page = CodeRay.scan("puts 'Hello, world!'", :ruby).html

See also demo/demo_simple.

[Source]

     # File lib/coderay.rb, line 168
168:     def scan code, lang, options = {}, &block
169:       # FIXME: return a proxy for direct-stream encoding
170:       TokensProxy.new code, lang, options, block
171:     end

Scans filename (a path to a code file) with the Scanner for lang.

If lang is :auto or omitted, the CodeRay::FileType module is used to determine it. If it cannot find out what type it is, it uses CodeRay::Scanners::Text.

Calls CodeRay.scan.

Example:

 require 'coderay'
 page = CodeRay.scan_file('some_c_code.c').html

[Source]

     # File lib/coderay.rb, line 184
184:     def scan_file filename, lang = :auto, options = {}, &block
185:       lang = FileType.fetch filename, :text, true if lang == :auto
186:       code = File.read filename
187:       scan code, lang, options, &block
188:     end

Finds the Scanner class for lang and creates an instance, passing options to it.

See Scanner.new.

[Source]

     # File lib/coderay.rb, line 269
269:     def scanner lang, options = {}, &block
270:       Scanners[lang].new '', options, &block
271:     end

[Validate]