Class: Coradoc::AsciiDoc::Model::IncludeResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/asciidoc/model/resolver.rb

Overview

Resolves include directives by parsing and including file contents.

Instance Method Summary collapse

Instance Method Details

#resolve(include_node, base_dir) ⇒ Array<Base>, Include

Resolve an include directive.

Parameters:

  • include_node (Include)

    the include directive

  • base_dir (String)

    base directory for relative paths

Returns:

  • (Array<Base>, Include)

    the included content or original node if not found



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/coradoc/asciidoc/model/resolver.rb', line 180

def resolve(include_node, base_dir)
  path = include_node.reference_path
  full_path = File.expand_path(path, base_dir)

  unless File.exist?(full_path)
    warn "[Coradoc] Warning: Include file not found: #{path}"
    return [include_node]
  end

  content = File.read(full_path)

  # Apply include options (lines, tags, etc.)
  content = apply_include_options(content, include_node.reference_options)

  # Parse the included content
  included_doc = Coradoc::AsciiDoc.parse(content)

  # Return the sections from the included document
  included_doc.sections || []
end