Class: FastHaml::IndentTracker
- Inherits:
-
Object
- Object
- FastHaml::IndentTracker
- Defined in:
- lib/fast_haml/indent_tracker.rb
Defined Under Namespace
Classes: IndentMismatch
Instance Method Summary collapse
- #current_level ⇒ Object
- #enter_comment! ⇒ Object
- #finish ⇒ Object
-
#initialize(on_enter: nil, on_leave: nil) ⇒ IndentTracker
constructor
A new instance of IndentTracker.
- #process(line, lineno) ⇒ Object
- #split(line) ⇒ Object
Constructor Details
#initialize(on_enter: nil, on_leave: nil) ⇒ IndentTracker
Returns a new instance of IndentTracker.
12 13 14 15 16 17 |
# File 'lib/fast_haml/indent_tracker.rb', line 12 def initialize(on_enter: nil, on_leave: nil) @indent_levels = [0] @on_enter = on_enter || lambda { |level, text| } @on_leave = on_leave || lambda { |level, text| } @comment_level = nil end |
Instance Method Details
#current_level ⇒ Object
38 39 40 |
# File 'lib/fast_haml/indent_tracker.rb', line 38 def current_level @indent_levels.last end |
#enter_comment! ⇒ Object
42 43 44 |
# File 'lib/fast_haml/indent_tracker.rb', line 42 def enter_comment! @comment_level = @indent_levels[-2] end |
#finish ⇒ Object
34 35 36 |
# File 'lib/fast_haml/indent_tracker.rb', line 34 def finish indent_leave(0, '', -1) end |
#process(line, lineno) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/fast_haml/indent_tracker.rb', line 19 def process(line, lineno) indent, text = split(line) indent_level = indent.size unless text.empty? track(indent_level, text, lineno) end [text, indent] end |
#split(line) ⇒ Object
29 30 31 32 |
# File 'lib/fast_haml/indent_tracker.rb', line 29 def split(line) m = line.match(/\A( *)(.*)\z/) [m[1], m[2]] end |