Class: Coradoc::ResolveIncludes

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/resolve_includes.rb

Overview

Flat-mode include processor — the explicit “flatten” step.

Walks a parsed CoreModel and expands every CoreModel::Include link node into the parsed content of its target, recursing into the result. The original CoreModel is NOT modified — a new subtree is constructed and spliced into place.

Invoked via the public API Coradoc.resolve_includes(doc, base_dir:). Callers control resolution strategy (filesystem, HTTP, custom), missing-include policy, recursion depth, and path-traversal safety.

Honors:

- +missing_include+ policy: :error (default) | :warn | :silent | :passthrough
- +max_depth+ limit (raises Coradoc::IncludeDepthExceededError)
- circular detection (raises Coradoc::CircularIncludeError)
- tags/lines/indent selectors (applied to raw text before parse)
- leveloffset selector (applied to parsed CoreModel)
- +base_dir+ re-rooting (recursive includes resolve relative to
  the including file — SPEC 7.2)

Constant Summary collapse

DEFAULT_MAX_DEPTH =
64

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resolver:, base_dir:, missing_include: :error, max_depth: DEFAULT_MAX_DEPTH, parse_format: :asciidoc) ⇒ ResolveIncludes

Returns a new instance of ResolveIncludes.

Parameters:

  • resolver (#call)

    anything responding to #call(target:, base_dir:, options:, context:)

  • base_dir (String)

    absolute path to the document root directory

  • missing_include (Symbol) (defaults to: :error)

    :error | :warn | :silent | :passthrough

  • max_depth (Integer) (defaults to: DEFAULT_MAX_DEPTH)

    recursion cap

  • parse_format (Symbol) (defaults to: :asciidoc)

    format to use when re-parsing included content



37
38
39
40
41
42
43
44
45
46
# File 'lib/coradoc/resolve_includes.rb', line 37

def initialize(resolver:, base_dir:,
               missing_include: :error,
               max_depth: DEFAULT_MAX_DEPTH,
               parse_format: :asciidoc)
  @resolver = Coradoc::IncludeResolver.coerce(resolver, base_dir: base_dir)
  @base_dir = base_dir
  @missing_policy = missing_include
  @max_depth = max_depth
  @parse_format = parse_format
end

Class Method Details

.call(core, resolver:, base_dir:, **opts) ⇒ Object



27
28
29
# File 'lib/coradoc/resolve_includes.rb', line 27

def call(core, resolver:, base_dir:, **opts)
  new(resolver: resolver, base_dir: base_dir, **opts).call(core)
end

Instance Method Details

#call(core) ⇒ Object

Walk + transform. Returns a NEW CoreModel with includes expanded.



49
50
51
# File 'lib/coradoc/resolve_includes.rb', line 49

def call(core)
  expand_node(core, base_dir: File.expand_path(@base_dir), chain: [], depth: 0)
end