mirror of
https://github.com/foo-dogsquared/website.git
synced 2025-01-31 07:58:02 +00:00
Update GitLab raw include processor
This apparently not accepted since I think what happens is the processing is taking place before whatever the class is initialized or isn't considered by the text processor.
This commit is contained in:
parent
524e0ffc49
commit
7d6f345122
@ -6,13 +6,11 @@ require 'open-uri'
|
|||||||
require 'uri'
|
require 'uri'
|
||||||
|
|
||||||
class GitLabRawIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
|
class GitLabRawIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
|
||||||
@prefix = 'gitlab:'
|
|
||||||
|
|
||||||
def handles?(target)
|
def handles?(target)
|
||||||
target.start_with? @prefix
|
target.start_with? 'gitlab:'
|
||||||
end
|
end
|
||||||
|
|
||||||
def warn_or_raise doc, warning
|
def warn_or_raise(doc, warning)
|
||||||
if (doc.safe > Asciidoctor::SafeMode::SERVER) && !(doc.attr? 'allow-uri-read')
|
if (doc.safe > Asciidoctor::SafeMode::SERVER) && !(doc.attr? 'allow-uri-read')
|
||||||
raise warning
|
raise warning
|
||||||
else
|
else
|
||||||
@ -21,7 +19,7 @@ class GitLabRawIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process(doc, reader, target, attrs)
|
def process(doc, reader, target, attrs)
|
||||||
src = target.delete_prefix(@prefix).split('/', 2)
|
src = target.delete_prefix('gitlab:').split('/', 2)
|
||||||
owner = src.at 0
|
owner = src.at 0
|
||||||
repo = src.at 1
|
repo = src.at 1
|
||||||
namespaced_repo = "#{owner}/#{repo}"
|
namespaced_repo = "#{owner}/#{repo}"
|
||||||
@ -55,15 +53,14 @@ class GitLabRawIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
|
|||||||
response = JSON.parse(f.read)
|
response = JSON.parse(f.read)
|
||||||
|
|
||||||
Base64.decode64 response['content'] if response['content'] && response['encoding'] == 'base64'
|
Base64.decode64 response['content'] if response['content'] && response['encoding'] == 'base64'
|
||||||
|
|
||||||
reader.push_include content, target, target, 1, attrs
|
|
||||||
end
|
end
|
||||||
rescue OpenURI::HTTPError => e
|
rescue OpenURI::HTTPError => e
|
||||||
warning = %(error while getting '#{path}' in GitLab repo '#{repo}': #{e})
|
warning = %(error while getting '#{path}' in GitLab repo '#{repo}': #{e})
|
||||||
warn_or_raise doc, warning
|
warn_or_raise doc, warning
|
||||||
reader.push_include warning, target, target, 1, attrs
|
warning
|
||||||
end
|
end
|
||||||
|
|
||||||
|
reader.push_include content, target, target, 1, attrs
|
||||||
reader
|
reader
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user