Class: HtmlToHaml::Html::IndentationTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/html_to_haml/tools/html/indentation_tracker.rb

Instance Method Summary collapse

Constructor Details

#initialize(indentation_amount:) ⇒ IndentationTracker

Returns a new instance of IndentationTracker.



5
6
7
8
9
# File 'lib/html_to_haml/tools/html/indentation_tracker.rb', line 5

def initialize(indentation_amount:)
  @indentation_level = 0
  @inside_self_closing_tag = false
  @indentation_amount = indentation_amount
end

Instance Method Details

#close_html_tagObject



20
21
22
23
24
25
# File 'lib/html_to_haml/tools/html/indentation_tracker.rb', line 20

def close_html_tag
  @indentation_level -= @indentation_amount
  if @indentation_level < 0
    raise ParseError, 'The html is malformed and is attempting to close an html tag that was never started'
  end
end

#indentationObject



27
28
29
# File 'lib/html_to_haml/tools/html/indentation_tracker.rb', line 27

def indentation
  " " * @indentation_level
end

#start_html_tagObject



11
12
13
14
# File 'lib/html_to_haml/tools/html/indentation_tracker.rb', line 11

def start_html_tag
  @indentation_level += @indentation_amount unless @inside_self_closing_tag
  @inside_self_closing_tag = false
end

#start_self_closing_tagObject



16
17
18
# File 'lib/html_to_haml/tools/html/indentation_tracker.rb', line 16

def start_self_closing_tag
  @inside_self_closing_tag = true
end