Class: CodeRay::Encoders::JSON
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/lib/coderay/encoders/json.rb
Overview
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"},
]
Constant Summary collapse
- FILE_EXTENSION =
'json'
Constants inherited from Encoder
Instance Attribute Summary
Attributes inherited from Encoder
Attributes included from Plugin
Instance Method Summary collapse
- #begin_group(kind) ⇒ Object
- #begin_line(kind) ⇒ Object
- #end_group(kind) ⇒ Object
- #end_line(kind) ⇒ Object
- #text_token(text, kind) ⇒ Object
Methods inherited from Encoder
#<<, const_missing, #encode, #encode_tokens, file_extension, #file_extension, #initialize, #token
Methods included from Plugin
#aliases, #plugin_host, #register_for, #title
Constructor Details
This class inherits a constructor from CodeRay::Encoders::Encoder
Instance Method Details
#begin_group(kind) ⇒ Object
64 65 66 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/lib/coderay/encoders/json.rb', line 64 def begin_group kind append :type => 'block', :action => 'open', :kind => kind end |
#begin_line(kind) ⇒ Object
72 73 74 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/lib/coderay/encoders/json.rb', line 72 def begin_line kind append :type => 'block', :action => 'begin_line', :kind => kind end |
#end_group(kind) ⇒ Object
68 69 70 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/lib/coderay/encoders/json.rb', line 68 def end_group kind append :type => 'block', :action => 'close', :kind => kind end |
#end_line(kind) ⇒ Object
76 77 78 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/lib/coderay/encoders/json.rb', line 76 def end_line kind append :type => 'block', :action => 'end_line', :kind => kind end |
#text_token(text, kind) ⇒ Object
60 61 62 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/lib/coderay/encoders/json.rb', line 60 def text_token text, kind append :type => 'text', :text => text, :kind => kind end |