Class Albino
In: lib/albino/multi.rb
lib/albino.rb
Parent: Object

Wrapper for the Pygments command line tool, pygmentize.

Pygments: pygments.org/

Assumes pygmentize is in the path. If not, set its location with Albino.bin = ’/path/to/pygmentize‘

Use like so:

  @syntaxer = Albino.new('puts "Hello World"', :ruby)
  puts @syntaxer.colorize

This‘ll print out an HTMLized, Ruby-highlighted version of ’/some/file.rb’.

To use another formatter, pass it as the third argument:

  @syntaxer = Albino.new('puts "Hello World"', :ruby, :bbcode)
  puts @syntaxer.colorize

You can also use the colorize class method:

  puts Albino.colorize('puts "Hello World"', :ruby)

To format a file, pass a file stream:

  puts Albino.colorize(File.new('/some/file.rb'), :ruby)

Another also: you get a to_s, for somewhat nicer use in Rails views.

  ... helper file ...
  def highlight(text)
    Albino.new(text, :ruby)
  end

  ... view file ...
  <%= highlight text %>

The default lexer is ‘text’. You need to specify a lexer yourself; because we are using STDIN there is no auto-detect.

To see all lexers and formatters available, run `pygmentize -L`.

Chris Wanstrath // chris@ozmm.org

        GitHub // http://github.com

Methods

Included Modules

POSIX::Spawn

Classes and Modules

Class Albino::Multi
Class Albino::ShellArgumentError

Constants

VERSION = '1.3.3'

Attributes

bin  [RW] 
default_encoding  [R] 
timeout_threshold  [RW] 

Public Class methods

Public Instance methods

to_s(options = {})

Alias for colorize

[Validate]