summaryrefslogtreecommitdiff
path: root/config/quiet-include-failure.rb
blob: cd238ede22570aada70094652609c441f6489b6c (plain)
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
26
27
28
29
30
# Copyright 2021-2023 The Khronos Group Inc.
#
# SPDX-License-Identifier: Apache-2.0

require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'

include Asciidoctor

class ExistsIncludeProcessor < Extensions::IncludeProcessor
  def handles? target
    # Only handle files which do not exist
    # This relies on the full absolute path to every include file being
    # given, since relative directory information exists only in the
    # process method.

    not File.exist? target
  end

  def process doc, reader, target, attributes
    # If we reach this point, we have been asked to include a file which
    # does not exist. Do nothing, instead of raising an error.

    reader
  end
end

Extensions.register do
  include_processor ExistsIncludeProcessor
end