Class: Asciidoctor::IncludeExt::IncludeProcessor
- Inherits:
-
Extensions::IncludeProcessor
- Object
- Extensions::IncludeProcessor
- Asciidoctor::IncludeExt::IncludeProcessor
- Defined in:
- lib/asciidoctor/include_ext/include_processor.rb
Overview
Asciidoctor preprocessor for processing `include::<target>[]` directives in the source document.
Instance Method Summary collapse
-
#initialize(selectors: [LinenoLinesSelector, TagLinesSelector], logger: Logging.default_logger) ⇒ IncludeProcessor
constructor
A new instance of IncludeProcessor.
- #process(_, reader, target, attributes) ⇒ Object
Constructor Details
#initialize(selectors: [LinenoLinesSelector, TagLinesSelector], logger: Logging.default_logger) ⇒ IncludeProcessor
Returns a new instance of IncludeProcessor.
26 27 28 29 30 31 |
# File 'lib/asciidoctor/include_ext/include_processor.rb', line 26 def initialize(selectors: [LinenoLinesSelector, TagLinesSelector], logger: Logging.default_logger, **) super @selectors = selectors.dup.freeze @logger = logger end |
Instance Method Details
#process(_, reader, target, attributes) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/asciidoctor/include_ext/include_processor.rb', line 38 def process(_, reader, target, attributes) unless include_allowed? target, reader reader.unshift_line("link:#{target}[]") return end if (max_depth = reader.exceeded_max_depth?) logger.error "#{reader.line_info}: maximum include depth of #{max_depth} exceeded" return end unless (path = resolve_target_path(target, reader)) if attributes.key? 'optional-option' reader.shift else logger.error "#{reader.line_info}: include target not found: #{target}" unresolved_include!(target, reader) end return end selector = lines_selector_for(target, attributes) begin lines = read_lines(path, selector) rescue => e # rubocop:disable RescueWithoutErrorClass logger.error "#{reader.line_info}: failed to read include file: #{path}: #{e}" unresolved_include!(target, reader) return end if selector && selector.respond_to?(:first_included_lineno) incl_offset = selector.first_included_lineno end unless lines.empty? reader.push_include(lines, path, target, incl_offset || 1, attributes) end end |