class GithubPrivateUriIncludeProcessor
Public Instance Methods
handles?(target)
click to toggle source
# File lib/asciidoctor-github-include.rb, line 7 def handles? target (target.start_with? 'https://raw.githubusercontent.com') end
process(doc, reader, target, attributes)
click to toggle source
# File lib/asciidoctor-github-include.rb, line 11 def process doc, reader, target, attributes tags = [attributes["tag"]] if attributes.key? "tag" unless attributes["tag"] == "" tags = attributes["tags"].split(DataDelimiterRx) if attributes.key? "tags" unless attributes["tags"] == "" lines = attributes["lines"] unless attributes["lines"] == "" if lines && tags warn %(asciidoctor: WARNING: Tag selection #{tags} in #{target} was ignored because line selection was specified.) end # Fetch the file to be included 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}[]" return reader.push_include content, target, target, 1, attributes end # process the lines and tags attributes content = process_line_selection(content, lines, target) if lines content = process_tags(content, tags, target) if tags unless lines # push the lines onto the reader and return it reader.push_include content, target, target, 1, attributes reader end
process_line_selection(text, lines, target)
click to toggle source
# File lib/asciidoctor-github-include.rb, line 79 def process_line_selection text, lines, target snipped_content = [] selected_lines = [] lines.split(DataDelimiterRx).each do |linedef| if linedef.include?('..') from, to = linedef.split('..', 2).map {|it| it.to_i } to = text.length if to == -1 # -1 as a closing length means end of file selected_lines.concat ::Range.new(from, to).to_a else selected_lines << linedef.to_i end end selected_lines.sort.uniq.each do |i| snipped_content << text[i-1] end snipped_content end