Class: GitIncludeMacro

Inherits:
Asciidoctor::Extensions::IncludeProcessor
  • Object
show all
Defined in:
lib/asciidoctor-git-include.rb

Instance Method Summary collapse

Instance Method Details

#handles?(target) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/asciidoctor-git-include.rb', line 8

def handles? target
  (target.start_with? 'git@')
end

#process(doc, reader, target, attributes) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/asciidoctor-git-include.rb', line 12

def process doc, reader, target, attributes
  target.slice! "git@"
  repository = attributes.fetch('repository', '.')
  revision = attributes.fetch('revision', 'HEAD')

  cmd = %(git -C #{repository} show #{revision}:#{target})
  content = %x(#{cmd})

  reader.push_include content, target, target, 1, attributes
  reader
end