Module: Banalize::Parser::PodStyleComments

Included in:
Banalize::Parser
Defined in:
lib/banalize/parser/pod_comments.rb

Overview

Munin project uses documentation in the style of Perl’s POD. These comments are not detected by standard Bash parser. This mixin takes POD style comments from #code and put them in #comments

POD style comments are in the form:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~bash :<<“=cut”

head1 NAME

....
...

cut

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Instance Method Summary collapse

Instance Method Details

#pod_commentsObject

Parse bash here-doc comments in the POD style and move them to Banalize::Parser#comments



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/banalize/parser/pod_comments.rb', line 28

def pod_comments
  start = code.grep(/^:<<"?=cut"?\s*$/)
  cut   = code.grep(/^=cut\s*$/)
  
  raise "Started not the same number of POD blocks as ended: #{start.size} vs #{cut.size}" if
    start.size != cut.size
  
  start.each do |start_pod|

    start_pod = start_pod.first.to_i
    cut_pod   = cut.shift.first.to_i

    raise "Starting line of POD comment after ending line: #{start_pod} > #{cut_pod}" if 
      start_pod > cut_pod
    
    comments.add code.delete(code.slice(start_pod,cut_pod))
  end
end