Class: RailsRouteChecker::Parsers::HamlParser::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-route-checker/parsers/haml_parser/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Document

Returns a new instance of Document.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rails-route-checker/parsers/haml_parser/document.rb', line 9

def initialize(source)
  @source = source.force_encoding(Encoding::UTF_8)
  @source_lines = @source.split(/\r\n|\r|\n/)

  version = Gem::Version.new(Haml::VERSION).approximate_recommendation

  original_tree = case version
                  when '~> 4.0', '~> 4.1'
                    options = Haml::Options.new
                    Haml::Parser.new(@source, options).parse
                  when '~> 5.0', '~> 5.1', '~> 5.2'
                    options = Haml::Options.new
                    Haml::Parser.new(options).call(@source)
                  when '~> 6.0', '~> 6.1', '~> 6.2', '~> 6.3'
                    Haml::Parser.new({}).call(@source)
                  else
                    raise "Cannot handle Haml version: #{version}"
                  end

  @tree = process_tree(original_tree)
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/rails-route-checker/parsers/haml_parser/document.rb', line 7

def source
  @source
end

#source_linesObject (readonly)

Returns the value of attribute source_lines.



7
8
9
# File 'lib/rails-route-checker/parsers/haml_parser/document.rb', line 7

def source_lines
  @source_lines
end

#treeObject (readonly)

Returns the value of attribute tree.



7
8
9
# File 'lib/rails-route-checker/parsers/haml_parser/document.rb', line 7

def tree
  @tree
end