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)'.freeze

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



30
31
32
33
34
35
# File 'lib/haml_lint/document.rb', line 30

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:



10
11
12
# File 'lib/haml_lint/document.rb', line 10

def config
  @config
end

#fileString (readonly)

Returns Haml template file path.

Returns:

  • (String)

    Haml template file path



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

def file
  @file
end

#sourceString (readonly)

Returns original source code.

Returns:

  • (String)

    original source code



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

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



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

def source_lines
  @source_lines
end

#treeHamlLint::Tree::Node (readonly)

Returns Root of the parse tree.

Returns:



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

def tree
  @tree
end