File: indentation.rb

package info (click to toggle)
ruby-mab 0.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 272 kB
  • sloc: ruby: 740; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 629 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module Mab
  module Indentation
     def mab_insert(str)
      if i = @mab_context.options[:indentation]
        super([$/ + "  " * i, str])
      else
        @mab_context.options[:indentation] = 0
        super
      end
    end

    def mab_done(tag)
      if blk = tag._block
        tag._block = proc do
          begin
            @mab_context.options[:indentation] += 1
            blk.call
          ensure
            @mab_context.options[:indentation] -= 1
          end
        end
      end
      super
    end

    def reindent!(str)
      str.split(/\r?\n/).each do |s|
        text! s
      end
    end
  end
end