Class: HtmlToHaml::Html::IndentationTracker
- Inherits:
-
Object
- Object
- HtmlToHaml::Html::IndentationTracker
- Defined in:
- lib/html_to_haml/tools/html/indentation_tracker.rb
Instance Method Summary collapse
- #close_html_tag ⇒ Object
- #indentation ⇒ Object
-
#initialize(indentation_amount:) ⇒ IndentationTracker
constructor
A new instance of IndentationTracker.
- #start_html_tag ⇒ Object
- #start_self_closing_tag ⇒ Object
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_tag ⇒ Object
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 |
#indentation ⇒ Object
27 28 29 |
# File 'lib/html_to_haml/tools/html/indentation_tracker.rb', line 27 def indentation " " * @indentation_level end |
#start_html_tag ⇒ Object
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_tag ⇒ Object
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 |