Class: CodeRay::Encoders::XML

### Home Classes Methods

### In Files

- lib/coderay/encoders/xml.rb

### Parent

CodeRay::Encoders::Encoder

### Methods

- #begin_group
- #end_group
- #finish
- #setup
- #text_token

### Class/Module Index

Quicksearch

- CodeRay
- CodeRay::Duo
- CodeRay::Encoders
- CodeRay::Encoders::CommentFilter
- CodeRay::Encoders::Count
- CodeRay::Encoders::Debug
- CodeRay::Encoders::DebugLint
- CodeRay::Encoders::Div
- CodeRay::Encoders::Encoder
- CodeRay::Encoders::Filter
- CodeRay::Encoders::HTML
- CodeRay::Encoders::HTML::Output
- CodeRay::Encoders::JSON
- CodeRay::Encoders::LinesOfCode
- CodeRay::Encoders::Lint
- CodeRay::Encoders::Null
- CodeRay::Encoders::Page
- CodeRay::Encoders::Span
- CodeRay::Encoders::Statistic
- CodeRay::Encoders::Terminal
- CodeRay::Encoders::Text
- CodeRay::Encoders::TokenKindFilter
- CodeRay::Encoders::XML
- CodeRay::Encoders::YAML
- CodeRay::FileType
- CodeRay::ForRedCloth
- CodeRay::Plugin
- CodeRay::PluginHost
- CodeRay::Scanners
- CodeRay::Scanners::C
- CodeRay::Scanners::CPlusPlus
- CodeRay::Scanners::CSS
- CodeRay::Scanners::Clojure
- CodeRay::Scanners::Debug
- CodeRay::Scanners::Delphi
- CodeRay::Scanners::Diff
- CodeRay::Scanners::ERB
- CodeRay::Scanners::Go
- CodeRay::Scanners::Groovy
- CodeRay::Scanners::HAML
- CodeRay::Scanners::HTML
- CodeRay::Scanners::JSON
- CodeRay::Scanners::Java
- CodeRay::Scanners::JavaScript
- CodeRay::Scanners::Python
- CodeRay::Scanners::Raydebug
- CodeRay::Scanners::Ruby
- CodeRay::Scanners::SQL
- CodeRay::Scanners::Sass
- CodeRay::Scanners::Scanner
- CodeRay::Scanners::Taskpaper
- CodeRay::Scanners::Text
- CodeRay::Scanners::XML
- CodeRay::Scanners::YAML
- CodeRay::Styles
- CodeRay::Styles::Alpha
- CodeRay::Styles::Style
- CodeRay::Tokens
- CodeRay::TokensProxy
- CodeRay::WordList
- CodeRay::WordList::CaseIgnoring

No matching classes.

# CodeRay::Encoders::XML

# XML Encoder

Uses REXML. Very slow.

### Constants

DEFAULT_OPTIONS
FILE_EXTENSION

### Public Instance Methods

begin_group(kind) click to toggle source

    # File lib/coderay/encoders/xml.rb, line 58
    def begin_group kind
      @node = @node.add_element kind.to_s
    end

end_group(kind) click to toggle source

    # File lib/coderay/encoders/xml.rb, line 62
    def end_group kind
      if @node == @root
        raise 'no token to close!'
      end
      @node = @node.parent
    end

text_token(text, kind) click to toggle source

    # File lib/coderay/encoders/xml.rb, line 38
    def text_token text, kind
      if kind == :space
        token = @node
      else
        token = @node.add_element kind.to_s
      end
      text.scan(/(\x20+)|(\t+)|(\n)|[^\x20\t\n]+/) do |space, tab, nl|
        case
        when space
          token << REXML::Text.new(space, true)
        when tab
          token << REXML::Text.new(tab, true)
        when nl
          token << REXML::Text.new(nl, true)
        else
          token << REXML::Text.new($&)
        end
      end
    end

### Protected Instance Methods

finish(options) click to toggle source

    # File lib/coderay/encoders/xml.rb, line 31
    def finish options
      @doc.write @out, options[:pretty], options[:transitive], true

      super
    end

setup(options) click to toggle source

    # File lib/coderay/encoders/xml.rb, line 22
    def setup options
      super

      @doc = REXML::Document.new
      @doc << REXML::XMLDecl.new
      @tab_width = options[:tab_width]
      @root = @node = @doc.add_element('coderay-tokens')
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.