Class: GithubPrivateUriIncludeProcessor

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

Instance Method Summary collapse

Instance Method Details

#handles?(target) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/asciidoctor-github-include.rb', line 7

def handles? target
  (target.start_with? 'https://raw.githubusercontent.com')
end

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



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

def process doc, reader, target, attributes
  begin
    doc.attr('github-access-token').nil? ? 
      content = (open target).readlines :
      content = (open target, "Authorization" => "token " + doc.attr('github-access-token')).readlines
  rescue
    warn %(asciidoctor: WARNING: Failed to retrieve GitHub URI #{target}. Did you set :github-access-token:?)
    content = "WARNING: Failed to retrieve GitHub URI link:#{target}[]"
  end
  reader.push_include content, target, target, 1, attributes
  reader
end