Class: HamlLint::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/haml_lint/document.rb

Overview

Represents a parsed Haml document and its associated metadata.

Constant Summary collapse

STRING_SOURCE =

File name given to source code parsed from just a string.

'(string)'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options) ⇒ Document

Parses the specified Haml code into a HamlLint::Document.

Parameters:

  • source (String)

    Haml code to parse

  • options (Hash)

Options Hash (options):

  • :file (String)

    file name of document that was parsed

Raises:

  • (Haml::Parser::Error)

    if there was a problem parsing the document



32
33
34
35
36
37
# File 'lib/haml_lint/document.rb', line 32

def initialize(source, options)
  @config = options[:config]
  @file = options.fetch(:file, STRING_SOURCE)

  process_source(source)
end

Instance Attribute Details

#configHamlLint::Configuration (readonly)

Returns Configuration used to parse template.

Returns:



12
13
14
# File 'lib/haml_lint/document.rb', line 12

def config
  @config
end

#fileString (readonly)

Returns Haml template file path.

Returns:

  • (String)

    Haml template file path



15
16
17
# File 'lib/haml_lint/document.rb', line 15

def file
  @file
end

#sourceString (readonly)

Returns original source code.

Returns:

  • (String)

    original source code



21
22
23
# File 'lib/haml_lint/document.rb', line 21

def source
  @source
end

#source_linesArray<String> (readonly)

Returns original source code as an array of lines.

Returns:

  • (Array<String>)

    original source code as an array of lines



24
25
26
# File 'lib/haml_lint/document.rb', line 24

def source_lines
  @source_lines
end

#treeHamlLint::Tree::Node (readonly)

Returns Root of the parse tree.

Returns:



18
19
20
# File 'lib/haml_lint/document.rb', line 18

def tree
  @tree
end