Class: ERBLint::ProcessedSource

Inherits:
Object
  • Object
show all
Defined in:
lib/erb_lint/processed_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, file_content) ⇒ ProcessedSource

Returns a new instance of ProcessedSource.



7
8
9
10
11
# File 'lib/erb_lint/processed_source.rb', line 7

def initialize(filename, file_content)
  @filename = filename
  @file_content = file_content
  @parser = BetterHtml::Parser.new(source_buffer, template_language: :html)
end

Instance Attribute Details

#file_contentObject (readonly)

Returns the value of attribute file_content.



5
6
7
# File 'lib/erb_lint/processed_source.rb', line 5

def file_content
  @file_content
end

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/erb_lint/processed_source.rb', line 5

def filename
  @filename
end

#parserObject (readonly)

Returns the value of attribute parser.



5
6
7
# File 'lib/erb_lint/processed_source.rb', line 5

def parser
  @parser
end

Instance Method Details

#astObject



13
14
15
# File 'lib/erb_lint/processed_source.rb', line 13

def ast
  @parser.ast
end

#source_bufferObject



17
18
19
20
21
22
23
# File 'lib/erb_lint/processed_source.rb', line 17

def source_buffer
  @source_buffer ||= begin
    buffer = Parser::Source::Buffer.new(filename)
    buffer.source = file_content
    buffer
  end
end

#to_source_range(range) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/erb_lint/processed_source.rb', line 25

def to_source_range(range)
  range = (range.begin_pos...range.end_pos) if range.is_a?(::Parser::Source::Range)
  BetterHtml::Tokenizer::Location.new(
    source_buffer,
    range.begin,
    range.exclude_end? ? range.end : range.end + 1
  )
end