Class: RubyJard::Decorators::LocDecorator

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

Overview

Decorate a line of code fetched from the source file. The line is tokenized, and feed into JardEncoder to append color (with Span).

Defined Under Namespace

Classes: JardLocEncoder

Instance Method Summary collapse

Constructor Details

#initializeLocDecorator

Returns a new instance of LocDecorator.



12
13
14
# File 'lib/ruby_jard/decorators/loc_decorator.rb', line 12

def initialize
  @encoder = JardLocEncoder.new
end

Instance Method Details

#decorate(loc, file = nil) ⇒ Object



16
17
18
19
20
# File 'lib/ruby_jard/decorators/loc_decorator.rb', line 16

def decorate(loc, file = nil)
  tokens = CodeRay.scan(loc, extension(file))
  spans = @encoder.encode_tokens(tokens)
  [spans, tokens]
end