ratatui_ruby 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/ratatui_ruby/Cargo.lock +1 -1
- data/ext/ratatui_ruby/Cargo.toml +1 -1
- data/lib/ratatui_ruby/version.rb +1 -1
- metadata +1 -255
- data/.builds/ruby-3.2.yml +0 -54
- data/.builds/ruby-3.3.yml +0 -54
- data/.builds/ruby-3.4.yml +0 -54
- data/.builds/ruby-4.0.0.yml +0 -54
- data/.pre-commit-config.yaml +0 -16
- data/.rubocop.yml +0 -10
- data/AGENTS.md +0 -147
- data/CHANGELOG.md +0 -736
- data/README.md +0 -187
- data/README.rdoc +0 -302
- data/Rakefile +0 -11
- data/Steepfile +0 -50
- data/doc/concepts/application_architecture.md +0 -321
- data/doc/concepts/application_testing.md +0 -193
- data/doc/concepts/async.md +0 -190
- data/doc/concepts/custom_widgets.md +0 -247
- data/doc/concepts/debugging.md +0 -401
- data/doc/concepts/event_handling.md +0 -162
- data/doc/concepts/interactive_design.md +0 -146
- data/doc/contributors/auditing/parity.md +0 -239
- data/doc/contributors/design/ruby_frontend.md +0 -448
- data/doc/contributors/design/rust_backend.md +0 -434
- data/doc/contributors/design.md +0 -11
- data/doc/contributors/developing_examples.md +0 -400
- data/doc/contributors/documentation_style.md +0 -121
- data/doc/contributors/index.md +0 -21
- data/doc/contributors/releasing.md +0 -215
- data/doc/contributors/todo/align/api_completeness_audit-finished.md +0 -381
- data/doc/contributors/todo/align/api_completeness_audit-unfinished.md +0 -200
- data/doc/contributors/todo/align/term.md +0 -351
- data/doc/contributors/todo/align/terminal.md +0 -647
- data/doc/contributors/todo/future_work.md +0 -169
- data/doc/contributors/upstream_requests/paragraph_span_rects.md +0 -259
- data/doc/contributors/upstream_requests/tab_rects.md +0 -173
- data/doc/contributors/upstream_requests/title_rects.md +0 -132
- data/doc/custom.css +0 -22
- data/doc/getting_started/quickstart.md +0 -291
- data/doc/getting_started/why.md +0 -93
- data/doc/images/app_all_events.png +0 -0
- data/doc/images/app_cli_rich_moments.gif +0 -0
- data/doc/images/app_color_picker.png +0 -0
- data/doc/images/app_debugging_showcase.gif +0 -0
- data/doc/images/app_debugging_showcase.png +0 -0
- data/doc/images/app_external_editor.gif +0 -0
- data/doc/images/app_login_form.png +0 -0
- data/doc/images/app_stateful_interaction.png +0 -0
- data/doc/images/verify_quickstart_dsl.png +0 -0
- data/doc/images/verify_quickstart_layout.png +0 -0
- data/doc/images/verify_quickstart_lifecycle.png +0 -0
- data/doc/images/verify_readme_usage.png +0 -0
- data/doc/images/widget_barchart.png +0 -0
- data/doc/images/widget_block.png +0 -0
- data/doc/images/widget_box.png +0 -0
- data/doc/images/widget_calendar.png +0 -0
- data/doc/images/widget_canvas.png +0 -0
- data/doc/images/widget_cell.png +0 -0
- data/doc/images/widget_center.png +0 -0
- data/doc/images/widget_chart.png +0 -0
- data/doc/images/widget_gauge.png +0 -0
- data/doc/images/widget_layout_split.png +0 -0
- data/doc/images/widget_line_gauge.png +0 -0
- data/doc/images/widget_list.png +0 -0
- data/doc/images/widget_map.png +0 -0
- data/doc/images/widget_overlay.png +0 -0
- data/doc/images/widget_popup.png +0 -0
- data/doc/images/widget_ratatui_logo.png +0 -0
- data/doc/images/widget_ratatui_mascot.png +0 -0
- data/doc/images/widget_rect.png +0 -0
- data/doc/images/widget_render.png +0 -0
- data/doc/images/widget_rich_text.png +0 -0
- data/doc/images/widget_scroll_text.png +0 -0
- data/doc/images/widget_scrollbar.png +0 -0
- data/doc/images/widget_sparkline.png +0 -0
- data/doc/images/widget_style_colors.png +0 -0
- data/doc/images/widget_table.png +0 -0
- data/doc/images/widget_tabs.png +0 -0
- data/doc/images/widget_text_width.png +0 -0
- data/doc/index.md +0 -34
- data/doc/troubleshooting/async.md +0 -4
- data/doc/troubleshooting/terminal_limitations.md +0 -131
- data/doc/troubleshooting/tui_output.md +0 -197
- data/examples/app_all_events/README.md +0 -114
- data/examples/app_all_events/app.rb +0 -98
- data/examples/app_all_events/model/app_model.rb +0 -159
- data/examples/app_all_events/model/event_color_cycle.rb +0 -43
- data/examples/app_all_events/model/event_entry.rb +0 -94
- data/examples/app_all_events/model/msg.rb +0 -39
- data/examples/app_all_events/model/timestamp.rb +0 -56
- data/examples/app_all_events/update.rb +0 -75
- data/examples/app_all_events/view/app_view.rb +0 -80
- data/examples/app_all_events/view/controls_view.rb +0 -54
- data/examples/app_all_events/view/counts_view.rb +0 -61
- data/examples/app_all_events/view/live_view.rb +0 -72
- data/examples/app_all_events/view/log_view.rb +0 -57
- data/examples/app_all_events/view.rb +0 -9
- data/examples/app_cli_rich_moments/README.md +0 -81
- data/examples/app_cli_rich_moments/app.rb +0 -189
- data/examples/app_color_picker/README.md +0 -156
- data/examples/app_color_picker/app.rb +0 -76
- data/examples/app_color_picker/clipboard.rb +0 -86
- data/examples/app_color_picker/color.rb +0 -193
- data/examples/app_color_picker/controls.rb +0 -92
- data/examples/app_color_picker/copy_dialog.rb +0 -168
- data/examples/app_color_picker/export_pane.rb +0 -128
- data/examples/app_color_picker/harmony.rb +0 -58
- data/examples/app_color_picker/input.rb +0 -176
- data/examples/app_color_picker/main_container.rb +0 -180
- data/examples/app_color_picker/palette.rb +0 -111
- data/examples/app_debugging_showcase/README.md +0 -119
- data/examples/app_debugging_showcase/app.rb +0 -318
- data/examples/app_external_editor/README.md +0 -62
- data/examples/app_external_editor/app.rb +0 -344
- data/examples/app_login_form/README.md +0 -58
- data/examples/app_login_form/app.rb +0 -109
- data/examples/app_stateful_interaction/README.md +0 -35
- data/examples/app_stateful_interaction/app.rb +0 -328
- data/examples/timeout_demo.rb +0 -45
- data/examples/verify_quickstart_dsl/README.md +0 -55
- data/examples/verify_quickstart_dsl/app.rb +0 -49
- data/examples/verify_quickstart_layout/README.md +0 -77
- data/examples/verify_quickstart_layout/app.rb +0 -73
- data/examples/verify_quickstart_lifecycle/README.md +0 -68
- data/examples/verify_quickstart_lifecycle/app.rb +0 -62
- data/examples/verify_readme_usage/README.md +0 -49
- data/examples/verify_readme_usage/app.rb +0 -42
- data/examples/verify_website_managed/README.md +0 -48
- data/examples/verify_website_managed/app.rb +0 -36
- data/examples/verify_website_menu/README.md +0 -60
- data/examples/verify_website_menu/app.rb +0 -84
- data/examples/verify_website_spinner/README.md +0 -44
- data/examples/verify_website_spinner/app.rb +0 -34
- data/examples/widget_barchart/README.md +0 -58
- data/examples/widget_barchart/app.rb +0 -240
- data/examples/widget_block/README.md +0 -44
- data/examples/widget_block/app.rb +0 -258
- data/examples/widget_box/README.md +0 -54
- data/examples/widget_box/app.rb +0 -255
- data/examples/widget_calendar/README.md +0 -48
- data/examples/widget_calendar/app.rb +0 -115
- data/examples/widget_canvas/README.md +0 -31
- data/examples/widget_canvas/app.rb +0 -130
- data/examples/widget_cell/README.md +0 -45
- data/examples/widget_cell/app.rb +0 -112
- data/examples/widget_center/README.md +0 -33
- data/examples/widget_center/app.rb +0 -118
- data/examples/widget_chart/README.md +0 -50
- data/examples/widget_chart/app.rb +0 -220
- data/examples/widget_gauge/README.md +0 -50
- data/examples/widget_gauge/app.rb +0 -229
- data/examples/widget_layout_split/README.md +0 -53
- data/examples/widget_layout_split/app.rb +0 -260
- data/examples/widget_line_gauge/README.md +0 -50
- data/examples/widget_line_gauge/app.rb +0 -219
- data/examples/widget_list/README.md +0 -58
- data/examples/widget_list/app.rb +0 -382
- data/examples/widget_map/README.md +0 -48
- data/examples/widget_map/app.rb +0 -95
- data/examples/widget_overlay/README.md +0 -45
- data/examples/widget_overlay/app.rb +0 -250
- data/examples/widget_popup/README.md +0 -45
- data/examples/widget_popup/app.rb +0 -106
- data/examples/widget_ratatui_logo/README.md +0 -43
- data/examples/widget_ratatui_logo/app.rb +0 -104
- data/examples/widget_ratatui_mascot/README.md +0 -43
- data/examples/widget_ratatui_mascot/app.rb +0 -95
- data/examples/widget_rect/README.md +0 -53
- data/examples/widget_rect/app.rb +0 -222
- data/examples/widget_render/README.md +0 -46
- data/examples/widget_render/app.rb +0 -186
- data/examples/widget_render/app.rbs +0 -41
- data/examples/widget_rich_text/README.md +0 -44
- data/examples/widget_rich_text/app.rb +0 -193
- data/examples/widget_scroll_text/README.md +0 -46
- data/examples/widget_scroll_text/app.rb +0 -109
- data/examples/widget_scrollbar/README.md +0 -46
- data/examples/widget_scrollbar/app.rb +0 -155
- data/examples/widget_sparkline/README.md +0 -51
- data/examples/widget_sparkline/app.rb +0 -277
- data/examples/widget_style_colors/README.md +0 -43
- data/examples/widget_style_colors/app.rb +0 -83
- data/examples/widget_table/README.md +0 -57
- data/examples/widget_table/app.rb +0 -285
- data/examples/widget_tabs/README.md +0 -50
- data/examples/widget_tabs/app.rb +0 -183
- data/examples/widget_text_width/README.md +0 -44
- data/examples/widget_text_width/app.rb +0 -117
- data/migrate_to_buffer.rb +0 -145
- data/mise.toml +0 -8
- data/tasks/autodoc/examples.rb +0 -87
- data/tasks/autodoc/member.rb +0 -58
- data/tasks/autodoc/name.rb +0 -21
- data/tasks/autodoc.rake +0 -21
- data/tasks/bump/bump_workflow.rb +0 -49
- data/tasks/bump/cargo_lockfile.rb +0 -21
- data/tasks/bump/changelog.rb +0 -104
- data/tasks/bump/header.rb +0 -32
- data/tasks/bump/history.rb +0 -32
- data/tasks/bump/links.rb +0 -69
- data/tasks/bump/manifest.rb +0 -33
- data/tasks/bump/patch_release.rb +0 -19
- data/tasks/bump/release_branch.rb +0 -17
- data/tasks/bump/release_from_trunk.rb +0 -49
- data/tasks/bump/repository.rb +0 -54
- data/tasks/bump/ruby_gem.rb +0 -29
- data/tasks/bump/sem_ver.rb +0 -44
- data/tasks/bump/unreleased_section.rb +0 -73
- data/tasks/bump.rake +0 -61
- data/tasks/doc/documentation.rb +0 -59
- data/tasks/doc/link/file_url.rb +0 -30
- data/tasks/doc/link/relative_path.rb +0 -61
- data/tasks/doc/link/web_url.rb +0 -55
- data/tasks/doc/link.rb +0 -52
- data/tasks/doc/link_audit.rb +0 -116
- data/tasks/doc/problem.rb +0 -40
- data/tasks/doc/source_file.rb +0 -93
- data/tasks/doc.rake +0 -905
- data/tasks/example_viewer.html.erb +0 -172
- data/tasks/extension.rake +0 -14
- data/tasks/license/headers_md.rb +0 -223
- data/tasks/license/headers_rb.rb +0 -210
- data/tasks/license/license_utils.rb +0 -130
- data/tasks/license/snippets_md.rb +0 -315
- data/tasks/license/snippets_rdoc.rb +0 -150
- data/tasks/license.rake +0 -91
- data/tasks/lint.rake +0 -170
- data/tasks/rbs_predicates/predicate_catalog.rb +0 -52
- data/tasks/rbs_predicates/predicate_tests.rb +0 -124
- data/tasks/rbs_predicates/rbs_signature.rb +0 -63
- data/tasks/rbs_predicates.rake +0 -31
- data/tasks/rdoc_config.rb +0 -29
- data/tasks/resources/build.yml.erb +0 -60
- data/tasks/resources/index.html.erb +0 -141
- data/tasks/resources/rubies.yml +0 -7
- data/tasks/sourcehut.rake +0 -110
- data/tasks/steep.rake +0 -11
- data/tasks/terminal_preview/app_screenshot.rb +0 -45
- data/tasks/terminal_preview/crash_report.rb +0 -54
- data/tasks/terminal_preview/example_app.rb +0 -27
- data/tasks/terminal_preview/launcher_script.rb +0 -48
- data/tasks/terminal_preview/preview_collection.rb +0 -60
- data/tasks/terminal_preview/preview_timing.rb +0 -24
- data/tasks/terminal_preview/safety_confirmation.rb +0 -58
- data/tasks/terminal_preview/saved_screenshot.rb +0 -56
- data/tasks/terminal_preview/system_appearance.rb +0 -13
- data/tasks/terminal_preview/terminal_window.rb +0 -138
- data/tasks/terminal_preview/window_id.rb +0 -16
- data/tasks/terminal_preview.rake +0 -30
- data/tasks/test.rake +0 -36
- data/tasks/website/index_page.rb +0 -30
- data/tasks/website/version.rb +0 -122
- data/tasks/website/version_menu.rb +0 -68
- data/tasks/website/versioned_documentation.rb +0 -83
- data/tasks/website/website.rb +0 -53
- data/tasks/website.rake +0 -28
data/tasks/doc/link_audit.rb
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
#--
|
|
4
|
-
# SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
5
|
-
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
6
|
-
#++
|
|
7
|
-
|
|
8
|
-
require_relative "documentation"
|
|
9
|
-
|
|
10
|
-
# Results of auditing documentation for broken links.
|
|
11
|
-
#
|
|
12
|
-
# Documentation breaks silently. Links rot. Files move. Paths change. Manual
|
|
13
|
-
# checking is tedious and error-prone. Automated checking catches problems
|
|
14
|
-
# before users do.
|
|
15
|
-
#
|
|
16
|
-
# LinkAudit scans all documentation, checks each link, and collects problems.
|
|
17
|
-
# It separates web URLs (slow to verify) from local paths (fast to check).
|
|
18
|
-
# The results render as a human-readable report via <tt>to_s</tt>.
|
|
19
|
-
#
|
|
20
|
-
# === Example
|
|
21
|
-
#
|
|
22
|
-
# audit = LinkAudit.new("/project/root", verify_web: false)
|
|
23
|
-
# puts audit # prints the full report
|
|
24
|
-
# exit 1 unless audit.success?
|
|
25
|
-
#
|
|
26
|
-
class LinkAudit
|
|
27
|
-
# Problems found during the audit.
|
|
28
|
-
attr_reader :problems
|
|
29
|
-
|
|
30
|
-
# Web URLs that were not verified (when <tt>verify_web: false</tt>).
|
|
31
|
-
attr_reader :unverified
|
|
32
|
-
|
|
33
|
-
# Creates a new LinkAudit and runs the scan immediately.
|
|
34
|
-
#
|
|
35
|
-
# [root] Project root directory to scan.
|
|
36
|
-
# [verify_web] Whether to make HTTP requests to verify web URLs.
|
|
37
|
-
def initialize(root, verify_web: false)
|
|
38
|
-
@root = root
|
|
39
|
-
@docs = Documentation.new(root)
|
|
40
|
-
@verify_web = verify_web
|
|
41
|
-
@problems = []
|
|
42
|
-
@unverified = []
|
|
43
|
-
@checked = 0
|
|
44
|
-
@web_checked = 0
|
|
45
|
-
scan
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# Whether the audit passed with no problems.
|
|
49
|
-
def success?
|
|
50
|
-
@problems.empty?
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Returns the audit report as a String.
|
|
54
|
-
def to_s
|
|
55
|
-
lines = []
|
|
56
|
-
lines << ""
|
|
57
|
-
lines << "Scanning for broken links in #{@root}..."
|
|
58
|
-
lines << ""
|
|
59
|
-
|
|
60
|
-
if @verify_web
|
|
61
|
-
lines << "Checked #{@checked} links in #{@docs.count} files (#{@web_checked} web URLs probed)."
|
|
62
|
-
else
|
|
63
|
-
lines << "Checked #{@checked} links in #{@docs.count} files (URL verification skipped)."
|
|
64
|
-
end
|
|
65
|
-
lines << ""
|
|
66
|
-
|
|
67
|
-
unless @unverified.empty?
|
|
68
|
-
lines << "📋 Unverified HTTP/HTTPS URLs (#{@unverified.size}):"
|
|
69
|
-
lines << ""
|
|
70
|
-
@unverified.uniq(&:raw).each { |link| lines << " #{link.raw}" }
|
|
71
|
-
lines << ""
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
if @problems.empty?
|
|
75
|
-
lines << "✅ No broken links found!"
|
|
76
|
-
else
|
|
77
|
-
lines << "❌ Found #{@problems.size} broken link(s):"
|
|
78
|
-
lines << ""
|
|
79
|
-
|
|
80
|
-
@problems.group_by(&:file).each do |path, problems|
|
|
81
|
-
lines << "#{path}:"
|
|
82
|
-
problems.each do |problem|
|
|
83
|
-
lines << " L#{problem.line || '?'}: #{problem.raw}"
|
|
84
|
-
lines << " → #{problem.reason}"
|
|
85
|
-
end
|
|
86
|
-
lines << ""
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
lines.join("\n")
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
private def scan # :nodoc:
|
|
94
|
-
@docs.each do |file|
|
|
95
|
-
file.links.each do |link|
|
|
96
|
-
@checked += 1
|
|
97
|
-
check(link)
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
private def check(link) # :nodoc:
|
|
103
|
-
if link.web?
|
|
104
|
-
if @verify_web
|
|
105
|
-
@web_checked += 1
|
|
106
|
-
problem = link.problem(@root)
|
|
107
|
-
@problems << problem if problem
|
|
108
|
-
else
|
|
109
|
-
@unverified << link
|
|
110
|
-
end
|
|
111
|
-
else
|
|
112
|
-
problem = link.problem(@root)
|
|
113
|
-
@problems << problem if problem
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
data/tasks/doc/problem.rb
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
#--
|
|
4
|
-
# SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
5
|
-
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
6
|
-
#++
|
|
7
|
-
|
|
8
|
-
# Represents a broken link.
|
|
9
|
-
#
|
|
10
|
-
# Link checking produces results. Some links are fine. Some are broken. You
|
|
11
|
-
# need to report the broken ones with context: where they were found and why
|
|
12
|
-
# they failed.
|
|
13
|
-
#
|
|
14
|
-
# Problem holds the link and the reason it failed. It delegates to the link
|
|
15
|
-
# for file, line, and raw text. Use it to build human-readable error reports.
|
|
16
|
-
#
|
|
17
|
-
# === Example
|
|
18
|
-
#
|
|
19
|
-
# problem = Problem.new(link, "File not found: missing.md")
|
|
20
|
-
# problem.file # => "doc/guide.md"
|
|
21
|
-
# problem.line # => 42
|
|
22
|
-
# problem.raw # => "missing.md"
|
|
23
|
-
# problem.reason # => "File not found: missing.md"
|
|
24
|
-
#
|
|
25
|
-
class Problem < Data.define(:link, :reason)
|
|
26
|
-
# Relative path to the file containing the broken link.
|
|
27
|
-
def file
|
|
28
|
-
link.source_file.relative_path
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# Line number where the broken link appears.
|
|
32
|
-
def line
|
|
33
|
-
link.line
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# The raw link text that failed validation.
|
|
37
|
-
def raw
|
|
38
|
-
link.raw
|
|
39
|
-
end
|
|
40
|
-
end
|
data/tasks/doc/source_file.rb
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
#--
|
|
4
|
-
# SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
5
|
-
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
6
|
-
#++
|
|
7
|
-
|
|
8
|
-
require "pathname"
|
|
9
|
-
require_relative "link"
|
|
10
|
-
|
|
11
|
-
# A file that may contain links.
|
|
12
|
-
#
|
|
13
|
-
# Documentation lives in many files: Ruby source with RDoc comments, Markdown
|
|
14
|
-
# guides, RDoc text files. Each file may reference images, other docs, or
|
|
15
|
-
# external URLs. Extracting these links by hand is tedious.
|
|
16
|
-
#
|
|
17
|
-
# SourceFile scans its content with regex patterns. It creates the appropriate
|
|
18
|
-
# Link subclass for each match. It tracks line numbers for error reporting.
|
|
19
|
-
#
|
|
20
|
-
# === Example
|
|
21
|
-
#
|
|
22
|
-
# file = SourceFile.new("/path/to/guide.md", "/project/root")
|
|
23
|
-
# file.links.each do |link|
|
|
24
|
-
# puts "#{link.raw} at line #{link.line}"
|
|
25
|
-
# end
|
|
26
|
-
#
|
|
27
|
-
class SourceFile
|
|
28
|
-
# Regex patterns for extracting links from documentation.
|
|
29
|
-
PATTERNS = {
|
|
30
|
-
rdoc_image_link: /\{rdoc-image:([^}]+)\}\[link:([^\]]+)\]/,
|
|
31
|
-
rdoc_link: /\{[^}]*\}\[link:([^\]]+)\]/,
|
|
32
|
-
rdoc_image: /\{rdoc-image:([^}]+)\}/,
|
|
33
|
-
markdown_link: /\[(?:[^\]]*)\]\((?!mailto:|#)([^)\s]+)\)/,
|
|
34
|
-
markdown_image: /!\[[^\]]*\]\(([^)\s]+)\)/,
|
|
35
|
-
html_src: /src=["']([^"']+)["']/,
|
|
36
|
-
html_href: /href=["'](?!mailto:|#)([^"']+)["']/,
|
|
37
|
-
}.freeze
|
|
38
|
-
|
|
39
|
-
# The Pathname to this file.
|
|
40
|
-
attr_reader :path
|
|
41
|
-
|
|
42
|
-
# Creates a new SourceFile.
|
|
43
|
-
#
|
|
44
|
-
# [path] Path to the file (String or Pathname).
|
|
45
|
-
# [root] Project root directory for computing relative paths.
|
|
46
|
-
def initialize(path, root)
|
|
47
|
-
@path = Pathname.new(path)
|
|
48
|
-
@root = Pathname.new(root)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# Extracts all links from the file content. Returns an Array of Link objects.
|
|
52
|
-
def links
|
|
53
|
-
found = []
|
|
54
|
-
|
|
55
|
-
PATTERNS.each_value do |pattern|
|
|
56
|
-
content.scan(pattern) do |matches|
|
|
57
|
-
matches = [matches] unless matches.is_a?(Array)
|
|
58
|
-
matches.each do |match|
|
|
59
|
-
next if match.nil? || match.empty?
|
|
60
|
-
next unless looks_like_link?(match)
|
|
61
|
-
found << Link.build(match, line_for(match), self)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
found
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# The file path relative to the project root.
|
|
70
|
-
def relative_path
|
|
71
|
-
@path.relative_path_from(@root).to_s
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
private def content # :nodoc:
|
|
75
|
-
@content ||= @path.read(mode: "rb").force_encoding("UTF-8").scrub("")
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
private def line_for(link_text) # :nodoc:
|
|
79
|
-
line_num = 1
|
|
80
|
-
content.each_line do |line|
|
|
81
|
-
return line_num if line.include?(link_text)
|
|
82
|
-
line_num += 1
|
|
83
|
-
end
|
|
84
|
-
nil
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
private def looks_like_link?(text) # :nodoc:
|
|
88
|
-
# Skip regex patterns and other false positives
|
|
89
|
-
return false if text.match?(/[\[\]^*+?]/) # Contains regex special chars
|
|
90
|
-
return false if text.length < 4
|
|
91
|
-
true
|
|
92
|
-
end
|
|
93
|
-
end
|