Module: Rouge::Indentation

Included in:
Lexers::Haml, Lexers::Sass
Defined in:
lib/rouge/util.rb

Overview

shared methods for some indentation-sensitive lexers

Instance Method Summary collapse

Instance Method Details

#indentation(indent_str) ⇒ Object

handle a single indented line



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rouge/util.rb', line 80

def indentation(indent_str)
  debug { "    indentation #{indent_str.inspect}" }
  debug { "    block_indentation: #{@block_indentation.inspect}" }
  @last_indentation = indent_str

  # if it's an indent and we know where to go next,
  # push that state.  otherwise, push content and
  # clear the block state.
  if (@block_state &&
      indent_str.start_with?(@block_indentation) &&
      indent_str != @block_indentation
  )
    push @block_state
  else
    @block_state = @block_indentation = nil
    push :content
  end
end

#reset!Object



66
67
68
69
# File 'lib/rouge/util.rb', line 66

def reset!
  super
  @block_state = @block_indentation = nil
end

#starts_block(block_state) ⇒ Object

push a state for the next indented block



72
73
74
75
76
77
# File 'lib/rouge/util.rb', line 72

def starts_block(block_state)
  @block_state = block_state
  @block_indentation = @last_indentation || ''
  debug { "    starts_block #{block_state.inspect}" }
  debug { "    block_indentation: #{@block_indentation.inspect}" }
end