aboutsummaryrefslogtreecommitdiff
path: root/shared/lib/GitReferencesMacro/extension.rb
blob: 40dcbed1fd3dcda52b8cd445edf1b30548355ca1 (plain) (blame)
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
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'

include ::Asciidoctor

class GitReferencesMacro < Asciidoctor::Extensions::InlineMacroProcessor
  use_dsl

  named :gitref

  def process parent, target, attrs
    hash = target
    repository = if (repository = attrs['repository'])
      "#{repository}"
    else
      "src"
    end
    length = if (length = attrs['length'])
      length.to_i
    else
      12
    end
    url = %(https://cgit.freebsd.org/#{repository}/commit/?id=#{hash})
    %(<a href="#{url}">#{hash[0, length]}</a>)
  end
end