Sha256: 9991ff17a647e30d267abb618648127487e7993666de313b3bb7186d0a9617d4

Contents?: true

Size: 1.48 KB

Versions: 10

Compression:

Stored size: 1.48 KB

Contents

# encoding: utf-8

require "coderay"

module Prawn
  module ManualBuilder
    # 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
    #
    class PrawnEncoder < CodeRay::Encoders::Encoder
      register_for :to_prawn

      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" 
               }

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

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

      def begin_group(kind)
        @open << kind
      end

      def end_group(kind)
        @open.pop
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
prawn-manual_builder-0.3.1 lib/prawn/manual_builder/syntax_highlight.rb
prawn-manual_builder-0.3.0 lib/prawn/manual_builder/syntax_highlight.rb
prawn-manual_builder-0.2.0 lib/prawn/manual_builder/syntax_highlight.rb
prawn-manual_builder-0.1.3 lib/prawn/manual_builder/syntax_highlight.rb
prawn-manual_builder-0.1.2 lib/prawn/manual_builder/syntax_highlight.rb
prawn-manual_builder-0.1.1 lib/prawn/manual_builder/syntax_highlight.rb
prawn-manual_builder-0.1.0 lib/prawn/manual_builder/syntax_highlight.rb
prawn-manual_builder-0.0.3 lib/prawn/manual_builder/syntax_highlight.rb
prawn-manual_builder-0.0.2 lib/prawn/manual_builder/syntax_highlight.rb
prawn-manual_builder-0.0.1 lib/prawn/manual_builder/syntax_highlight.rb