Class: RubyJard::Decorators::LocDecorator::JardLocEncoder

Inherits:
CodeRay::Encoders::Encoder
  • Object
show all
Defined in:
lib/ruby_jard/decorators/loc_decorator.rb

Overview

Constant Summary collapse

DEFAULT_STYLE =
:normal_token
TOKEN_STYLES =
{
  annotation: :keyword,
  attribute_name: :keyword,
  attribute_value: :keyword,
  binary: {
    self: :keyword,
    char: :keyword,
    delimiter: :keyword
  },
  char: {
    self: :keyword,
    delimiter: :keyword
  },
  class: :constant,
  class_variable: :constant,
  color: :constant,
  comment: {
    self: :comment,
    char: :comment,
    delimiter: :comment
  },
  constant: :constant,
  decorator: :keyword,
  definition: :keyword,
  directive: :keyword,
  docstring: :keyword,
  doctype: :keyword,
  done: :keyword,
  entity: :keyword,
  error: :constant,
  exception: :keyword,
  float: :literal,
  function: :constant,
  method: :method,
  global_variable: :constant,
  hex: :keyword,
  id: :keyword,
  include: :keyword,
  integer: :literal,
  imaginary: :keyword,
  important: :keyword,
  key: {
    self: :literal,
    char: :literal,
    delimiter: :literal
  },
  label: :literal,
  local_variable: :keyword,
  namespace: :keyword,
  octal: :keyword,
  predefined: :keyword,
  predefined_constant: :keyword,
  predefined_type: :constant,
  preprocessor: :keyword,
  pseudo_class: :keyword,
  regexp: {
    self: :keyword,
    delimiter: :keyword,
    modifier: :keyword,
    char: :keyword
  },
  reserved: :keyword,
  keyword: :keyword,
  shell: {
    self: :keyword,
    char: :keyword,
    delimiter: :keyword,
    escape: :keyword
  },
  string: {
    self: :string,
    modifier: :string,
    char: :string,
    delimiter: :string,
    escape: :string,
    content: :string
  },
  symbol: {
    self: :literal,
    delimiter: :literal
  },
  tag: :constant,
  type: :keyword,
  value: :keyword,
  variable: :keyword,
  instance_variable: :instance_variable
}.freeze

Instance Method Summary collapse

Instance Method Details

#begin_group(kind) ⇒ Object Also known as: begin_line



155
156
157
158
# File 'lib/ruby_jard/decorators/loc_decorator.rb', line 155

def begin_group(kind)
  @opened << kind
  open_token(kind)
end

#end_group(_kind) ⇒ Object



161
162
163
164
165
# File 'lib/ruby_jard/decorators/loc_decorator.rb', line 161

def end_group(_kind)
  return unless @opened.pop

  @color_scopes.pop
end

#end_line(kind) ⇒ Object



167
168
169
# File 'lib/ruby_jard/decorators/loc_decorator.rb', line 167

def end_line(kind)
  end_group(kind)
end

#text_token(text, kind) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/ruby_jard/decorators/loc_decorator.rb', line 137

def text_token(text, kind)
  color = @color_scopes.last[kind]
  text.gsub!("\n", '')
  style =
    if !color
      DEFAULT_STYLE
    elsif color.is_a? Hash
      color[:self]
    else
      color
    end
  @out << Span.new(
    content: text,
    content_length: text.length,
    styles: style.to_sym
  )
end