Class: CodeRay::Encoders::JSON

### Home Classes Methods

### In Files

- lib/coderay/encoders/json.rb

### Parent

CodeRay::Encoders::Encoder

### Methods

- #append
- #begin_group
- #begin_line
- #end_group
- #end_line
- #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::JSON

A simple JSON Encoder.

Example:

    CodeRay.scan('puts "Hello world!"', :ruby).json

yields

    [
      {"type"=>"text", "text"=>"puts", "kind"=>"ident"},
      {"type"=>"text", "text"=>" ", "kind"=>"space"},
      {"type"=>"block", "action"=>"open", "kind"=>"string"},
      {"type"=>"text", "text"=>"\"", "kind"=>"delimiter"},
      {"type"=>"text", "text"=>"Hello world!", "kind"=>"content"},
      {"type"=>"text", "text"=>"\"", "kind"=>"delimiter"},
      {"type"=>"block", "action"=>"close", "kind"=>"string"},
    ]

### Constants

FILE_EXTENSION

### Public Instance Methods

begin_group(kind) click to toggle source

    # File lib/coderay/encoders/json.rb, line 64
    def begin_group kind
      append :type => 'block', :action => 'open', :kind => kind
    end

begin_line(kind) click to toggle source

    # File lib/coderay/encoders/json.rb, line 72
    def begin_line kind
      append :type => 'block', :action => 'begin_line', :kind => kind
    end

end_group(kind) click to toggle source

    # File lib/coderay/encoders/json.rb, line 68
    def end_group kind
      append :type => 'block', :action => 'close', :kind => kind
    end

end_line(kind) click to toggle source

    # File lib/coderay/encoders/json.rb, line 76
    def end_line kind
      append :type => 'block', :action => 'end_line', :kind => kind
    end

text_token(text, kind) click to toggle source

    # File lib/coderay/encoders/json.rb, line 60
    def text_token text, kind
      append :type => 'text', :text => text, :kind => kind
    end

### Protected Instance Methods

append(data) click to toggle source

    # File lib/coderay/encoders/json.rb, line 49
    def append data
      if @first
        @first = false
      else
        @out << ','
      end

      @out << data.to_json
    end

finish(options) click to toggle source

    # File lib/coderay/encoders/json.rb, line 45
    def finish options
      @out << ']'
    end

setup(options) click to toggle source

    # File lib/coderay/encoders/json.rb, line 38
    def setup options
      super

      @first = true
      @out << '['
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.