aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/extensions/revision_history_processor.rb
blob: f416de08a3db5ad4effca86ab1f6200ee606f524 (plain)
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
module Nuldoc
  module Extensions
    class RevisionHistoryProcessor < Asciidoctor::Extensions::TreeProcessor
      def process(doc)
        revisions = []
        i = 1
        loop do
          break unless (rev = doc.attributes["revision-#{i}"])
          revisions << parse_revision(rev)
          i += 1
        end
        doc.attributes['revision-history'] = revisions
      end

      private

      def parse_revision(rev)
        m = rev.match(/\A(\d\d\d\d-\d\d-\d\d) (.*)\z/)
        raise unless m
        Revision.new(
          date: Date.parse(m[1], '%Y-%m-%d'),
          remark: m[2],
        )
      end
    end
  end
end