Class: Chiridion::Engine::ClassLinker
- Inherits:
-
Object
- Object
- Chiridion::Engine::ClassLinker
- Defined in:
- lib/chiridion/engine/class_linker.rb
Overview
Converts class/module references to Obsidian wikilinks.
Handles various reference formats:
-
Full paths: ‘Autopax::Foo::Bar` → `[[foo/bar|Bar]]`
-
YARD curly braces: ‘Extractor` → `[[extractor|Extractor]]`
-
Relative names: ‘Writer` → `[[writer|Writer]]` (within same namespace)
Instance Attribute Summary collapse
-
#known_classes ⇒ Hash<String, String>
readonly
Known classes mapped to doc paths.
-
#namespace_strip ⇒ String?
readonly
Namespace prefix to strip from paths.
Instance Method Summary collapse
-
#initialize(namespace_strip: nil) ⇒ ClassLinker
constructor
A new instance of ClassLinker.
-
#known?(class_name) ⇒ Boolean
Check if a class is a known documentable class.
-
#link(class_path, context: nil) ⇒ String
Convert a class path to a wikilink.
-
#linkify_docstring(text, context: nil) ⇒ String
Process a docstring, converting Class references to wikilinks.
-
#linkify_type(type_str, context: nil) ⇒ String
Convert a type annotation to include wikilinks where possible.
-
#register_classes(structure) ⇒ Object
Register known classes from the documentation structure.
- #skip_type?(class_ref) ⇒ Boolean
Constructor Details
#initialize(namespace_strip: nil) ⇒ ClassLinker
Returns a new instance of ClassLinker.
18 19 20 21 |
# File 'lib/chiridion/engine/class_linker.rb', line 18 def initialize(namespace_strip: nil) @namespace_strip = namespace_strip @known_classes = {} end |
Instance Attribute Details
#known_classes ⇒ Hash<String, String> (readonly)
Returns Known classes mapped to doc paths.
13 14 15 |
# File 'lib/chiridion/engine/class_linker.rb', line 13 def known_classes @known_classes end |
#namespace_strip ⇒ String? (readonly)
Returns Namespace prefix to strip from paths.
16 17 18 |
# File 'lib/chiridion/engine/class_linker.rb', line 16 def namespace_strip @namespace_strip end |
Instance Method Details
#known?(class_name) ⇒ Boolean
Check if a class is a known documentable class.
92 |
# File 'lib/chiridion/engine/class_linker.rb', line 92 def known?(class_name) = @known_classes.key?(class_name) |
#link(class_path, context: nil) ⇒ String
Convert a class path to a wikilink.
41 42 43 44 45 46 47 |
# File 'lib/chiridion/engine/class_linker.rb', line 41 def link(class_path, context: nil) display_name = class_path.split("::").last resolved = resolve(class_path, context: context) return display_name unless resolved "[[#{resolved}|#{display_name}]]" end |
#linkify_docstring(text, context: nil) ⇒ String
Process a docstring, converting Class references to wikilinks.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/chiridion/engine/class_linker.rb', line 54 def linkify_docstring(text, context: nil) return text if text.nil? || text.empty? result = text.dup # Convert YARD headings (= Title) to markdown headings # Direct 1:1 conversion; normalize_headers filter will adjust levels for context result.gsub!(/^(=+)\s+(.+)$/) do level = Regexp.last_match(1).length "#" * level + " " + Regexp.last_match(2) end # Convert {Class} references to wikilinks result.gsub(/\{([A-Z][\w:]*)\}/) do |_match| class_ref = Regexp.last_match(1) link(class_ref, context: context) end end |
#linkify_type(type_str, context: nil) ⇒ String
Convert a type annotation to include wikilinks where possible.
Returns formatted string with backticks around non-link parts. Wikilinks must be outside backticks to render properly.
81 82 83 84 85 86 |
# File 'lib/chiridion/engine/class_linker.rb', line 81 def linkify_type(type_str, context: nil) return "`Object`" if type_str.nil? || type_str.empty? segments = build_type_segments(type_str, context: context) format_type_segments(segments) end |
#register_classes(structure) ⇒ Object
Register known classes from the documentation structure.
26 27 28 29 30 31 32 33 34 |
# File 'lib/chiridion/engine/class_linker.rb', line 26 def register_classes(structure) (structure[:classes] + structure[:modules]).each do |obj| path = obj[:path] @known_classes[path] = doc_path(path) # Also register short name for relative lookups short_name = path.split("::").last @known_classes[short_name] ||= doc_path(path) end end |
#skip_type?(class_ref) ⇒ Boolean
98 |
# File 'lib/chiridion/engine/class_linker.rb', line 98 def skip_type?(class_ref) = SKIP_TYPES.include?(class_ref) |