13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/puppet-cleaner/workers/softtabs.rb', line 13
def operate(line)
case line.current.name
when :LBRACE, :LBRACK, :LPAREN
@depth += 1
when :RBRACE, :RBRACK, :RPAREN
@resource_tab[:size] = 0 if line.current.name == :RBRACE && @resource_tab[:depth] == @depth
@depth -= 1
when :SEMIC
@resource_tab[:size] = 0
@resource_tab[:depth] = nil
when :COLON
pos = line.position - 1
pos -= 1 while pos >= 0 && ![:LBRACE, :RETURN].include?(line.parts[pos].name)
return if pos < 0 || line.parts[pos].name != :RETURN
pos = line.position + 1
pos += 1 while pos < line.parts.size && [:BLANK, :RETURN].include?(line.parts[pos].name)
return if pos == line.parts.size || line.parts[pos].name == :LBRACE
@resource_tab[:size] = 1
@resource_tab[:depth] = @depth
when :RETURN
return if line.last? || line.next.name == :RETURN
line.append(line.position, Part.create([:BLANK, {:value => ''}])) if line.next.name != :BLANK
n = [:RBRACE, :RBRACK, :RPAREN].include?(line.next(2).name) ? 1 : 0
@resource_tab[:size] = 0 if line.next(2).name == :RBRACE && @resource_tab[:depth] == @depth
blanks = ' '*@tabstop*(@depth - n + @resource_tab[:size])
line.next.value = blanks if line.next.value != blanks
end
end
|