Class: Prawn::ManualBuilder::PrawnEncoder

Inherits:
CodeRay::Encoders::Encoder
  • Object
show all
Defined in:
lib/prawn/manual_builder/syntax_highlight.rb

Overview

Registers a to_prawn method on CodeRay. It returns an array of hashes to be used with formatted_text.

Usage:

CodeRay.scan(string, :ruby).to_prawn

Constant Summary collapse

COLORS =
{ :default           => "FFFFFF",
  
  :comment           => "AEAEAE",
  :constant          => "88A5D2",
  :instance_variable => "E8ED97",
  :integer           => "C8FF0E",
  :float             => "C8FF0E",
  :inline_delimiter  => "EF804F",  # #{} within a string
  :keyword           => "FEE100",
  
  # BUG: There appear to be some problem with this token. Method
  #      definitions are considered as ident tokens
  #
  :method            => "FF5C00",
  :string            => "56D65E",
  :symbol            => "C8FF0E" 
}

Instance Method Summary collapse

Instance Method Details

#begin_group(kind) ⇒ Object



47
48
49
# File 'lib/prawn/manual_builder/syntax_highlight.rb', line 47

def begin_group(kind)
  @open << kind
end

#end_group(kind) ⇒ Object



51
52
53
# File 'lib/prawn/manual_builder/syntax_highlight.rb', line 51

def end_group(kind)
  @open.pop
end

#setup(options) ⇒ Object



35
36
37
38
39
# File 'lib/prawn/manual_builder/syntax_highlight.rb', line 35

def setup(options)
  super
  @out  = []
  @open = []
end

#text_token(text, kind) ⇒ Object



41
42
43
44
45
# File 'lib/prawn/manual_builder/syntax_highlight.rb', line 41

def text_token(text, kind)
  color = COLORS[kind] || COLORS[@open.last] || COLORS[:default]
  
  @out << {:text => text, :color => color}
end