Module: RDoc::Generator::Markdown::Paths
- Included in:
- RDoc::Generator::Markdown
- Defined in:
- lib/rdoc/generator/markdown/paths.rb
Overview
Resolves source and generated documentation paths.
Class Method Summary collapse
-
.normalize_input_path(path, source_dir) ⇒ String
Normalizes an input path against an explicit source directory.
-
.resolve_output_path_from(path, current_dir, state) ⇒ String?
Resolves a link against explicit generated-path state.
-
.rewrite_internal_links(markdown, current_output_path, state) ⇒ String
Rewrites links using explicit generated-path state.
Class Method Details
.normalize_input_path(path, source_dir) ⇒ String
Normalizes an input path against an explicit source directory.
110 111 112 113 114 115 116 117 |
# File 'lib/rdoc/generator/markdown/paths.rb', line 110 def self.normalize_input_path(path, source_dir) normalized = path.tr("\\", "/").sub(%r{\A\./}, "") normalized = normalized.sub(%r{\A#{Regexp.escape(source_dir)}/}, "") normalized = normalized.sub(%r{\A/}, "") root_basename = File.basename(source_dir) normalized.sub(%r{\A#{Regexp.escape(root_basename)}/}, "") end |
.resolve_output_path_from(path, current_dir, state) ⇒ String?
Resolves a link against explicit generated-path state.
85 86 87 88 89 90 91 |
# File 'lib/rdoc/generator/markdown/paths.rb', line 85 def self.resolve_output_path_from(path, current_dir, state) candidates = [path, path.delete_prefix("#{state.root_path_segment}/")] candidates += candidates.map { |candidate| candidate.sub(/_(md|markdown)\.md\z/i, '.\1') } = candidates.map { |candidate| current_dir.join(candidate).cleanpath.to_s } (candidates + ).find { |candidate| state.known_output_paths.include?(candidate) } end |
.rewrite_internal_links(markdown, current_output_path, state) ⇒ String
Rewrites links using explicit generated-path state.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rdoc/generator/markdown/paths.rb', line 64 def self.rewrite_internal_links(markdown, current_output_path, state) current_dir = Pathname.new(current_output_path).dirname markdown.gsub(%r{\]\(([^)]+)\)}) do target = Regexp.last_match(1) path = target.sub(/[?#].*\z/, "") suffix = target[path.length..] resolved = resolve_output_path_from(path, current_dir, state) rewritten = resolved ? Pathname.new(resolved).relative_path_from(current_dir) : path "](#{rewritten}#{suffix})" end end |