Class: Chiridion::Engine::GithubLinker
- Inherits:
-
Object
- Object
- Chiridion::Engine::GithubLinker
- Defined in:
- lib/chiridion/engine/github_linker.rb
Overview
Generates GitHub source links from file paths and line numbers.
Parses git remote URL to extract org/repo, then constructs blob URLs with line references for linking documentation back to source.
Instance Attribute Summary collapse
-
#base_url ⇒ String?
readonly
GitHub base URL (e.g., “github.com/org/repo”).
-
#branch ⇒ String
readonly
Git branch for source links.
Instance Method Summary collapse
-
#initialize(repo: nil, branch: "main", root: Dir.pwd) ⇒ GithubLinker
constructor
A new instance of GithubLinker.
-
#link(path, start_line, end_line = nil) ⇒ String
Generate a markdown link to a source location on GitHub.
-
#url(path, start_line, end_line = nil) ⇒ String?
Generate just the URL (for frontmatter).
Constructor Details
#initialize(repo: nil, branch: "main", root: Dir.pwd) ⇒ GithubLinker
Returns a new instance of GithubLinker.
19 20 21 22 |
# File 'lib/chiridion/engine/github_linker.rb', line 19 def initialize(repo: nil, branch: "main", root: Dir.pwd) @branch = branch @base_url = repo ? "https://github.com/#{repo}" : extract_github_base_url(root) end |
Instance Attribute Details
#base_url ⇒ String? (readonly)
Returns GitHub base URL (e.g., “github.com/org/repo”).
11 12 13 |
# File 'lib/chiridion/engine/github_linker.rb', line 11 def base_url @base_url end |
#branch ⇒ String (readonly)
Returns Git branch for source links.
14 15 16 |
# File 'lib/chiridion/engine/github_linker.rb', line 14 def branch @branch end |
Instance Method Details
#link(path, start_line, end_line = nil) ⇒ String
Generate a markdown link to a source location on GitHub.
30 31 32 33 34 35 36 |
# File 'lib/chiridion/engine/github_linker.rb', line 30 def link(path, start_line, end_line = nil) text = format_text(path, start_line, end_line) return "`#{text}`" unless @base_url url = format_url(path, start_line, end_line) "[#{text}](#{url})" end |
#url(path, start_line, end_line = nil) ⇒ String?
Generate just the URL (for frontmatter).
44 45 46 47 48 |
# File 'lib/chiridion/engine/github_linker.rb', line 44 def url(path, start_line, end_line = nil) return nil unless @base_url format_url(path, start_line, end_line) end |