class HtmlToHaml::Erb::IndentationTracker

Attributes

case_statement_level[R]
indentation_amount[R]
indentation_level[RW]

Public Class Methods

new(indentation_level:, indentation_amount:) click to toggle source
# File lib/html_to_haml/tools/erb/indentation_tracker.rb, line 6
def initialize(indentation_level:, indentation_amount:)
  @indentation_level = indentation_level
  @indentation_amount = indentation_amount
  @case_statement_level = []
end

Public Instance Methods

add_indentation() click to toggle source
# File lib/html_to_haml/tools/erb/indentation_tracker.rb, line 17
def add_indentation
  self.indentation_level += indentation_amount
end
begin_case_statement() click to toggle source
# File lib/html_to_haml/tools/erb/indentation_tracker.rb, line 12
def begin_case_statement
  self.indentation_level += indentation_amount * 2
  case_statement_level << indentation_level
end
end_block() click to toggle source
# File lib/html_to_haml/tools/erb/indentation_tracker.rb, line 21
def end_block
  if indentation_level == @case_statement_level.last
    case_statement_level.pop
    self.indentation_level -= indentation_amount * 2
  else
    self.indentation_level -= indentation_amount
  end
end
nested_case_statement?() click to toggle source

I may allow people to use this for nested case statements, but reserve the right to be snarky about it when they do.

# File lib/html_to_haml/tools/erb/indentation_tracker.rb, line 32
def nested_case_statement?
  case_statement_level.length > 1
end