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"}, ]
# File lib/coderay/encoders/json.rb, line 64 def begin_group kind append :type => 'block', :action => 'open', :kind => kind end
# File lib/coderay/encoders/json.rb, line 72 def begin_line kind append :type => 'block', :action => 'begin_line', :kind => kind end
# File lib/coderay/encoders/json.rb, line 68 def end_group kind append :type => 'block', :action => 'close', :kind => kind end
# File lib/coderay/encoders/json.rb, line 76 def end_line kind append :type => 'block', :action => 'end_line', :kind => kind end
# File lib/coderay/encoders/json.rb, line 60 def text_token text, kind append :type => 'text', :text => text, :kind => kind end
# File lib/coderay/encoders/json.rb, line 49 def append data if @first @first = false else @out << ',' end @out << data.to_json end
# File lib/coderay/encoders/json.rb, line 45 def finish options @out << ']' end
# File lib/coderay/encoders/json.rb, line 38 def setup options super @first = true @out << '[' end